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

Commit 14b30ae4 authored by Ben Lin's avatar Ben Lin Committed by Android (Google) Code Review
Browse files

Merge "Better event handling when coming from a trackpad." into arc-apps

parents 382d63e6 f88bc0b6
Loading
Loading
Loading
Loading
+48 −1
Original line number Diff line number Diff line
@@ -134,6 +134,20 @@ public final class Events {
        /** Returns true if the action is the final release of a mouse or touch. */
        boolean isActionUp();

        /**
         * Returns true when the action is the initial press of a non-primary (ex. second finger)
         * pointer.
         * See {@link MotionEvent#ACTION_POINTER_DOWN}.
         */
        boolean isMultiPointerActionDown();

        /**
         * Returns true when the action is the final of a non-primary (ex. second finger)
         * pointer.
         * * See {@link MotionEvent#ACTION_POINTER_UP}.
         */
        boolean isMultiPointerActionUp();

        /** Returns true if the action is neither the initial nor the final release of a mouse
         * or touch. */
        boolean isActionMove();
@@ -150,6 +164,7 @@ public final class Events {
        float getY();
        float getRawX();
        float getRawY();
        int getPointerCount();

        /** Returns true if there is an item under the finger/cursor. */
        boolean isOverItem();
@@ -161,9 +176,17 @@ public final class Events {
         */
        boolean isOverModelItem();

        /** Returns true if the event is over an area that can be dragged via touch */
        /**
         * Returns true if the event is over an area that can be dragged via touch.
         * List items have a white area that is not draggable.
         */
        boolean isOverDragHotspot();

        /**
         * Returns true if the event is a two/three-finger scroll on touchpad.
         */
        boolean isTouchpadScroll();

        /** Returns the adapter position of the item under the finger/cursor. */
        int getItemPosition();

@@ -267,6 +290,17 @@ public final class Events {
            return mEvent.getActionMasked() == MotionEvent.ACTION_UP;
        }

        @Override
        public boolean isMultiPointerActionDown() {
            return mEvent.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN;
        }

        @Override
        public boolean isMultiPointerActionUp() {
            return mEvent.getActionMasked() == MotionEvent.ACTION_POINTER_UP;
        }


        @Override
        public boolean isActionMove() {
            return mEvent.getActionMasked() == MotionEvent.ACTION_MOVE;
@@ -302,6 +336,18 @@ public final class Events {
            return mEvent.getRawY();
        }

        @Override
        public int getPointerCount() {
            return mEvent.getPointerCount();
        }

        @Override
        public boolean isTouchpadScroll() {
            // Touchpad inputs are treated as mouse inputs, and when scrolling, there are no buttons
            // returned.
            return isMouseEvent() && isActionMove() && mEvent.getButtonState() == 0;
        }

        @Override
        public boolean isOverDragHotspot() {
            return isOverItem() ? getDocumentDetails().isInDragHotspot(this) : false;
@@ -357,6 +403,7 @@ public final class Events {
                    .append(" isOverItem=").append(isOverItem())
                    .append(" getItemPosition=").append(getItemPosition())
                    .append(" getDocumentDetails=").append(getDocumentDetails())
                    .append(" getPointerCount=").append(getPointerCount())
                    .append("}")
                    .toString();
        }
+2 −1
Original line number Diff line number Diff line
@@ -305,7 +305,8 @@ public final class UserInputHandler<T extends InputEvent>
        // Don't scroll content window in response to mouse drag
        boolean onScroll(T event) {
            if (VERBOSE) Log.v(MTAG, "Delegated onScroll event.");
            return true;
            // If it's two-finger trackpad scrolling, we want to scroll
            return !event.isTouchpadScroll();
        }

        boolean onSingleTapUp(T event) {
+7 −5
Original line number Diff line number Diff line
@@ -82,7 +82,8 @@ public class BandController extends OnScrollListener {
        this(new RuntimeSelectionEnvironment(view), adapter, selectionManager, lock, gridItemTester);
    }

    private BandController(
    @VisibleForTesting
    BandController(
            SelectionEnvironment env,
            DocumentsAdapter adapter,
            SelectionManager selectionManager,
@@ -174,7 +175,8 @@ public class BandController extends OnScrollListener {
        };
    }

    private boolean isActive() {
    @VisibleForTesting
    boolean isActive() {
        return mModel != null;
    }

@@ -210,8 +212,8 @@ public class BandController extends OnScrollListener {
    }

    public boolean shouldStart(InputEvent e) {
        // Don't start, or extend bands on right click.
        if (e.isSecondaryButtonPressed()) {
        // Don't start, or extend bands on non-left clicks.
        if (!e.isPrimaryButtonPressed()) {
            return false;
        }

@@ -237,7 +239,7 @@ public class BandController extends OnScrollListener {
    public boolean shouldStop(InputEvent input) {
        return isActive()
                && input.isMouseEvent()
                && (input.isActionUp() || input.isActionCancel());
                && (input.isActionUp() || input.isMultiPointerActionUp() || input.isActionCancel());
    }

    /**
+35 −6
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ public class TestEvent implements InputEvent {

    private @Action int mAction;
    private @ToolType int mToolType;
    private int mPointerCount;
    private Set<Integer> mButtons;
    private Set<Integer> mKeys;
    private Point mLocation;
@@ -87,6 +88,7 @@ public class TestEvent implements InputEvent {
        mLocation = new Point(0, 0);
        mRawLocation = new Point(0, 0);
        mDetails = new Details();
        mPointerCount = 0;
    }

    private TestEvent(TestEvent source) {
@@ -98,6 +100,7 @@ public class TestEvent implements InputEvent {
        mLocation = source.mLocation;
        mRawLocation = source.mRawLocation;
        mDetails = new Details(source.mDetails);
        mPointerCount = source.mPointerCount;
    }

    @Override
@@ -125,6 +128,11 @@ public class TestEvent implements InputEvent {
        return mRawLocation.y;
    }

    @Override
    public int getPointerCount() {
        return mPointerCount;
    }

    @Override
    public boolean isMouseEvent() {
        return mToolType == MotionEvent.TOOL_TYPE_MOUSE;
@@ -170,6 +178,16 @@ public class TestEvent implements InputEvent {
        return mAction == MotionEvent.ACTION_UP;
    }

    @Override
    public boolean isMultiPointerActionDown() {
        return mAction == MotionEvent.ACTION_POINTER_DOWN;
    }

    @Override
    public boolean isMultiPointerActionUp() {
        return mAction == MotionEvent.ACTION_POINTER_UP;
    }

    @Override
    public boolean isActionMove() {
        return mAction == MotionEvent.ACTION_MOVE;
@@ -187,7 +205,7 @@ public class TestEvent implements InputEvent {

    @Override
    public boolean isOverDragHotspot() {
        return mDetails.isOverInteractiveArea();
        return isOverItem() && mDetails.isInDragHotspot(this);
    }

    @Override
@@ -199,6 +217,11 @@ public class TestEvent implements InputEvent {
        return false;
    }

    @Override
    public boolean isTouchpadScroll() {
        return isMouseEvent() && mButtons.isEmpty() && isActionMove();
    }

    @Override
    public int getItemPosition() {
        return mDetails.mPosition;
@@ -260,10 +283,6 @@ public class TestEvent implements InputEvent {
            return mPosition != Integer.MIN_VALUE && mPosition != RecyclerView.NO_POSITION;
        }

        private boolean isOverInteractiveArea() {
            return mPosition != Integer.MIN_VALUE && mPosition != RecyclerView.NO_POSITION;
        }

        @Override
        public boolean hasModelId() {
            return !TextUtils.isEmpty(mModelId);
@@ -352,6 +371,11 @@ public class TestEvent implements InputEvent {
            return this;
        }

        public Builder pointerCount(int count) {
            mState.mPointerCount = count;
            return this;
        }

        /**
         * Adds one or more button press attributes.
         */
@@ -408,6 +432,11 @@ public class TestEvent implements InputEvent {
            return this;
        }

        public Builder notInDragHotspot() {
            mState.mDetails.mInDragHotspot = false;
            return this;
        }

        public Builder touch() {
            type(MotionEvent.TOOL_TYPE_FINGER);
            return this;
+1 −0
Original line number Diff line number Diff line
@@ -90,6 +90,7 @@ public class DragStartListenerTest extends AndroidTestCase {
                .action(MotionEvent.ACTION_MOVE)
                .mouse()
                .at(1)
                .inDragHotspot()
                .primary();
    }

Loading