public void Unsubscribe()
        {
            _element.ManipulationStarted   -= OnManipulationStarted;
            _element.ManipulationCompleted -= OnManipulationCompleted;
            _element.ManipulationDelta     -= OnManipulationDelta;
            TouchHelper.RemoveHandlers(_element);

            if (_doubleTap != null)
            {
                _doubleTap.Cancel();
                _doubleTap = null;
            }

            if (_tapAndHold != null)
            {
                _tapAndHold.Cancel();
                _tapAndHold = null;
            }

            if (_pressAndTap != null)
            {
                _pressAndTap.Cancel();
                _pressAndTap = null;
            }
        }
 private void AbortTapHold()
 {
     if (_tapAndHold != null)
     {
         _tapAndHold.Cancel();
         _tapAndHold = null;
     }
 }
        private void OnManipulationStarted(object sender, ManipulationStartedEventArgs e)
        {
            _fingerTaps.Clear();

            Debug.WriteLine("OnManipulationStarted: ({0})", e.ManipulationOrigin);

            _isTap             = true;
            _tapStartTimestamp = DateTime.Now.Ticks;

            _tapAndHold = new FutureAction(() =>
            {
                if (IsTwoFingerTap())
                {
                    RaiseEvent(sender, TwoFingerTapAndHold, new TwoFingerTapAndHoldGestureEventArgs
                    {
                        Origin = e.ManipulationOrigin
                    });
                }
                else
                {
                    RaiseEvent(sender, TapAndHold, new TapAndHoldGestureEventArgs
                    {
                        Origin = e.ManipulationOrigin
                    });
                }

                _isTap = false;
                e.Complete();
            }, TapAndHoldTimeThreshold);

            _pressAndTap = new FutureAction(() =>
            {
                if (_fingerTaps.Count == 2 && _fingerTaps[0].IsTapComplete == false && _fingerTaps[1].IsTapComplete)
                {
                    AbortTapHold();

                    RaiseEvent(sender, PressAndTap, new PressAndTapGestureEventArgs
                    {
                        Origin = e.ManipulationOrigin
                    });

                    _isTap = false;
                    e.Complete();
                }
            }, PressAndTapTimeThreshold);
        }
Exemplo n.º 4
0
 public FutureAction(FutureAction action)
 {
 }
        private void OnManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
        {
            Point    origin = e.ManipulationOrigin;
            DateTime now    = DateTime.Now;

            if (_isTap)
            {
                AbortTapHold();

                if (_waitingFor2ndTap && IsDoubleTap(_lastTapOrigin, _lastTapTimestamp, origin, now.Ticks))
                {
                    _doubleTap.Cancel();
                    _doubleTap        = null;
                    _waitingFor2ndTap = false;
                    RaiseEvent(sender, DoubleTap, new DoubleTapGestureEventArgs
                    {
                        Origin = origin
                    });
                }
                else
                {
                    _waitingFor2ndTap = true;
                    _lastTapTimestamp = now.Ticks;
                    _lastTapOrigin    = origin;
                    _doubleTap        = new FutureAction(() =>
                    {
                        if (IsTwoFingerTap())
                        {
                            RaiseEvent(sender, TwoFingerTap, new TwoFingerTapGestureEventArgs
                            {
                                Origin = e.ManipulationOrigin
                            });
                        }
                        else
                        {
                            RaiseEvent(sender, Tap, new TapGestureEventArgs
                            {
                                Origin = e.ManipulationOrigin
                            });
                        }
                    },
                                                         DoubleTapTimeThreshold);
                }
            }
            else
            {
                _isTap            = false;
                _waitingFor2ndTap = false;
            }

            if (e.IsInertial && ((Math.Abs(e.FinalVelocities.LinearVelocity.X) > MinimumFlickSpeed) || (Math.Abs(e.FinalVelocities.LinearVelocity.Y) > MinimumFlickSpeed)))
            {
                RaiseEvent(sender, Flick, new FlickGestureEventArgs
                {
                    Origin         = e.ManipulationOrigin,
                    Velocity       = e.FinalVelocities.LinearVelocity,
                    FlickDirection = FlickGestureEventArgs.GetDirection(e.ManipulationOrigin, e.FinalVelocities.LinearVelocity)
                });
            }

            _primaryTouchPoint       = null;
            _secondaryTouchPoint     = null;
            _lastPrimaryTouchPoint   = null;
            _lastSecondaryTouchPoint = null;
        }