Search in sources :

Example 1 with GesturePoint

use of android.gesture.GesturePoint in project android_frameworks_base by DirtyUnicorns.

the class AccessibilityGestureDetector method onMotionEvent.

/**
     * Handle a motion event.  If an action is completed, the appropriate
     * callback on mListener is called, and the return value of the callback is
     * passed to the caller.
     *
     * @param event The raw motion event.  It's important that this be the raw
     * event, before any transformations have been applied, so that measurements
     * can be made in physical units.
     * @param policyFlags Policy flags for the event.
     *
     * @return true if the event is consumed, else false
     */
public boolean onMotionEvent(MotionEvent event, int policyFlags) {
    final float x = event.getX();
    final float y = event.getY();
    final long time = event.getEventTime();
    mPolicyFlags = policyFlags;
    switch(event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            mDoubleTapDetected = false;
            mSecondFingerDoubleTap = false;
            mRecognizingGesture = true;
            mGestureStarted = false;
            mPreviousGestureX = x;
            mPreviousGestureY = y;
            mStrokeBuffer.clear();
            mStrokeBuffer.add(new GesturePoint(x, y, time));
            mBaseX = x;
            mBaseY = y;
            mBaseTime = time;
            break;
        case MotionEvent.ACTION_MOVE:
            if (mRecognizingGesture) {
                final float deltaX = mBaseX - x;
                final float deltaY = mBaseY - y;
                final double moveDelta = Math.hypot(deltaX, deltaY);
                if (moveDelta > mGestureDetectionThreshold) {
                    // If the pointer has moved more than the threshold,
                    // update the stored values.
                    mBaseX = x;
                    mBaseY = y;
                    mBaseTime = time;
                    // Since the pointer has moved, this is not a double
                    // tap.
                    mFirstTapDetected = false;
                    mDoubleTapDetected = false;
                    // the event.
                    if (!mGestureStarted) {
                        mGestureStarted = true;
                        return mListener.onGestureStarted();
                    }
                } else if (!mFirstTapDetected) {
                    // The finger may not move if they are double tapping.
                    // In that case, we shouldn't cancel the gesture.
                    final long timeDelta = time - mBaseTime;
                    final long threshold = mGestureStarted ? CANCEL_ON_PAUSE_THRESHOLD_STARTED_MS : CANCEL_ON_PAUSE_THRESHOLD_NOT_STARTED_MS;
                    // timeout, cancel gesture detection.
                    if (timeDelta > threshold) {
                        cancelGesture();
                        return mListener.onGestureCancelled(event, policyFlags);
                    }
                }
                final float dX = Math.abs(x - mPreviousGestureX);
                final float dY = Math.abs(y - mPreviousGestureY);
                if (dX >= TOUCH_TOLERANCE || dY >= TOUCH_TOLERANCE) {
                    mPreviousGestureX = x;
                    mPreviousGestureY = y;
                    mStrokeBuffer.add(new GesturePoint(x, y, time));
                }
            }
            break;
        case MotionEvent.ACTION_UP:
            if (mDoubleTapDetected) {
                return finishDoubleTap(event, policyFlags);
            }
            if (mGestureStarted) {
                mStrokeBuffer.add(new GesturePoint(x, y, time));
                return recognizeGesture(event, policyFlags);
            }
            break;
        case MotionEvent.ACTION_POINTER_DOWN:
            // Once a second finger is used, we're definitely not
            // recognizing a gesture.
            cancelGesture();
            if (event.getPointerCount() == 2) {
                // If this was the second finger, attempt to recognize double
                // taps on it.
                mSecondFingerDoubleTap = true;
                mSecondPointerDownTime = time;
            } else {
                // If there are more than two fingers down, stop watching
                // for a double tap.
                mSecondFingerDoubleTap = false;
            }
            break;
        case MotionEvent.ACTION_POINTER_UP:
            // should finish the double tap.
            if (mSecondFingerDoubleTap && mDoubleTapDetected) {
                return finishDoubleTap(event, policyFlags);
            }
            break;
        case MotionEvent.ACTION_CANCEL:
            clear();
            break;
    }
    // finger to the first finger.
    if (mSecondFingerDoubleTap) {
        MotionEvent newEvent = mapSecondPointerToFirstPointer(event);
        if (newEvent == null) {
            return false;
        }
        boolean handled = mGestureDetector.onTouchEvent(newEvent);
        newEvent.recycle();
        return handled;
    }
    if (!mRecognizingGesture) {
        return false;
    }
    // Pass the event on to the standard gesture detector.
    return mGestureDetector.onTouchEvent(event);
}
Also used : GesturePoint(android.gesture.GesturePoint) MotionEvent(android.view.MotionEvent)

Example 2 with GesturePoint

use of android.gesture.GesturePoint in project android_frameworks_base by crdroidandroid.

the class AccessibilityGestureDetector method onMotionEvent.

/**
     * Handle a motion event.  If an action is completed, the appropriate
     * callback on mListener is called, and the return value of the callback is
     * passed to the caller.
     *
     * @param event The raw motion event.  It's important that this be the raw
     * event, before any transformations have been applied, so that measurements
     * can be made in physical units.
     * @param policyFlags Policy flags for the event.
     *
     * @return true if the event is consumed, else false
     */
public boolean onMotionEvent(MotionEvent event, int policyFlags) {
    final float x = event.getX();
    final float y = event.getY();
    final long time = event.getEventTime();
    mPolicyFlags = policyFlags;
    switch(event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            mDoubleTapDetected = false;
            mSecondFingerDoubleTap = false;
            mRecognizingGesture = true;
            mGestureStarted = false;
            mPreviousGestureX = x;
            mPreviousGestureY = y;
            mStrokeBuffer.clear();
            mStrokeBuffer.add(new GesturePoint(x, y, time));
            mBaseX = x;
            mBaseY = y;
            mBaseTime = time;
            break;
        case MotionEvent.ACTION_MOVE:
            if (mRecognizingGesture) {
                final float deltaX = mBaseX - x;
                final float deltaY = mBaseY - y;
                final double moveDelta = Math.hypot(deltaX, deltaY);
                if (moveDelta > mGestureDetectionThreshold) {
                    // If the pointer has moved more than the threshold,
                    // update the stored values.
                    mBaseX = x;
                    mBaseY = y;
                    mBaseTime = time;
                    // Since the pointer has moved, this is not a double
                    // tap.
                    mFirstTapDetected = false;
                    mDoubleTapDetected = false;
                    // the event.
                    if (!mGestureStarted) {
                        mGestureStarted = true;
                        return mListener.onGestureStarted();
                    }
                } else if (!mFirstTapDetected) {
                    // The finger may not move if they are double tapping.
                    // In that case, we shouldn't cancel the gesture.
                    final long timeDelta = time - mBaseTime;
                    final long threshold = mGestureStarted ? CANCEL_ON_PAUSE_THRESHOLD_STARTED_MS : CANCEL_ON_PAUSE_THRESHOLD_NOT_STARTED_MS;
                    // timeout, cancel gesture detection.
                    if (timeDelta > threshold) {
                        cancelGesture();
                        return mListener.onGestureCancelled(event, policyFlags);
                    }
                }
                final float dX = Math.abs(x - mPreviousGestureX);
                final float dY = Math.abs(y - mPreviousGestureY);
                if (dX >= TOUCH_TOLERANCE || dY >= TOUCH_TOLERANCE) {
                    mPreviousGestureX = x;
                    mPreviousGestureY = y;
                    mStrokeBuffer.add(new GesturePoint(x, y, time));
                }
            }
            break;
        case MotionEvent.ACTION_UP:
            if (mDoubleTapDetected) {
                return finishDoubleTap(event, policyFlags);
            }
            if (mGestureStarted) {
                mStrokeBuffer.add(new GesturePoint(x, y, time));
                return recognizeGesture(event, policyFlags);
            }
            break;
        case MotionEvent.ACTION_POINTER_DOWN:
            // Once a second finger is used, we're definitely not
            // recognizing a gesture.
            cancelGesture();
            if (event.getPointerCount() == 2) {
                // If this was the second finger, attempt to recognize double
                // taps on it.
                mSecondFingerDoubleTap = true;
                mSecondPointerDownTime = time;
            } else {
                // If there are more than two fingers down, stop watching
                // for a double tap.
                mSecondFingerDoubleTap = false;
            }
            break;
        case MotionEvent.ACTION_POINTER_UP:
            // should finish the double tap.
            if (mSecondFingerDoubleTap && mDoubleTapDetected) {
                return finishDoubleTap(event, policyFlags);
            }
            break;
        case MotionEvent.ACTION_CANCEL:
            clear();
            break;
    }
    // finger to the first finger.
    if (mSecondFingerDoubleTap) {
        MotionEvent newEvent = mapSecondPointerToFirstPointer(event);
        if (newEvent == null) {
            return false;
        }
        boolean handled = mGestureDetector.onTouchEvent(newEvent);
        newEvent.recycle();
        return handled;
    }
    if (!mRecognizingGesture) {
        return false;
    }
    // Pass the event on to the standard gesture detector.
    return mGestureDetector.onTouchEvent(event);
}
Also used : GesturePoint(android.gesture.GesturePoint) MotionEvent(android.view.MotionEvent)

Example 3 with GesturePoint

use of android.gesture.GesturePoint in project platform_frameworks_base by android.

the class AccessibilityGestureDetector method onMotionEvent.

/**
     * Handle a motion event.  If an action is completed, the appropriate
     * callback on mListener is called, and the return value of the callback is
     * passed to the caller.
     *
     * @param event The raw motion event.  It's important that this be the raw
     * event, before any transformations have been applied, so that measurements
     * can be made in physical units.
     * @param policyFlags Policy flags for the event.
     *
     * @return true if the event is consumed, else false
     */
public boolean onMotionEvent(MotionEvent event, int policyFlags) {
    final float x = event.getX();
    final float y = event.getY();
    final long time = event.getEventTime();
    mPolicyFlags = policyFlags;
    switch(event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            mDoubleTapDetected = false;
            mSecondFingerDoubleTap = false;
            mRecognizingGesture = true;
            mGestureStarted = false;
            mPreviousGestureX = x;
            mPreviousGestureY = y;
            mStrokeBuffer.clear();
            mStrokeBuffer.add(new GesturePoint(x, y, time));
            mBaseX = x;
            mBaseY = y;
            mBaseTime = time;
            break;
        case MotionEvent.ACTION_MOVE:
            if (mRecognizingGesture) {
                final float deltaX = mBaseX - x;
                final float deltaY = mBaseY - y;
                final double moveDelta = Math.hypot(deltaX, deltaY);
                if (moveDelta > mGestureDetectionThreshold) {
                    // If the pointer has moved more than the threshold,
                    // update the stored values.
                    mBaseX = x;
                    mBaseY = y;
                    mBaseTime = time;
                    // Since the pointer has moved, this is not a double
                    // tap.
                    mFirstTapDetected = false;
                    mDoubleTapDetected = false;
                    // the event.
                    if (!mGestureStarted) {
                        mGestureStarted = true;
                        return mListener.onGestureStarted();
                    }
                } else if (!mFirstTapDetected) {
                    // The finger may not move if they are double tapping.
                    // In that case, we shouldn't cancel the gesture.
                    final long timeDelta = time - mBaseTime;
                    final long threshold = mGestureStarted ? CANCEL_ON_PAUSE_THRESHOLD_STARTED_MS : CANCEL_ON_PAUSE_THRESHOLD_NOT_STARTED_MS;
                    // timeout, cancel gesture detection.
                    if (timeDelta > threshold) {
                        cancelGesture();
                        return mListener.onGestureCancelled(event, policyFlags);
                    }
                }
                final float dX = Math.abs(x - mPreviousGestureX);
                final float dY = Math.abs(y - mPreviousGestureY);
                if (dX >= TOUCH_TOLERANCE || dY >= TOUCH_TOLERANCE) {
                    mPreviousGestureX = x;
                    mPreviousGestureY = y;
                    mStrokeBuffer.add(new GesturePoint(x, y, time));
                }
            }
            break;
        case MotionEvent.ACTION_UP:
            if (mDoubleTapDetected) {
                return finishDoubleTap(event, policyFlags);
            }
            if (mGestureStarted) {
                mStrokeBuffer.add(new GesturePoint(x, y, time));
                return recognizeGesture(event, policyFlags);
            }
            break;
        case MotionEvent.ACTION_POINTER_DOWN:
            // Once a second finger is used, we're definitely not
            // recognizing a gesture.
            cancelGesture();
            if (event.getPointerCount() == 2) {
                // If this was the second finger, attempt to recognize double
                // taps on it.
                mSecondFingerDoubleTap = true;
                mSecondPointerDownTime = time;
            } else {
                // If there are more than two fingers down, stop watching
                // for a double tap.
                mSecondFingerDoubleTap = false;
            }
            break;
        case MotionEvent.ACTION_POINTER_UP:
            // should finish the double tap.
            if (mSecondFingerDoubleTap && mDoubleTapDetected) {
                return finishDoubleTap(event, policyFlags);
            }
            break;
        case MotionEvent.ACTION_CANCEL:
            clear();
            break;
    }
    // finger to the first finger.
    if (mSecondFingerDoubleTap) {
        MotionEvent newEvent = mapSecondPointerToFirstPointer(event);
        if (newEvent == null) {
            return false;
        }
        boolean handled = mGestureDetector.onTouchEvent(newEvent);
        newEvent.recycle();
        return handled;
    }
    if (!mRecognizingGesture) {
        return false;
    }
    // Pass the event on to the standard gesture detector.
    return mGestureDetector.onTouchEvent(event);
}
Also used : GesturePoint(android.gesture.GesturePoint) MotionEvent(android.view.MotionEvent)

Example 4 with GesturePoint

use of android.gesture.GesturePoint in project android_frameworks_base by AOSPA.

the class AccessibilityGestureDetector method onMotionEvent.

/**
     * Handle a motion event.  If an action is completed, the appropriate
     * callback on mListener is called, and the return value of the callback is
     * passed to the caller.
     *
     * @param event The raw motion event.  It's important that this be the raw
     * event, before any transformations have been applied, so that measurements
     * can be made in physical units.
     * @param policyFlags Policy flags for the event.
     *
     * @return true if the event is consumed, else false
     */
public boolean onMotionEvent(MotionEvent event, int policyFlags) {
    final float x = event.getX();
    final float y = event.getY();
    final long time = event.getEventTime();
    mPolicyFlags = policyFlags;
    switch(event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            mDoubleTapDetected = false;
            mSecondFingerDoubleTap = false;
            mRecognizingGesture = true;
            mGestureStarted = false;
            mPreviousGestureX = x;
            mPreviousGestureY = y;
            mStrokeBuffer.clear();
            mStrokeBuffer.add(new GesturePoint(x, y, time));
            mBaseX = x;
            mBaseY = y;
            mBaseTime = time;
            break;
        case MotionEvent.ACTION_MOVE:
            if (mRecognizingGesture) {
                final float deltaX = mBaseX - x;
                final float deltaY = mBaseY - y;
                final double moveDelta = Math.hypot(deltaX, deltaY);
                if (moveDelta > mGestureDetectionThreshold) {
                    // If the pointer has moved more than the threshold,
                    // update the stored values.
                    mBaseX = x;
                    mBaseY = y;
                    mBaseTime = time;
                    // Since the pointer has moved, this is not a double
                    // tap.
                    mFirstTapDetected = false;
                    mDoubleTapDetected = false;
                    // the event.
                    if (!mGestureStarted) {
                        mGestureStarted = true;
                        return mListener.onGestureStarted();
                    }
                } else if (!mFirstTapDetected) {
                    // The finger may not move if they are double tapping.
                    // In that case, we shouldn't cancel the gesture.
                    final long timeDelta = time - mBaseTime;
                    final long threshold = mGestureStarted ? CANCEL_ON_PAUSE_THRESHOLD_STARTED_MS : CANCEL_ON_PAUSE_THRESHOLD_NOT_STARTED_MS;
                    // timeout, cancel gesture detection.
                    if (timeDelta > threshold) {
                        cancelGesture();
                        return mListener.onGestureCancelled(event, policyFlags);
                    }
                }
                final float dX = Math.abs(x - mPreviousGestureX);
                final float dY = Math.abs(y - mPreviousGestureY);
                if (dX >= TOUCH_TOLERANCE || dY >= TOUCH_TOLERANCE) {
                    mPreviousGestureX = x;
                    mPreviousGestureY = y;
                    mStrokeBuffer.add(new GesturePoint(x, y, time));
                }
            }
            break;
        case MotionEvent.ACTION_UP:
            if (mDoubleTapDetected) {
                return finishDoubleTap(event, policyFlags);
            }
            if (mGestureStarted) {
                mStrokeBuffer.add(new GesturePoint(x, y, time));
                return recognizeGesture(event, policyFlags);
            }
            break;
        case MotionEvent.ACTION_POINTER_DOWN:
            // Once a second finger is used, we're definitely not
            // recognizing a gesture.
            cancelGesture();
            if (event.getPointerCount() == 2) {
                // If this was the second finger, attempt to recognize double
                // taps on it.
                mSecondFingerDoubleTap = true;
                mSecondPointerDownTime = time;
            } else {
                // If there are more than two fingers down, stop watching
                // for a double tap.
                mSecondFingerDoubleTap = false;
            }
            break;
        case MotionEvent.ACTION_POINTER_UP:
            // should finish the double tap.
            if (mSecondFingerDoubleTap && mDoubleTapDetected) {
                return finishDoubleTap(event, policyFlags);
            }
            break;
        case MotionEvent.ACTION_CANCEL:
            clear();
            break;
    }
    // finger to the first finger.
    if (mSecondFingerDoubleTap) {
        MotionEvent newEvent = mapSecondPointerToFirstPointer(event);
        if (newEvent == null) {
            return false;
        }
        boolean handled = mGestureDetector.onTouchEvent(newEvent);
        newEvent.recycle();
        return handled;
    }
    if (!mRecognizingGesture) {
        return false;
    }
    // Pass the event on to the standard gesture detector.
    return mGestureDetector.onTouchEvent(event);
}
Also used : GesturePoint(android.gesture.GesturePoint) MotionEvent(android.view.MotionEvent)

Example 5 with GesturePoint

use of android.gesture.GesturePoint in project android_frameworks_base by ResurrectionRemix.

the class AccessibilityGestureDetector method onMotionEvent.

/**
     * Handle a motion event.  If an action is completed, the appropriate
     * callback on mListener is called, and the return value of the callback is
     * passed to the caller.
     *
     * @param event The raw motion event.  It's important that this be the raw
     * event, before any transformations have been applied, so that measurements
     * can be made in physical units.
     * @param policyFlags Policy flags for the event.
     *
     * @return true if the event is consumed, else false
     */
public boolean onMotionEvent(MotionEvent event, int policyFlags) {
    final float x = event.getX();
    final float y = event.getY();
    final long time = event.getEventTime();
    mPolicyFlags = policyFlags;
    switch(event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            mDoubleTapDetected = false;
            mSecondFingerDoubleTap = false;
            mRecognizingGesture = true;
            mGestureStarted = false;
            mPreviousGestureX = x;
            mPreviousGestureY = y;
            mStrokeBuffer.clear();
            mStrokeBuffer.add(new GesturePoint(x, y, time));
            mBaseX = x;
            mBaseY = y;
            mBaseTime = time;
            break;
        case MotionEvent.ACTION_MOVE:
            if (mRecognizingGesture) {
                final float deltaX = mBaseX - x;
                final float deltaY = mBaseY - y;
                final double moveDelta = Math.hypot(deltaX, deltaY);
                if (moveDelta > mGestureDetectionThreshold) {
                    // If the pointer has moved more than the threshold,
                    // update the stored values.
                    mBaseX = x;
                    mBaseY = y;
                    mBaseTime = time;
                    // Since the pointer has moved, this is not a double
                    // tap.
                    mFirstTapDetected = false;
                    mDoubleTapDetected = false;
                    // the event.
                    if (!mGestureStarted) {
                        mGestureStarted = true;
                        return mListener.onGestureStarted();
                    }
                } else if (!mFirstTapDetected) {
                    // The finger may not move if they are double tapping.
                    // In that case, we shouldn't cancel the gesture.
                    final long timeDelta = time - mBaseTime;
                    final long threshold = mGestureStarted ? CANCEL_ON_PAUSE_THRESHOLD_STARTED_MS : CANCEL_ON_PAUSE_THRESHOLD_NOT_STARTED_MS;
                    // timeout, cancel gesture detection.
                    if (timeDelta > threshold) {
                        cancelGesture();
                        return mListener.onGestureCancelled(event, policyFlags);
                    }
                }
                final float dX = Math.abs(x - mPreviousGestureX);
                final float dY = Math.abs(y - mPreviousGestureY);
                if (dX >= TOUCH_TOLERANCE || dY >= TOUCH_TOLERANCE) {
                    mPreviousGestureX = x;
                    mPreviousGestureY = y;
                    mStrokeBuffer.add(new GesturePoint(x, y, time));
                }
            }
            break;
        case MotionEvent.ACTION_UP:
            if (mDoubleTapDetected) {
                return finishDoubleTap(event, policyFlags);
            }
            if (mGestureStarted) {
                mStrokeBuffer.add(new GesturePoint(x, y, time));
                return recognizeGesture(event, policyFlags);
            }
            break;
        case MotionEvent.ACTION_POINTER_DOWN:
            // Once a second finger is used, we're definitely not
            // recognizing a gesture.
            cancelGesture();
            if (event.getPointerCount() == 2) {
                // If this was the second finger, attempt to recognize double
                // taps on it.
                mSecondFingerDoubleTap = true;
                mSecondPointerDownTime = time;
            } else {
                // If there are more than two fingers down, stop watching
                // for a double tap.
                mSecondFingerDoubleTap = false;
            }
            break;
        case MotionEvent.ACTION_POINTER_UP:
            // should finish the double tap.
            if (mSecondFingerDoubleTap && mDoubleTapDetected) {
                return finishDoubleTap(event, policyFlags);
            }
            break;
        case MotionEvent.ACTION_CANCEL:
            clear();
            break;
    }
    // finger to the first finger.
    if (mSecondFingerDoubleTap) {
        MotionEvent newEvent = mapSecondPointerToFirstPointer(event);
        if (newEvent == null) {
            return false;
        }
        boolean handled = mGestureDetector.onTouchEvent(newEvent);
        newEvent.recycle();
        return handled;
    }
    if (!mRecognizingGesture) {
        return false;
    }
    // Pass the event on to the standard gesture detector.
    return mGestureDetector.onTouchEvent(event);
}
Also used : GesturePoint(android.gesture.GesturePoint) MotionEvent(android.view.MotionEvent)

Aggregations

GesturePoint (android.gesture.GesturePoint)5 MotionEvent (android.view.MotionEvent)5