Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ac1b31da authored by Dennis Kempin's avatar Dennis Kempin Committed by Prameet Shah
Browse files

Disable touch slop for generated gesture events

This accounts for a special flag for gesture events generated by
InputFlinger. For these events we do not need a touch slop since we
can reliably tell that the intention is to scroll.

Bug: 31799135
Bug: 32944705
Test: None
Change-Id: Ibca8eaebca61bd4eb401708f5b19463c19c23309
(cherry picked from commit 8e07f0f91d8e6e8965faaaadc94b4bac18ba3310)
(cherry picked from commit 3e1b4218e6f0117e58a5452bcb725b105d32b528)
parent 6deaa4c8
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -502,6 +502,8 @@ public class GestureDetector {
        final boolean pointerUp =
                (action & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_UP;
        final int skipIndex = pointerUp ? ev.getActionIndex() : -1;
        final boolean isGeneratedGesture =
                (ev.getFlags() & MotionEvent.FLAG_IS_GENERATED_GESTURE) != 0;

        // Determine focal point
        float sumX = 0, sumY = 0;
@@ -604,7 +606,8 @@ public class GestureDetector {
                final int deltaX = (int) (focusX - mDownFocusX);
                final int deltaY = (int) (focusY - mDownFocusY);
                int distance = (deltaX * deltaX) + (deltaY * deltaY);
                if (distance > mTouchSlopSquare) {
                int slopSquare = isGeneratedGesture ? 0 : mTouchSlopSquare;
                if (distance > slopSquare) {
                    handled = mListener.onScroll(mCurrentDownEvent, ev, scrollX, scrollY);
                    mLastFocusX = focusX;
                    mLastFocusY = focusY;
@@ -613,7 +616,8 @@ public class GestureDetector {
                    mHandler.removeMessages(SHOW_PRESS);
                    mHandler.removeMessages(LONG_PRESS);
                }
                if (distance > mDoubleTapTouchSlopSquare) {
                int doubleTapSlopSquare = isGeneratedGesture ? 0 : mDoubleTapTouchSlopSquare;
                if (distance > doubleTapSlopSquare) {
                    mAlwaysInBiggerTapRegion = false;
                }
            } else if ((Math.abs(scrollX) >= 1) || (Math.abs(scrollY) >= 1)) {
@@ -761,7 +765,10 @@ public class GestureDetector {

        int deltaX = (int) firstDown.getX() - (int) secondDown.getX();
        int deltaY = (int) firstDown.getY() - (int) secondDown.getY();
        return (deltaX * deltaX + deltaY * deltaY < mDoubleTapSlopSquare);
        final boolean isGeneratedGesture =
                (firstDown.getFlags() & MotionEvent.FLAG_IS_GENERATED_GESTURE) != 0;
        int slopSquare = isGeneratedGesture ? 0 : mDoubleTapSlopSquare;
        return (deltaX * deltaX + deltaY * deltaY < slopSquare);
    }

    private void dispatchLongPress() {
+62 −54
Original line number Diff line number Diff line
@@ -443,6 +443,14 @@ public final class MotionEvent extends InputEvent implements Parcelable {
     */
    public static final int FLAG_HOVER_EXIT_PENDING = 0x4;

    /**
     * This flag indicates that the event has been generated by a gesture generator. It
     * provides a hint to the GestureDector to not apply any touch slop.
     *
     * @hide
     */
    public static final int FLAG_IS_GENERATED_GESTURE = 0x8;

    /**
     * Private flag that indicates when the system has detected that this motion event
     * may be inconsistent with respect to the sequence of previously delivered motion events,