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;
                    }
                }
            }
        }
        public static bool FireLongPressed(Windows.UI.Xaml.FrameworkElement element, Windows.UI.Xaml.Input.TappedRoutedEventArgs e, long elapsedMilliseconds, Listener listener)
        {
            var args = new UwpLongPressEventArgs(element, e, elapsedMilliseconds);

            args.Listener = listener;
            listener?.OnLongPressed(args);
            e.Handled = args.Handled;
            return(e.Handled);
        }
Пример #3
0
        public static bool FireLongPressed(FrameworkElement element, long elapsedMilliseconds, Listener listener)
        {
            var args = new UwpLongPressEventArgs(element, elapsedMilliseconds)
            {
                Listener = listener
            };

            listener?.OnLongPressed(args);
            return(args.Handled);
        }
        void OnManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
        {
            DebugMethodName(2);
            DebugMessage("Element=[" + _xfElement + "]");
            PointerDeviceTypeDebugMessage(e.PointerDeviceType);
            PositionDebugMessage(e.Position);
            ManipulationDeltaDebugMessage(e.Cumulative, "Cumul");
            ContainerDebugMessage(e.Container);
            HandledDebugString(e.Handled);

            if (!_xfElement.IsVisible || FrameworkElement == null)
            {
                return;
            }

            long elapsed = 0;

            if (_holdTimer != null)
            {
                elapsed = _holdTimer.ElapsedMilliseconds;
                _holdTimer?.Stop();
                _holdTimer = null;
            }
            DebugMessage("elapse=[" + elapsed + "]");
            if (!_panning || !_pinching || !_rotating)
            {
                _longPressing = elapsed > 750;
                if (_longPressing)
                {
                    foreach (var listener in _listeners)
                    {
                        if (listener.HandlesLongPressing)
                        {
                            var args = new UwpLongPressEventArgs(FrameworkElement, e, elapsed)
                            {
                                Listener = listener
                            };
                            listener?.OnLongPressing(args);
                            e.Handled = args.Handled;
                            DebugMessage("LongPressing Handled=[" + e.Handled + "]");
                            if (e.Handled)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            HandledDebugString(e.Handled);
        }
        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;
        }