Example #1
0
        protected override void OnAttached()
        {
            // Get the Android View corresponding to the Element that the effect is attached to
            view = Control == null ? Container : Control;

            // Get access to the TouchEffect class in the .NET Standard library
            TouchTracking.TouchEffect touchEffect =
                (TouchTracking.TouchEffect)Element.Effects.
                FirstOrDefault(e => e is TouchTracking.TouchEffect);

            if (touchEffect != null && view != null)
            {
                formsElement = Element;

                libTouchEffect = touchEffect;

                // Save fromPixels function
                fromPixels = view.Context.FromPixels;

                tapDetector = new InternalGestureDetector
                {
                    TapAction = motionEvent =>
                    {
                        libTouchEffect.OnTapAction(formsElement);
                    },
                };

                gestureRecognizer = new GestureDetectorCompat(view.Context, tapDetector);

                // Set event handler on View
                view.Touch += OnTouch;
            }
        }
Example #2
0
        public GestureStackLayoutRenderer()
        {
            _tapDetector = new InternalGestureDetector();

            _tapDetector.OnTap        += HandleTap;
            _tapDetector.OnSwipeLeft  += HandleOnSwipeLeft;
            _tapDetector.OnSwipeRight += HandleOnSwipeRight;
        }
        public PlatformGestureEffect()
        {
            tapDetector = new InternalGestureDetector
            {
                TapAction = motionEvent =>
                {
                    var command = tapCommand;
                    if (command != null)
                    {
                        var x     = motionEvent.GetX();
                        var y     = motionEvent.GetY();
                        var point = GetScaledCoord(x, y);
                        if (command.CanExecute(point))
                        {
                            command.Execute(point);
                        }
                    }
                },
                PanAction = (e1, e2, distanceX, distanceY) =>
                {
                    moving = true;
                    var command = panCommand;
                    if (command != null)
                    {
                        eventArgs.StartPosition   = GetScaledCoord(e1.GetX(), e1.GetY());
                        eventArgs.CurrentPosition = GetScaledCoord(e2.GetX(), e2.GetY());
                        eventArgs.StatusType      = GestureStatus.Running;
                        eventArgs.TotalMove       = GetScaledCoord(e2.GetX() - e1.GetX(), e2.GetY() - e1.GetY());
                        if (command.CanExecute(eventArgs))
                        {
                            command.Execute(eventArgs);
                        }
                    }
                },
                PanEndAction = (motionEvent) =>
                {
                    if (!moving)
                    {
                        return;
                    }
                    var command = panCommand;
                    if (command != null)
                    {
                        eventArgs.CurrentPosition = GetScaledCoord(motionEvent.GetX(), motionEvent.GetY());
                        eventArgs.StatusType      = GestureStatus.Completed;
                        eventArgs.TotalMove       = GetScaledCoord(motionEvent.GetX() - eventArgs.StartPosition.X, motionEvent.GetY() - eventArgs.StartPosition.Y);
                        if (command.CanExecute(eventArgs))
                        {
                            command.Execute(eventArgs);
                        }
                    }

                    moving = false;
                }
            };
        }
        public TapWithPositionGestureEffect()
        {
            tapDetector = new InternalGestureDetector
            {
                TapAction = motionEvent =>
                {
                    var tap = tapWithPositionCommand;
                    if (tap != null)
                    {
                        var x = motionEvent.GetX();
                        var y = motionEvent.GetY();

                        var point = PxToDp(new Point(x, y));
                        Log.WriteLine(LogPriority.Debug, "gesture", $"Tap detected at {x} x {y} in forms: {point.X} x {point.Y}");
                        if (tap.CanExecute(point))
                        {
                            tap.Execute(point);
                        }
                    }
                }
            };
        }
        public PlatformGestureEffect()
        {
            tapDetector = new InternalGestureDetector
            {
                TapAction = motionEvent =>
                {
                    var command = tapCommand2;
                    if (command != null)
                    {
                        var x = motionEvent.GetX();
                        var y = motionEvent.GetY();

                        var point = PxToDp(new Point(x, y));
                        if (command.CanExecute(point))
                        {
                            command.Execute(point);
                        }
                    }
                    var handler = tapCommand;
                    if (handler?.CanExecute(null) == true)
                    {
                        handler.Execute(null);
                    }
                },
                DoubleTapAction = motionEvent =>
                {
                    var command = doubleTapCommand;
                    if (command != null)
                    {
                        var x = motionEvent.GetX();
                        var y = motionEvent.GetY();

                        var point = PxToDp(new Point(x, y));
                        if (command.CanExecute(point))
                        {
                            command.Execute(point);
                        }
                    }
                },
                SwipeLeftAction = motionEvent =>
                {
                    var handler = swipeLeftCommand;
                    if (handler?.CanExecute(null) == true)
                    {
                        handler.Execute(null);
                    }
                },
                SwipeRightAction = motionEvent =>
                {
                    var handler = swipeRightCommand;
                    if (handler?.CanExecute(null) == true)
                    {
                        handler.Execute(null);
                    }
                },
                SwipeTopAction = motionEvent =>
                {
                    var handler = swipeTopCommand;
                    if (handler?.CanExecute(null) == true)
                    {
                        handler.Execute(null);
                    }
                },
                SwipeBottomAction = motionEvent =>
                {
                    var handler = swipeBottomCommand;
                    if (handler?.CanExecute(null) == true)
                    {
                        handler.Execute(null);
                    }
                },
                PanAction = (initialDown, currentMove) =>
                {
                    var command = panCommand;
                    if (command != null)
                    {
                        var x0 = initialDown.GetX();
                        var y0 = initialDown.GetY();
                        var x  = currentMove.GetX();
                        var y  = currentMove.GetY();

                        var point = PxToDp(new Point(x - x0, y - y0));
                        if (command.CanExecute(point))
                        {
                            command.Execute(point);
                        }
                    }
                },
            };
        }