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

Commit 35538a4d authored by Gavin Williams's avatar Gavin Williams Committed by Android (Google) Code Review
Browse files

Merge "Autoclick: Improve scroll click testing" into main

parents a4f3d47a e7f540d1
Loading
Loading
Loading
Loading
+24 −9
Original line number Diff line number Diff line
@@ -525,13 +525,17 @@ public class AutoclickController extends BaseEventStreamTransformation implement
     */
    private boolean isPaused() {
        return Flags.enableAutoclickIndicator() && mAutoclickTypePanel.isPaused()
                && !isPanelHovered();
                && !isClickTypePanelHovered();
    }

    private boolean isPanelHovered() {
    private boolean isClickTypePanelHovered() {
        return Flags.enableAutoclickIndicator() && mAutoclickTypePanel.isHovered();
    }

    private boolean isScrollPanelHovered() {
        return Flags.enableAutoclickIndicator() && mAutoclickScrollPanel.isHovered();
    }

    private void cancelPendingClick() {
        if (mClickScheduler != null) {
            mClickScheduler.cancel();
@@ -1005,6 +1009,12 @@ public class AutoclickController extends BaseEventStreamTransformation implement
         */
        private static final double DEFAULT_MOVEMENT_SLOP = 20f;

        /**
         * A reduced minimal distance to make the closely spaced buttons easier to click. Used when
         * the pointer is hovering either the click type panel or the scroll panel.
         */
        private static final double PANEL_HOVERED_SLOP = 5f;

        private double mMovementSlop = DEFAULT_MOVEMENT_SLOP;

        /** Whether the minor cursor movement should be ignored. */
@@ -1258,7 +1268,7 @@ public class AutoclickController extends BaseEventStreamTransformation implement
            }
            mLastMotionEvent = MotionEvent.obtain(event);
            mEventPolicyFlags = policyFlags;
            mHoveredState = isPanelHovered();
            mHoveredState = isClickTypePanelHovered();

            if (useAsAnchor) {
                final int pointerIndex = mLastMotionEvent.getActionIndex();
@@ -1300,12 +1310,17 @@ public class AutoclickController extends BaseEventStreamTransformation implement
            float deltaY = mAnchorCoords.y - event.getY(pointerIndex);
            double delta = Math.hypot(deltaX, deltaY);

            // If the panel is hovered, always use the default slop so it's easier to click the
            // closely spaced buttons.
            double slop =
                    ((Flags.enableAutoclickIndicator() && !isPanelHovered())
                            ? mMovementSlop
                            : DEFAULT_MOVEMENT_SLOP);
            // If a panel is hovered, use the special slop to make clicking the panel buttons
            // easier.
            double slop;
            if (!Flags.enableAutoclickIndicator()) {
                slop = DEFAULT_MOVEMENT_SLOP;
            } else if (isClickTypePanelHovered() || isScrollPanelHovered()) {
                slop = PANEL_HOVERED_SLOP;
            } else {
                slop = mMovementSlop;
            }

            return delta > slop;
        }

+4 −5
Original line number Diff line number Diff line
@@ -341,6 +341,10 @@ public class AutoclickScrollPanel {
        });
    }

    public boolean isHovered() {
        return mContentView.isHovered();
    }

    /**
     * Retrieves the layout params for AutoclickScrollPanel, used when it's added to the Window
     * Manager.
@@ -368,11 +372,6 @@ public class AutoclickScrollPanel {
        return mInScrollMode;
    }

    @VisibleForTesting
    public boolean isHovered() {
        return mContentView.isHovered();
    }

    @VisibleForTesting
    public AutoclickLinearLayout getContentViewForTesting() {
        return mContentView;
+8 −6
Original line number Diff line number Diff line
@@ -201,14 +201,16 @@ class AutoclickClickTypeTests {
        changeClickType(uiDevice, desktopMouseTestRule, SCROLL_BUTTON_LAYOUT_ID)
        moveMouseToView(testClickButton)

        moveMouseToScrollButton(SCROLL_UP_BUTTON_LAYOUT_ID)
        // Scroll to each button in this order to prevent the exit button from being inadvertently
        // hovered.
        moveMouseToScrollButton(SCROLL_RIGHT_BUTTON_LAYOUT_ID)
        waitAndAssert {
            testClickButton.text == SCROLL_UP_TEXT
            testClickButton.text == SCROLL_RIGHT_TEXT
        }

        moveMouseToScrollButton(SCROLL_DOWN_BUTTON_LAYOUT_ID)
        moveMouseToScrollButton(SCROLL_UP_BUTTON_LAYOUT_ID)
        waitAndAssert {
            testClickButton.text == SCROLL_DOWN_TEXT
            testClickButton.text == SCROLL_UP_TEXT
        }

        moveMouseToScrollButton(SCROLL_LEFT_BUTTON_LAYOUT_ID)
@@ -216,9 +218,9 @@ class AutoclickClickTypeTests {
            testClickButton.text == SCROLL_LEFT_TEXT
        }

        moveMouseToScrollButton(SCROLL_RIGHT_BUTTON_LAYOUT_ID)
        moveMouseToScrollButton(SCROLL_DOWN_BUTTON_LAYOUT_ID)
        waitAndAssert {
            testClickButton.text == SCROLL_RIGHT_TEXT
            testClickButton.text == SCROLL_DOWN_TEXT
        }

        // Close the scroll panel.