예제 #1
0
        protected internal override void HandleInProgressEvent(MotionEventActions actionCode, MotionEvent
                                                               evt)
        {
            switch (actionCode)
            {
            case MotionEventActions.Up:
            case MotionEventActions.Cancel:
            {
                mListener.OnMoveEnd(this);
                ResetState();
                break;
            }

            case MotionEventActions.Move:
            {
                UpdateStateByEvent(evt);
                // Only accept the event if our relative pressure is within
                // a certain limit. This can help filter shaky data as a
                // finger is lifted.
                if (mCurrPressure / mPrevPressure > PressureThreshold)
                {
                    bool updatePrevious = mListener.OnMove(this);
                    if (updatePrevious)
                    {
                        mPrevEvent.Recycle();
                        mPrevEvent = MotionEvent.Obtain(evt);
                    }
                }
                break;
            }
            }
        }
예제 #2
0
        /// <summary>
        /// Called when the current event occurred when a gesture IS in progress. The
        /// handling in this implementation may set the gesture out of progress.
        /// </summary>
        /// <param name="actionCode">Action code.</param>
        /// <param name="e">E.</param>
        protected override void HandleInProgressEvent(MotionEventActions actionCode, MotionEvent e)
        {
            if (e.PointerCount > 1)
            {
                switch (actionCode)
                {
                case MotionEventActions.PointerDown:
                    // At least the second finger is on the screen now.

                    ResetState();
                    _previousEvent = MotionEvent.Obtain(e);
                    _timeDelta     = 0;

                    UpdateStateByEvent(e);

                    // See if we have a sloppy gesture.
                    _sloppyGesture = this.IsSloppyGesture(e);
                    if (!_sloppyGesture)
                    {
                        // No, start gesture now.
                        _gestureInProgress = _listener.OnRotateBegin(this);
                    }
                    break;

                case MotionEventActions.Move:
                    if (!_sloppyGesture)
                    {
                        break;
                    }

                    // See if we still have a sloppy gesture
                    _sloppyGesture = this.IsSloppyGesture(e);
                    if (!_sloppyGesture)
                    {
                        _gestureInProgress = _listener.OnRotateBegin(this);
                    }

                    break;

                case MotionEventActions.PointerUp:
                    if (!_sloppyGesture)
                    {
                        break;
                    }

                    break;
                }
            }
            else
            { // the gesture has to stop!
                _gestureInProgress = false;
                _listener.OnRotateEnd(this);

                ResetState();
            }
        }
예제 #3
0
        protected internal override void HandleStartProgressEvent(MotionEventActions actionCode, MotionEvent
                                                                  evt)
        {
            switch (actionCode)
            {
            case MotionEventActions.PointerDown:
            {
                // At least the second finger is on screen now
                ResetState();
                // In case we missed an UP/CANCEL event
                mPrevEvent = MotionEvent.Obtain(evt);
                mTimeDelta = 0;
                UpdateStateByEvent(evt);
                // See if we have a sloppy gesture
                mSloppyGesture = IsSloppyGesture(evt);
                if (!mSloppyGesture)
                {
                    // No, start gesture now
                    mGestureInProgress = mListener.OnRotateBegin(this);
                }
                break;
            }

            case MotionEventActions.Move:
            {
                if (!mSloppyGesture)
                {
                    break;
                }
                // See if we still have a sloppy gesture
                mSloppyGesture = IsSloppyGesture(evt);
                if (!mSloppyGesture)
                {
                    // No, start normal gesture now
                    mGestureInProgress = mListener.OnRotateBegin(this);
                }
                break;
            }

            case MotionEventActions.PointerUp:
            {
                if (!mSloppyGesture)
                {
                    break;
                }
                break;
            }
            }
        }
예제 #4
0
        protected internal virtual void UpdateStateByEvent(MotionEvent curr)
        {
            MotionEvent prev = mPrevEvent;

            // Reset mCurrEvent
            if (mCurrEvent != null)
            {
                mCurrEvent.Recycle();
                mCurrEvent = null;
            }
            mCurrEvent = MotionEvent.Obtain(curr);
            // Delta time
            mTimeDelta = curr.EventTime - prev.EventTime;
            // Pressure
            mCurrPressure = curr.GetPressure(curr.ActionIndex);
            mPrevPressure = prev.GetPressure(prev.ActionIndex);
        }
예제 #5
0
        protected override void HandleStartProgressEvent(MotionEventActions actionCode, MotionEvent e)
        {
            switch (actionCode)
            {
            case MotionEventActions.PointerUp:
                // Gesture ended but
                UpdateStateByEvent(e);

                if (!_sloppyGesture)
                {
                    _listener.OnRotateEnd(this);
                }

                ResetState();
                break;

            case MotionEventActions.Cancel:
                if (!_sloppyGesture)
                {
                    _listener.OnRotateEnd(this);
                }

                ResetState();
                break;

            case MotionEventActions.Move:
                UpdateStateByEvent(e);

                // Only accept the event if our relative pressure is within
                // a certain limit. This can help filter shaky data as a
                // finger is lifted.
                if (_currentPressure / _previousPressure > PressureThreshold)
                {
                    bool updatePrevious = _listener.OnRotate(this);
                    if (updatePrevious)
                    {
                        if (_previousEvent != null)
                        {
                            _previousEvent.Recycle();
                        }
                        _previousEvent = MotionEvent.Obtain(e);
                    }
                }
                break;
            }
        }
예제 #6
0
        /// <summary>
        /// Called when the current event occurred when NO gesture is in progress
        /// yet. The handling in this implementation may set the gesture in progress
        /// or out of progress.
        /// </summary>
        /// <param name="actionCode">Action code.</param>
        /// <param name="e">The event.</param>
        protected override void HandleStartProgressEvent(MotionEventActions actionCode, MotionEvent e)
        {
            switch (actionCode)
            {
            case MotionEventActions.Down:
                ResetState();                  // In case we missed an UP/CANCEL event

                _previousEvent = MotionEvent.Obtain(e);
                _timeDelta     = 0;

                UpdateStateByEvent(e);
                break;

            case MotionEventActions.Move:
                _gestureInProgress = _listener.OnMoveBegin(this);
                break;
            }
        }
예제 #7
0
        /// <summary>
        /// Called when the current event occurred when NO gesture is in progress
        /// yet. The handling in this implementation may set the gesture in progress
        /// or out of progress.
        /// </summary>
        /// <param name="actionCode">Action code.</param>
        /// <param name="e">The event.</param>
        protected override void HandleStartProgressEvent(MotionEventActions actionCode, MotionEvent e)
        {
            switch (actionCode)
            {
            case MotionEventActions.Down:
                ResetState();                  // In case we missed an UP/CANCEL event
                _firstEventTime = e.EventTime;

                _previousEvent     = MotionEvent.Obtain(e);
                _timeDelta         = 0;
                _gestureInProgress = true;

                _x = e.GetX();
                _y = e.GetY();

                UpdateStateByEvent(e);
                break;

            case MotionEventActions.Move:
                break;
            }
        }
예제 #8
0
        protected internal override void HandleStartProgressEvent(MotionEventActions actionCode, MotionEvent
                                                                  evt)
        {
            switch (actionCode)
            {
            case MotionEventActions.Down:
            {
                ResetState();
                // In case we missed an UP/CANCEL event
                mPrevEvent = MotionEvent.Obtain(evt);
                mTimeDelta = 0;
                UpdateStateByEvent(evt);
                break;
            }

            case MotionEventActions.Move:
            {
                mGestureInProgress = mListener.OnMoveBegin(this);
                break;
            }
            }
        }
예제 #9
0
        /// <summary>
        /// Updates the current state with the given event.
        /// </summary>
        /// <param name="curr">The current event.</param>
        protected virtual void UpdateStateByEvent(MotionEvent curr)
        {
            MotionEvent prev = _previousEvent;

            // Reset _currentEvent.
            if (_currentEvent != null)
            {
                _currentEvent.Recycle();
                _currentEvent = null;
            }
            _currentEvent = MotionEvent.Obtain(curr);

            // Delta time.
            _timeDelta = 0;
            if (prev != null)
            {
                _timeDelta = curr.EventTime - prev.EventTime;

                // Pressure.
                _previousPressure = prev.GetPressure(prev.ActionIndex);
            }
            _currentPressure = curr.GetPressure(curr.ActionIndex);
        }