From: SungHyun Min Date: Wed, 22 Feb 2017 10:58:28 +0000 (+0900) Subject: Add LongTapGesture X-Git-Tag: submit/tizen/20170315.053346~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F21%2F116021%2F10;p=platform%2Fcore%2Fcsapi%2Fxamarin-forms-extension.git 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 --- 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