Add LongTapGesture 21/116021/10
authorSungHyun Min <shyun.min@samsung.com>
Wed, 22 Feb 2017 10:58:28 +0000 (19:58 +0900)
committerSungHyun Min <shyun.min@samsung.com>
Tue, 14 Mar 2017 08:13:06 +0000 (17:13 +0900)
 - RFC : http://suprem.sec.samsung.net/confluence/display/SPTDTLC/%5BFormsTizen%5D+RFC+13+-+LongTapGestureRecognizer
 - Depends on https://review.tizen.org/gerrit/#/c/116015/

Change-Id: I72f8648c7dcea53c7e2310aa77b72c783721190f
Signed-off-by: SungHyun Min <shyun.min@samsung.com>
Tizen.Xamarin.Forms.Extension.Renderer/LongTapGestureHandler.cs [new file with mode: 0644]
Tizen.Xamarin.Forms.Extension.Renderer/Tizen.Xamarin.Forms.Extension.Renderer.csproj [changed mode: 0755->0644]
Tizen.Xamarin.Forms.Extension/ILongTapGestureController.cs [new file with mode: 0644]
Tizen.Xamarin.Forms.Extension/LongTapGestureRecognizer.cs [new file with mode: 0644]
Tizen.Xamarin.Forms.Extension/LongTapUpdatedEventArgs.cs [new file with mode: 0644]
Tizen.Xamarin.Forms.Extension/Tizen.Xamarin.Forms.Extension.csproj [changed mode: 0755->0644]

diff --git a/Tizen.Xamarin.Forms.Extension.Renderer/LongTapGestureHandler.cs b/Tizen.Xamarin.Forms.Extension.Renderer/LongTapGestureHandler.cs
new file mode 100644 (file)
index 0000000..bf23ae3
--- /dev/null
@@ -0,0 +1,53 @@
+using System;
+using ElmSharp;
+using Tizen.Xamarin.Forms.Extension;
+using Tizen.Xamarin.Forms.Extension.Renderer;
+using Xamarin.Forms;
+using Xamarin.Forms.Platform.Tizen;
+
+[assembly: ExportHandler(typeof(LongTapGestureRecognizer), typeof(LongTapGestureHandler))]
+
+namespace Tizen.Xamarin.Forms.Extension.Renderer
+{
+    public class LongTapGestureHandler : GestureHandler
+    {
+        public LongTapGestureHandler(IGestureRecognizer recognizer) : base(recognizer)
+        {
+        }
+
+        public override GestureLayer.GestureType Type
+        {
+            get
+            {
+                return GestureLayer.GestureType.LongTap;
+            }
+        }
+
+        public override double Timeout
+        {
+            get
+            {
+                return (Recognizer as LongTapGestureRecognizer).Timeout;
+            }
+        }
+
+        protected override void OnCanceled(View sender, object data)
+        {
+            (Recognizer as ILongTapGestureController).SendLongTapCanceled(sender, ((GestureLayer.TapData)data).Timestamp);
+        }
+
+        protected override void OnCompleted(View sender, object data)
+        {
+            (Recognizer as ILongTapGestureController).SendLongTapCompleted(sender, ((GestureLayer.TapData)data).Timestamp);
+        }
+
+        protected override void OnMoved(View sender, object data)
+        {
+        }
+
+        protected override void OnStarted(View sender, object data)
+        {
+            (Recognizer as ILongTapGestureController).SendLongTapStarted(sender, ((GestureLayer.TapData)data).Timestamp);
+        }
+    }
+}
\ No newline at end of file
old mode 100755 (executable)
new mode 100644 (file)
index 6c07bec..bf2367e
@@ -42,6 +42,7 @@
     <Compile Include="Cells\GridViewTypeCellRenderer.cs" />\r
     <Compile Include="Cells\MultilineCellRenderer.cs" />\r
     <Compile Include="Cells\TypeCellRenderer.cs" />\r
+    <Compile Include="LongTapGestureHandler.cs" />\r
     <Compile Include="RadioButtonRenderer.cs" />\r
     <Compile Include="GridViewRenderer.cs" />\r
     <Compile Include="TizenExtension.cs" />\r
@@ -76,4 +77,4 @@
     <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory)</_FullFrameworkReferenceAssemblyPaths>\r
     <AutoUnifyAssemblyReferences>true</AutoUnifyAssemblyReferences>\r
   </PropertyGroup>\r
-</Project>
+</Project>
\ No newline at end of file
diff --git a/Tizen.Xamarin.Forms.Extension/ILongTapGestureController.cs b/Tizen.Xamarin.Forms.Extension/ILongTapGestureController.cs
new file mode 100644 (file)
index 0000000..6431d70
--- /dev/null
@@ -0,0 +1,16 @@
+using Xamarin.Forms;
+
+namespace Tizen.Xamarin.Forms.Extension
+{
+    /// <summary>
+    /// This interface is for internal use by platfrom renderer.
+    /// </summary>
+    public interface ILongTapGestureController
+    {
+        void SendLongTapStarted(Element sender, double timeStamp);
+
+        void SendLongTapCompleted(Element sender, double timeStamp);
+
+        void SendLongTapCanceled(Element sender, double timeStamp);
+    }
+}
\ No newline at end of file
diff --git a/Tizen.Xamarin.Forms.Extension/LongTapGestureRecognizer.cs b/Tizen.Xamarin.Forms.Extension/LongTapGestureRecognizer.cs
new file mode 100644 (file)
index 0000000..9182dde
--- /dev/null
@@ -0,0 +1,132 @@
+using System;
+using System.Windows.Input;
+using Xamarin.Forms;
+
+namespace Tizen.Xamarin.Forms.Extension
+{
+    /// <summary>
+    /// A recognizer for long-tap gesture.
+    /// </summary>
+    /// <example>
+    /// <code>
+    /// var image = new Image { Source = ImageSource.FromFile("picture.png") };
+    /// var longTapGesture = new LongTapGestureRecognizer
+    /// {
+    ///     Timeout = 0.05
+    /// };
+    /// longTapGesture.LongTapUpdated += (sender, args) =>
+    /// {
+    ///     Debug.WriteLine("LongTap updated : " + args.Status);
+    /// };
+    /// image.GestureRecognizers.Add(longTapGesture);
+    /// </code>
+    /// </example>
+    public class LongTapGestureRecognizer : Element, IGestureRecognizer, ILongTapGestureController
+    {
+        public static readonly BindableProperty TimeoutProperty = BindableProperty.Create("Timeout", typeof(double), typeof(LongTapGestureRecognizer), default(double));
+
+        public static readonly BindableProperty TapStartedCommandProperty = BindableProperty.Create("TapStartedCommand", typeof(ICommand), typeof(LongTapGestureRecognizer), null);
+
+        public static readonly BindableProperty TapCompletedCommandProperty = BindableProperty.Create("TapCompletedCommand", typeof(ICommand), typeof(LongTapGestureRecognizer), null);
+
+        public static readonly BindableProperty TapStartedCommandParameterProperty = BindableProperty.Create("TapStartedCommandParameter", typeof(object), typeof(LongTapGestureRecognizer), null);
+
+        public static readonly BindableProperty TapCompletedCommandParameterProperty = BindableProperty.Create("TapCompletedCommandParameter", typeof(object), typeof(LongTapGestureRecognizer), null);
+
+        /// <summary>
+        /// Event that is raised when the long-tap gesture updates.
+        /// </summary>
+        public event EventHandler<LongTapUpdatedEventArgs> LongTapUpdated;
+
+        /// <summary>
+        /// Event that is raised when the user presses the View
+        /// </summary>
+        public event EventHandler TapStarted;
+
+        /// <summary>
+        /// Event that is raised when the user releases the view after pressing the View.
+        /// </summary>
+        public event EventHandler TapCompleted;
+
+        /// <summary>
+        /// Event that is raised when the wrong gesture is detected after pressing the View.
+        /// </summary>
+        public event EventHandler TapCanceled;
+
+        /// <summary>
+        /// Gets or Sets the minimum time(seconds) the user should press the view for triggering long-tap event.
+        /// </summary>
+        /// <remarks>
+        /// The default value are defined in the system policy. In Tizen the default value is 0.33 seconds
+        /// </remarks>
+        public double Timeout
+        {
+            get { return (double)GetValue(TimeoutProperty); }
+            set { SetValue(TimeoutProperty, value); }
+        }
+
+        /// <summary>
+        /// Gets or sets the command to invoke when the Pressed event occurs
+        /// </summary>
+        public ICommand TapStartedCommand
+        {
+            get { return (ICommand)GetValue(TapStartedCommandProperty); }
+            set { SetValue(TapStartedCommandProperty, value); }
+        }
+
+        /// <summary>
+        /// Gests or sets an object to be passed when the PressedCommand is excuted.
+        /// </summary>
+        public object TapStartedCommandParameter
+        {
+            get { return GetValue(TapStartedCommandParameterProperty); }
+            set { SetValue(TapStartedCommandParameterProperty, value); }
+        }
+
+        /// <summary>
+        /// Gests or sets the command to invoke when the Released event occurs
+        /// </summary>
+        /// <remarks>
+        /// </remarks>
+        public ICommand TapCompletedCommand
+        {
+            get { return (ICommand)GetValue(TapCompletedCommandProperty); }
+            set { SetValue(TapCompletedCommandProperty, value); }
+        }
+
+        /// <summary>
+        /// Gests or sets an object to be passed when the ReleasedCommand is excuted.
+        /// </summary>
+        public object TapCompletedCommandParameter
+        {
+            get { return GetValue(TapCompletedCommandParameterProperty); }
+            set { SetValue(TapCompletedCommandParameterProperty, value); }
+        }
+
+        void ILongTapGestureController.SendLongTapStarted(Element sender, double timeStamp)
+        {
+            ICommand cmd = TapStartedCommand;
+            if (cmd != null && cmd.CanExecute(TapStartedCommandParameter))
+                cmd.Execute(TapStartedCommandParameter);
+
+            TapStarted?.Invoke(sender, EventArgs.Empty);
+            LongTapUpdated?.Invoke(sender, new LongTapUpdatedEventArgs(GestureStatus.Started, timeStamp));
+        }
+
+        void ILongTapGestureController.SendLongTapCompleted(Element sender, double timeStamp)
+        {
+            ICommand cmd = TapCompletedCommand;
+            if (cmd != null && cmd.CanExecute(TapCompletedCommandParameter))
+                cmd.Execute(TapCompletedCommandParameter);
+
+            TapCompleted?.Invoke(sender, EventArgs.Empty);
+            LongTapUpdated?.Invoke(sender, new LongTapUpdatedEventArgs(GestureStatus.Completed, timeStamp));
+        }
+
+        void ILongTapGestureController.SendLongTapCanceled(Element sender, double timeStamp)
+        {
+            TapCanceled?.Invoke(sender, EventArgs.Empty);
+            LongTapUpdated?.Invoke(sender, new LongTapUpdatedEventArgs(GestureStatus.Canceled, timeStamp));
+        }
+    }
+}
\ No newline at end of file
diff --git a/Tizen.Xamarin.Forms.Extension/LongTapUpdatedEventArgs.cs b/Tizen.Xamarin.Forms.Extension/LongTapUpdatedEventArgs.cs
new file mode 100644 (file)
index 0000000..6a3d551
--- /dev/null
@@ -0,0 +1,27 @@
+using System;
+using Xamarin.Forms;
+
+namespace Tizen.Xamarin.Forms.Extension
+{
+    /// <summary>
+    /// Arguments for the LongTapUpdated event.
+    /// </summary>
+    public class LongTapUpdatedEventArgs : EventArgs
+    {
+        public LongTapUpdatedEventArgs(GestureStatus status, double timestamp)
+        {
+            Status = status;
+            TimeStamp = timestamp;
+        }
+
+        /// <summary>
+        /// Gets the timestamp(millisecond).
+        /// </summary>
+        public double TimeStamp { get; }
+
+        /// <summary>
+        /// Gets the status that indicates whether the gesture started, has finished or has canceled.
+        /// </summary>
+        public GestureStatus Status { get; }
+    }
+}
old mode 100755 (executable)
new mode 100644 (file)
index 5269638..f6435c3
     <Compile Include="GridView.cs" />\r
     <Compile Include="GridViewEnums.cs" />\r
     <Compile Include="GridViewEventArgs.cs" />\r
+    <Compile Include="ILongTapGestureController.cs" />\r
     <Compile Include="ItemsView.cs" />\r
     <Compile Include="ListProxy.cs" />\r
+    <Compile Include="LongTapGestureRecognizer.cs" />\r
+    <Compile Include="LongTapUpdatedEventArgs.cs" />\r
     <Compile Include="Properties\AssemblyInfo.cs" />\r
     <Compile Include="RadioButton.cs" />\r
     <Compile Include="SelectedEventArgs.cs" />\r
   <Target Name="AfterBuild">
   </Target>
   -->\r
-</Project>
+</Project>
\ No newline at end of file