Example #1
0
        protected override void OnPointerCaptureLost(
            PointerRoutedEventArgs e)
        {
            base.OnPointerCaptureLost(e);

            bool result = false;

            var itemContainer = this.ItemContainer;

            if (null != itemContainer)
            {
                var   position = e.GetCurrentPoint(this).Position;
                Point point    = new Point((float)position.X, (float)position.Y);

                var pointerEvent = new PointerInputEvent(point, PointerInputState.Canceled, e.Pointer.IsInContact);

                result = itemContainer.HandlePointerEvent(pointerEvent);
            }

            if (this._pointerCaptured)
            {
                this.ReleasePointerCapture(e.Pointer);
            }

            e.Handled = result;
        }
Example #2
0
        protected override void OnPointerInput(
            PointerInputEvent touch,
            ref GestureEventResult result)
        {
            result.DidHandleEvent = true;

            if (touch.State == PointerInputState.Began)
            {
                if (this.State == GestureState.Possible)
                {
                    this.State = GestureState.Began;

                    this._gestureStart = touch.Point;

                    this._delegate.OnTapBegan();
                }
            }
            else if (touch.State == PointerInputState.Moved)
            {
                if (this.State == GestureState.Began)
                {
                    double distance = touch.Point.DistanceTo(this._gestureStart);

                    if (distance > Application.TouchSlop)
                    {
                        this.State = GestureState.Failed;

                        this._delegate.OnTapEnded();
                    }
                }
            }
            else if (touch.State == PointerInputState.Ended)
            {
                if (this.State == GestureState.Began)
                {
                    double distance = touch.Point.DistanceTo(this._gestureStart);

                    if (distance <= Application.TouchSlop)
                    {
                        this.State = GestureState.Recognized;

                        this._delegate.OnTapped();
                    }
                    else
                    {
                        this.State = GestureState.Failed;
                    }

                    this._delegate.OnTapEnded();
                }
                else
                {
                    this.State = GestureState.Failed;
                }
            }
            else if (touch.State == PointerInputState.Canceled)
            {
                if (this.State == GestureState.Began)
                {
                    this.State = GestureState.Failed;

                    this._delegate.OnTapEnded();
                }
                else
                {
                    this.State = GestureState.Failed;
                }
            }
        }
Example #3
0
        protected override void OnPointerInput(
            PointerInputEvent touch,
            ref GestureEventResult result)
        {
            result.DidHandleEvent = true;

            if (touch.State == PointerInputState.Began)
            {
                if (this.State == GestureState.Possible)
                {
                    this.State = GestureState.Began;

                    this._swipeDirection = 0;
                    this._gestureStart   = touch.Point;

                    this._delegate.OnTapBegan();
                }
            }
            else if (this.State != GestureState.Possible)
            {
                float dx = (float)(touch.Point.X - this._gestureStart.X);

                if (this._swipeDirection == 0)
                {
                    this._swipeDirection = Math.Sign(dx);
                }

                if (Math.Sign(dx) != this._swipeDirection)
                {
                    dx = 0;
                }
                else
                {
                    dx = Math.Abs(dx);
                }

                double dy = Math.Abs(touch.Point.Y - this._gestureStart.Y);

                if (touch.State == PointerInputState.Moved)
                {
                    if (this.State == GestureState.Began)
                    {
                        if (dx >= Application.TouchSlop)
                        {
                            this._delegate.OnSwipeBegan(this._swipeDirection);

                            this.State = GestureState.Changed;
                        }
                        else if (dy >= Application.TouchSlop)
                        {
                            this.State = GestureState.Failed;

                            this._delegate.OnTapEnded();
                        }
                    }
                    else if (this.State == GestureState.Changed)
                    {
                        this._delegate.OnSwipeMoved(this._swipeDirection, dx);
                    }
                }
                else if (touch.State == PointerInputState.Ended)
                {
                    if (this.State == GestureState.Began)
                    {
                        this.State = GestureState.Recognized;

                        this._delegate.OnTapped();

                        this._delegate.OnTapEnded();
                    }
                    else if (this.State == GestureState.Changed)
                    {
                        this._delegate.OnSwipeEnded(this._swipeDirection, dx);

                        this._delegate.OnTapEnded();

                        this.State = GestureState.Recognized;
                    }
                    else
                    {
                        this.State = GestureState.Failed;
                    }
                }
                else if (touch.State == PointerInputState.Canceled)
                {
                    if (this.State == GestureState.Began)
                    {
                        this._delegate.OnTapEnded();
                    }
                    else if (this.State == GestureState.Changed)
                    {
                        this._delegate.OnSwipeCanceled(this._swipeDirection);

                        this._delegate.OnTapEnded();
                    }

                    if (this.State != GestureState.Possible)
                    {
                        this.State = GestureState.Canceled;
                    }
                }
            }
        }
Example #4
0
        private void Element_Touch(
            object sender,
            AndroidView.TouchEventArgs e)
        {
            bool result = false;

            if (this.IsInputVisible)
            {
                var control = this.ViewDelegate;
                if (null != control)
                {
                    var  motionEvent = e.Event;
                    bool isInContact;
                    bool isKnownAction;
                    PointerInputState pointerState;
                    if (motionEvent.Action == MotionEventActions.Down)
                    {
                        pointerState  = PointerInputState.Began;
                        isKnownAction = true;
                        isInContact   = true;
                    }
                    else if (motionEvent.Action == MotionEventActions.Up)
                    {
                        pointerState  = PointerInputState.Ended;
                        isKnownAction = true;
                        isInContact   = true;
                    }
                    else if (motionEvent.Action == MotionEventActions.Move)
                    {
                        pointerState  = PointerInputState.Moved;
                        isKnownAction = true;
                        isInContact   = true;
                    }
                    else if (motionEvent.Action == MotionEventActions.Cancel)
                    {
                        pointerState  = PointerInputState.Canceled;
                        isKnownAction = true;
                        isInContact   = true;
                    }
                    else if (motionEvent.Action == MotionEventActions.HoverMove)
                    {
                        pointerState  = PointerInputState.Moved;
                        isKnownAction = true;
                        isInContact   = false;
                    }
                    else
                    {
                        pointerState  = PointerInputState.Canceled;
                        isKnownAction = false;
                        isInContact   = false;
                    }

                    if (isKnownAction)
                    {
                        var contactPoint = new Point(
                            this.PixelsToDevicePixels(motionEvent.GetX()),
                            this.PixelsToDevicePixels(motionEvent.GetY()));

                        var pointerEvent = new PointerInputEvent(contactPoint, pointerState, isInContact);

                        result = control.HandlePointerEvent(pointerEvent);

                        if ((result) && (pointerState == PointerInputState.Began))
                        {
                            this.CapturePointer();
                        }
                        else if ((pointerState == PointerInputState.Ended) ||
                                 (pointerState == PointerInputState.Canceled))
                        {
                            this.ReleasePointer();
                        }
                    }
                }
            }

            e.Handled = result;
        }