diff options
author | Jason Smith <jason.smith@xamarin.com> | 2016-03-22 13:02:25 -0700 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-03-22 16:13:41 -0700 |
commit | 17fdde66d94155fc62a034fa6658995bef6fd6e5 (patch) | |
tree | b5e5073a2a7b15cdbe826faa5c763e270a505729 /Xamarin.Forms.Platform.Android/TapGestureHandler.cs | |
download | xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.gz xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.bz2 xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.zip |
Initial import
Diffstat (limited to 'Xamarin.Forms.Platform.Android/TapGestureHandler.cs')
-rw-r--r-- | Xamarin.Forms.Platform.Android/TapGestureHandler.cs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.Android/TapGestureHandler.cs b/Xamarin.Forms.Platform.Android/TapGestureHandler.cs new file mode 100644 index 00000000..dcd8d6f7 --- /dev/null +++ b/Xamarin.Forms.Platform.Android/TapGestureHandler.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Xamarin.Forms.Platform.Android +{ + internal class TapGestureHandler + { + public TapGestureHandler(Func<View> getView) + { + GetView = getView; + } + + Func<View> GetView { get; } + + public void OnSingleClick() + { + // only handle click if we don't have double tap registered + if (TapGestureRecognizers(2).Any()) + return; + + OnTap(1); + } + + public bool OnTap(int count) + { + View view = GetView(); + + if (view == null) + return false; + + IEnumerable<TapGestureRecognizer> gestureRecognizers = TapGestureRecognizers(count); + var result = false; + foreach (TapGestureRecognizer gestureRecognizer in gestureRecognizers) + { + gestureRecognizer.SendTapped(view); + result = true; + } + + return result; + } + + public IEnumerable<TapGestureRecognizer> TapGestureRecognizers(int count) + { + View view = GetView(); + if (view == null) + return Enumerable.Empty<TapGestureRecognizer>(); + + return view.GestureRecognizers.GetGesturesFor<TapGestureRecognizer>(recognizer => recognizer.NumberOfTapsRequired == count); + } + } +}
\ No newline at end of file |