From c459d97f2f0f1728a5483ff05108f4772475450f Mon Sep 17 00:00:00 2001 From: SungHyun Min Date: Wed, 22 Feb 2017 19:58:28 +0900 Subject: [PATCH] Add LongTapGesture - 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 --- .../LongTapGestureHandler.cs | 53 +++++++++ .../Tizen.Xamarin.Forms.Extension.Renderer.csproj | 3 +- .../ILongTapGestureController.cs | 16 +++ .../LongTapGestureRecognizer.cs | 132 +++++++++++++++++++++ .../LongTapUpdatedEventArgs.cs | 27 +++++ .../Tizen.Xamarin.Forms.Extension.csproj | 5 +- 6 files changed, 234 insertions(+), 2 deletions(-) create mode 100644 Tizen.Xamarin.Forms.Extension.Renderer/LongTapGestureHandler.cs mode change 100755 => 100644 Tizen.Xamarin.Forms.Extension.Renderer/Tizen.Xamarin.Forms.Extension.Renderer.csproj create mode 100644 Tizen.Xamarin.Forms.Extension/ILongTapGestureController.cs create mode 100644 Tizen.Xamarin.Forms.Extension/LongTapGestureRecognizer.cs create mode 100644 Tizen.Xamarin.Forms.Extension/LongTapUpdatedEventArgs.cs mode change 100755 => 100644 Tizen.Xamarin.Forms.Extension/Tizen.Xamarin.Forms.Extension.csproj diff --git a/Tizen.Xamarin.Forms.Extension.Renderer/LongTapGestureHandler.cs b/Tizen.Xamarin.Forms.Extension.Renderer/LongTapGestureHandler.cs new file mode 100644 index 0000000..bf23ae3 --- /dev/null +++ b/Tizen.Xamarin.Forms.Extension.Renderer/LongTapGestureHandler.cs @@ -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 diff --git a/Tizen.Xamarin.Forms.Extension.Renderer/Tizen.Xamarin.Forms.Extension.Renderer.csproj b/Tizen.Xamarin.Forms.Extension.Renderer/Tizen.Xamarin.Forms.Extension.Renderer.csproj old mode 100755 new mode 100644 index 6c07bec..bf2367e --- a/Tizen.Xamarin.Forms.Extension.Renderer/Tizen.Xamarin.Forms.Extension.Renderer.csproj +++ b/Tizen.Xamarin.Forms.Extension.Renderer/Tizen.Xamarin.Forms.Extension.Renderer.csproj @@ -42,6 +42,7 @@ + @@ -76,4 +77,4 @@ <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory) true - + \ 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 index 0000000..6431d70 --- /dev/null +++ b/Tizen.Xamarin.Forms.Extension/ILongTapGestureController.cs @@ -0,0 +1,16 @@ +using Xamarin.Forms; + +namespace Tizen.Xamarin.Forms.Extension +{ + /// + /// This interface is for internal use by platfrom renderer. + /// + 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 index 0000000..9182dde --- /dev/null +++ b/Tizen.Xamarin.Forms.Extension/LongTapGestureRecognizer.cs @@ -0,0 +1,132 @@ +using System; +using System.Windows.Input; +using Xamarin.Forms; + +namespace Tizen.Xamarin.Forms.Extension +{ + /// + /// A recognizer for long-tap gesture. + /// + /// + /// + /// 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); + /// + /// + 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); + + /// + /// Event that is raised when the long-tap gesture updates. + /// + public event EventHandler LongTapUpdated; + + /// + /// Event that is raised when the user presses the View + /// + public event EventHandler TapStarted; + + /// + /// Event that is raised when the user releases the view after pressing the View. + /// + public event EventHandler TapCompleted; + + /// + /// Event that is raised when the wrong gesture is detected after pressing the View. + /// + public event EventHandler TapCanceled; + + /// + /// Gets or Sets the minimum time(seconds) the user should press the view for triggering long-tap event. + /// + /// + /// The default value are defined in the system policy. In Tizen the default value is 0.33 seconds + /// + public double Timeout + { + get { return (double)GetValue(TimeoutProperty); } + set { SetValue(TimeoutProperty, value); } + } + + /// + /// Gets or sets the command to invoke when the Pressed event occurs + /// + public ICommand TapStartedCommand + { + get { return (ICommand)GetValue(TapStartedCommandProperty); } + set { SetValue(TapStartedCommandProperty, value); } + } + + /// + /// Gests or sets an object to be passed when the PressedCommand is excuted. + /// + public object TapStartedCommandParameter + { + get { return GetValue(TapStartedCommandParameterProperty); } + set { SetValue(TapStartedCommandParameterProperty, value); } + } + + /// + /// Gests or sets the command to invoke when the Released event occurs + /// + /// + /// + public ICommand TapCompletedCommand + { + get { return (ICommand)GetValue(TapCompletedCommandProperty); } + set { SetValue(TapCompletedCommandProperty, value); } + } + + /// + /// Gests or sets an object to be passed when the ReleasedCommand is excuted. + /// + 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 index 0000000..6a3d551 --- /dev/null +++ b/Tizen.Xamarin.Forms.Extension/LongTapUpdatedEventArgs.cs @@ -0,0 +1,27 @@ +using System; +using Xamarin.Forms; + +namespace Tizen.Xamarin.Forms.Extension +{ + /// + /// Arguments for the LongTapUpdated event. + /// + public class LongTapUpdatedEventArgs : EventArgs + { + public LongTapUpdatedEventArgs(GestureStatus status, double timestamp) + { + Status = status; + TimeStamp = timestamp; + } + + /// + /// Gets the timestamp(millisecond). + /// + public double TimeStamp { get; } + + /// + /// Gets the status that indicates whether the gesture started, has finished or has canceled. + /// + public GestureStatus Status { get; } + } +} diff --git a/Tizen.Xamarin.Forms.Extension/Tizen.Xamarin.Forms.Extension.csproj b/Tizen.Xamarin.Forms.Extension/Tizen.Xamarin.Forms.Extension.csproj old mode 100755 new mode 100644 index 5269638..f6435c3 --- a/Tizen.Xamarin.Forms.Extension/Tizen.Xamarin.Forms.Extension.csproj +++ b/Tizen.Xamarin.Forms.Extension/Tizen.Xamarin.Forms.Extension.csproj @@ -65,8 +65,11 @@ + + + @@ -105,4 +108,4 @@ --> - + \ No newline at end of file -- 2.7.4