private void OnPointerPressed(object sender, PointerRoutedEventArgs e)
        {
            if (!_xfElement.IsVisible || FrameworkElement == null)
            {
                return;
            }
            DebugMethodName(2);

            if (_releaseTimer == null || _releaseTimer.Elapsed.TotalMilliseconds > 750)
            {
                _releaseTimer?.Stop();
                _releaseTimer = null;
                _numberOfTaps = 0;
            }
            _numberOfTaps++;

            _holdTimer?.Stop();
            _holdTimer = new Stopwatch();
            _holdTimer.Start();

            _rotating     = false;
            _pinching     = false;
            _panning      = false;
            _longPressing = false;

            foreach (var listener in _listeners)
            {
                if (listener.HandlesDown && UwpDownUpArgs.FireDown(FrameworkElement, e, listener))
                {
                    return;
                }
            }
        }
        private void OnPointerCancelled(object sender, PointerRoutedEventArgs e)
        {
            if (!_xfElement.IsVisible || FrameworkElement == null)
            {
                return;
            }
            PointerRoutedDebugMessage(e, "POINTER CANCELLED");

            long elapsed = 0;

            if (_holdTimer != null)
            {
                elapsed = _holdTimer.ElapsedMilliseconds;
                _holdTimer?.Stop();
                _holdTimer = null;
            }

            _releaseTimer?.Stop();
            _releaseTimer = null;

            foreach (var listener in _listeners)
            {
                if (listener.HandlesTapped)
                {
                    var args = new UwpTapEventArgs(FrameworkElement, e, _numberOfTaps)
                    {
                        Listener  = listener,
                        Cancelled = true
                    };
                    listener?.OnTapped(args);
                    e.Handled = args.Handled;
                }
                if (_longPressing && listener.HandlesLongPressed)
                {
                    var args = new UwpLongPressEventArgs(FrameworkElement, e, elapsed)
                    {
                        Listener  = listener,
                        Cancelled = true
                    };
                    listener?.OnLongPressed(args);
                    e.Handled = args.Handled;
                }
                if (listener.HandlesDown)
                {
                    var args = new UwpDownUpArgs(FrameworkElement, e)
                    {
                        Listener  = listener,
                        Cancelled = true
                    };
                    listener.OnUp(args);
                    e.Handled = args.Handled;
                    if (e.Handled)
                    {
                        return;
                    }
                }
            }
        }
Example #3
0
        public static bool FireUp(FrameworkElement element, TappedRoutedEventArgs e, Listener listener)
        {
            var args = new UwpDownUpArgs(element, e);

            args.Listener = listener;
            listener.OnUp(args);
            e.Handled = args.Handled;
            return(e.Handled);
        }
Example #4
0
 public static bool FireDown(FrameworkElement frameworkElement, TappedRoutedEventArgs e, Listener listener)
 {
     if (frameworkElement is FrameworkElement element)
     {
         var args = new UwpDownUpArgs(element, e)
         {
             Listener = listener
         };
         listener.OnDown(args);
         e.Handled = args.Handled;
         return(e.Handled);
     }
     return(false);
 }
        private void OnTapped(object sender, TappedRoutedEventArgs e)
        {
            if (!_xfElement.IsVisible || FrameworkElement == null)
            {
                return;
            }

            DebugMethodName(2);

            long elapsed = 0;

            if (_holdTimer != null)
            {
                elapsed = _holdTimer.ElapsedMilliseconds;
                _holdTimer?.Stop();
                _holdTimer = null;
            }

            _releaseTimer?.Stop();
            _releaseTimer = new Stopwatch();
            _releaseTimer.Start();

            if (!_runningTapCounterResetter)
            {
                _runningTapCounterResetter = true;
                Device.StartTimer(TimeSpan.FromSeconds(1), () =>
                {
                    if (_releaseTimer == null || _releaseTimer.ElapsedMilliseconds > 750)
                    {
                        _numberOfTaps = 0;
                        _releaseTimer?.Stop();
                        _releaseTimer = null;
                        _runningTapCounterResetter = false;
                    }
                    return(_runningTapCounterResetter);
                });
            }

            foreach (var listener in _listeners)
            {
                if (listener.HandlesTapped && UwpTapEventArgs.FireTapped(FrameworkElement, e, _numberOfTaps, listener))
                {
                    break;
                }
            }

            foreach (var listener in _listeners)
            {
                if (_longPressing && listener.HandlesLongPressed && UwpLongPressEventArgs.FireLongPressed(FrameworkElement, e, elapsed, listener))
                {
                    break;
                }
            }


            foreach (var listener in _listeners)
            {
                if (listener.HandlesDown && UwpDownUpArgs.FireUp(FrameworkElement, e, listener))
                {
                    break;
                }
            }


            _longPressing = false;
        }