Exemplo n.º 1
0
        public void OnTouchAction(Element element, TouchActionEventArgs args)
        {
            TouchAction?.Invoke(element, args);

            if (args.Type == TouchActionType.Pressed)
            {
                if (element.GetValue(CommandProperty) is ICommand iCommand)
                {
                    if (iCommand?.CanExecute(element) == true)
                    {
                        iCommand.Execute(element);
                    }
                }
            }
        }
Exemplo n.º 2
0
 public void OnTouchAction(Element element, TouchActionEventArgs args)
 {
     TouchAction?.Invoke(element, args);
 }
Exemplo n.º 3
0
        private async void OnTouch(object sender, SKTouchEventArgs e)
        {
            // Save time, when the event occures
            long ticks = DateTime.Now.Ticks;

            var location = GetScreenPosition(e.Location);

            // if user handles action by his own return
            TouchAction?.Invoke(sender, e);
            if (e.Handled)
            {
                return;
            }

            if (e.ActionType == SKTouchAction.Pressed)
            {
                _firstTouch = location;

                _touches[e.Id] = new TouchEvent(e.Id, location, ticks);

                _flingTracker.Clear();

                // Do we have a doubleTapTestTimer running?
                // If yes, stop it and increment _numOfTaps
                if (_waitingForDoubleTap)
                {
                    _waitingForDoubleTap = false;
                    _numOfTaps++;
                }
                else
                {
                    _numOfTaps = 1;
                }

                e.Handled = OnTouchStart(_touches.Select(t => t.Value.Location).ToList());
            }
            // Delete e.Id from _touches, because finger is released
            else if (e.ActionType == SKTouchAction.Released && _touches.TryRemove(e.Id, out var releasedTouch))
            {
                // Is this a fling or swipe?
                if (_touches.Count == 0)
                {
                    double velocityX;
                    double velocityY;

                    (velocityX, velocityY) = _flingTracker.CalcVelocity(e.Id, ticks);

                    if (Math.Abs(velocityX) > 200 || Math.Abs(velocityY) > 200)
                    {
                        // This was the last finger on screen, so this is a fling
                        e.Handled = OnFlinged(velocityX, velocityY);
                    }

                    // Do we have a tap event
                    if (releasedTouch == null)
                    {
                        e.Handled = false;
                        return;
                    }

                    // While tapping on screen, there could be a small movement of the finger
                    // (especially on Samsung). So check, if touch start location isn't more
                    // than a number of pixels away from touch end location.
                    bool isAround = IsAround(releasedTouch);

                    // If touch start and end is in the same area and the touch time is shorter
                    // than longTap, than we have a tap.
                    if (isAround && (ticks - releasedTouch.Tick) < (e.DeviceType == SKTouchDeviceType.Mouse ? shortClick : longTap) * 10000)
                    {
                        _waitingForDoubleTap = true;
                        if (UseDoubleTap)
                        {
                            await Task.Delay(delayTap);
                        }

                        if (_numOfTaps > 1)
                        {
                            if (!e.Handled)
                            {
                                e.Handled = OnDoubleTapped(location, _numOfTaps);
                            }
                        }
                        else
                        {
                            if (!e.Handled)
                            {
                                e.Handled = OnSingleTapped(location);
                            }
                        }
                        _numOfTaps = 1;
                        if (_waitingForDoubleTap)
                        {
                            _waitingForDoubleTap = false;;
                        }
                    }
                    else if (isAround && (ticks - releasedTouch.Tick) >= longTap * 10000)
                    {
                        if (!e.Handled)
                        {
                            e.Handled = OnLongTapped(location);
                        }
                    }
                }

                _flingTracker.RemoveId(e.Id);

                if (_touches.Count == 1)
                {
                    e.Handled = OnTouchStart(_touches.Select(t => t.Value.Location).ToList());
                }

                if (!e.Handled)
                {
                    e.Handled = OnTouchEnd(_touches.Select(t => t.Value.Location).ToList(), releasedTouch.Location);
                }
            }
            else if (e.ActionType == SKTouchAction.Moved)
            {
                _touches[e.Id] = new TouchEvent(e.Id, location, ticks);

                if (e.InContact)
                {
                    _flingTracker.AddEvent(e.Id, location, ticks);
                }

                if (e.InContact && !e.Handled)
                {
                    e.Handled = OnTouchMove(_touches.Select(t => t.Value.Location).ToList());
                }
                else
                {
                    e.Handled = OnHovered(_touches.Select(t => t.Value.Location).FirstOrDefault());
                }
            }
            else if (e.ActionType == SKTouchAction.Cancelled)
            {
                // This gesture is cancelled, so clear all touches
                _touches.Clear();
            }
            else if (e.ActionType == SKTouchAction.Exited && _touches.TryRemove(e.Id, out var exitedTouch))
            {
                e.Handled = OnTouchExited(_touches.Select(t => t.Value.Location).ToList(), exitedTouch.Location);
            }
            else if (e.ActionType == SKTouchAction.Entered)
            {
                e.Handled = OnTouchEntered(_touches.Select(t => t.Value.Location).ToList());
            }
            else if (e.ActionType == SKTouchAction.WheelChanged)
            {
                if (e.WheelDelta > 0)
                {
                    OnZoomIn(location);
                }
                else
                {
                    OnZoomOut(location);
                }
            }
        }
Exemplo n.º 4
0
 public void OnTouchAction(Xamarin.Forms.Element element, TouchActionEventArgs args)
 {
     TouchAction?.Invoke(element, args);
 }
Exemplo n.º 5
0
 public virtual void OnTouchAction(Element element, TouchActionEventArgs args)
 {
     TouchAction?.Invoke(element, args);
     System.Diagnostics.Debug.WriteLine($"\nTouch Event: {args.Type}; Is in Contact: {args.IsInContact}; Location: {args.Location}\n");
 }
Exemplo n.º 6
0
 public void OnTouchAction()
 {
     TouchAction?.Invoke();
 }