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

Commit 3a52fbb4 authored by Longbo Wei's avatar Longbo Wei Committed by Android (Google) Code Review
Browse files

Merge "a11y: Remove CurrentCornerIndex" into main

parents f43cd7d7 d290e702
Loading
Loading
Loading
Loading
+14 −22
Original line number Diff line number Diff line
@@ -86,13 +86,6 @@ public class AutoclickTypePanel {
    })
    public @interface Corner {}

    private static final @Corner int[] CORNER_ROTATION_ORDER = {
            CORNER_BOTTOM_RIGHT,
            CORNER_BOTTOM_LEFT,
            CORNER_TOP_LEFT,
            CORNER_TOP_RIGHT
    };

    // An interface exposed to {@link AutoclickController) to handle different actions on the panel,
    // including changing autoclick type, pausing/resuming autoclick.
    public interface ClickPanelControllerInterface {
@@ -136,10 +129,9 @@ public class AutoclickTypePanel {

    // Whether autoclick is paused.
    private boolean mPaused = false;
    // Tracks the current corner position of the panel using an index into CORNER_ROTATION_ORDER
    // array. This allows the panel to cycle through screen corners in a defined sequence when
    // repositioned.
    private int mCurrentCornerIndex = 0;

    // The current corner position of the panel, default to bottom right.
    private @Corner int mCurrentCorner = CORNER_BOTTOM_RIGHT;

    private final LinearLayout mLeftClickButton;
    private final LinearLayout mRightClickButton;
@@ -257,13 +249,13 @@ public class AutoclickTypePanel {
            params.gravity = Gravity.START | Gravity.TOP;
            // Set the current corner to be bottom-left to ensure that the subsequent reposition
            // action rotates the panel clockwise from bottom-left towards top-left.
            mCurrentCornerIndex = 1;
            mCurrentCorner = CORNER_BOTTOM_LEFT;
        } else {
            // Snap to right edge. Set params.gravity to make sure x, y offsets from correct anchor.
            params.gravity = Gravity.END | Gravity.TOP;
            // Set the current corner to be top-right to ensure that the subsequent reposition
            // action rotates the panel clockwise from top-right towards bottom-right.
            mCurrentCornerIndex = 3;
            mCurrentCorner = CORNER_TOP_RIGHT;
        }

        // Apply final position: set params.x to be edge margin, params.y to maintain vertical
@@ -415,10 +407,10 @@ public class AutoclickTypePanel {

    /** Moves the panel to the next corner in clockwise direction. */
    private void moveToNextCorner() {
        @Corner int nextCornerIndex = (mCurrentCornerIndex + 1) % CORNER_ROTATION_ORDER.length;
        mCurrentCornerIndex = nextCornerIndex;
        @Corner int nextCorner = (mCurrentCorner + 1) % 4;
        mCurrentCorner = nextCorner;

        setPanelPositionForCorner(mParams, mCurrentCornerIndex);
        setPanelPositionForCorner(mParams, mCurrentCorner);
        mWindowManager.updateViewLayout(mContentView, mParams);
    }

@@ -457,7 +449,7 @@ public class AutoclickTypePanel {
                String.valueOf(mParams.gravity),
                String.valueOf(mParams.x),
                String.valueOf(mParams.y),
                String.valueOf(mCurrentCornerIndex)
                String.valueOf(mCurrentCorner)
        });
        Settings.Secure.putStringForUser(mContext.getContentResolver(),
                ACCESSIBILITY_AUTOCLICK_PANEL_POSITION, positionString, mUserId);
@@ -473,7 +465,7 @@ public class AutoclickTypePanel {
                ACCESSIBILITY_AUTOCLICK_PANEL_POSITION, mUserId);
        if (savedPosition == null) {
            setPanelPositionForCorner(mParams, CORNER_BOTTOM_RIGHT);
            mCurrentCornerIndex = 0;
            mCurrentCorner = CORNER_BOTTOM_RIGHT;
            return;
        }

@@ -481,7 +473,7 @@ public class AutoclickTypePanel {
        String[] parts = TextUtils.split(savedPosition, POSITION_DELIMITER);
        if (!isValidPositionParts(parts)) {
            setPanelPositionForCorner(mParams, CORNER_BOTTOM_RIGHT);
            mCurrentCornerIndex = 0;
            mCurrentCorner = CORNER_BOTTOM_RIGHT;
            return;
        }

@@ -489,7 +481,7 @@ public class AutoclickTypePanel {
        mParams.gravity = Integer.parseInt(parts[0]);
        mParams.x = Integer.parseInt(parts[1]);
        mParams.y = Integer.parseInt(parts[2]);
        mCurrentCornerIndex = Integer.parseInt(parts[3]);
        mCurrentCorner = Integer.parseInt(parts[3]);
    }

    private boolean isValidPositionParts(String[] parts) {
@@ -538,8 +530,8 @@ public class AutoclickTypePanel {

    @VisibleForTesting
    @Corner
    int getCurrentCornerIndexForTesting() {
        return mCurrentCornerIndex;
    int getCurrentCornerForTesting() {
        return mCurrentCorner;
    }

    @VisibleForTesting
+13 −13
Original line number Diff line number Diff line
@@ -201,11 +201,11 @@ public class AutoclickTypePanelTest {
    public void moveToNextCorner_positionButton_rotatesThroughAllPositions() {
        // Define all positions in sequence
        int[][] expectedPositions = {
                {0, Gravity.END | Gravity.BOTTOM, /*x=*/ 15, /*y=*/ 90},
                {1, Gravity.START | Gravity.BOTTOM, /*x=*/ 15, /*y=*/ 90},
                {2, Gravity.START | Gravity.TOP, /*x=*/ 15, /*y=*/ 30},
                {3, Gravity.END | Gravity.TOP, /*x=*/ 15, /*y=*/ 30},
                {0, Gravity.END | Gravity.BOTTOM, /*x=*/ 15, /*y=*/ 90}
                {CORNER_BOTTOM_RIGHT, Gravity.END | Gravity.BOTTOM, /*x=*/ 15, /*y=*/ 90},
                {CORNER_BOTTOM_LEFT, Gravity.START | Gravity.BOTTOM, /*x=*/ 15, /*y=*/ 90},
                {CORNER_TOP_LEFT, Gravity.START | Gravity.TOP, /*x=*/ 15, /*y=*/ 30},
                {CORNER_TOP_RIGHT, Gravity.END | Gravity.TOP, /*x=*/ 15, /*y=*/ 30},
                {CORNER_BOTTOM_RIGHT, Gravity.END | Gravity.BOTTOM, /*x=*/ 15, /*y=*/ 90}
        };

        // Check initial position
@@ -270,7 +270,7 @@ public class AutoclickTypePanelTest {
        int screenWidth = mTestableContext.getResources().getDisplayMetrics().widthPixels;

        // Verify initial corner is bottom-right.
        assertThat(mAutoclickTypePanel.getCurrentCornerIndexForTesting())
        assertThat(mAutoclickTypePanel.getCurrentCornerForTesting())
                .isEqualTo(CORNER_BOTTOM_RIGHT);

        dispatchDragSequence(contentView,
@@ -279,7 +279,7 @@ public class AutoclickTypePanelTest {

        // Verify snapping to the right.
        assertThat(params.gravity).isEqualTo(Gravity.END | Gravity.TOP);
        assertThat(mAutoclickTypePanel.getCurrentCornerIndexForTesting())
        assertThat(mAutoclickTypePanel.getCurrentCornerForTesting())
                .isEqualTo(CORNER_TOP_RIGHT);
    }

@@ -293,7 +293,7 @@ public class AutoclickTypePanelTest {
        int screenWidth = mTestableContext.getResources().getDisplayMetrics().widthPixels;

        // Verify initial corner is bottom-right.
        assertThat(mAutoclickTypePanel.getCurrentCornerIndexForTesting())
        assertThat(mAutoclickTypePanel.getCurrentCornerForTesting())
                .isEqualTo(CORNER_BOTTOM_RIGHT);

        dispatchDragSequence(contentView,
@@ -302,7 +302,7 @@ public class AutoclickTypePanelTest {

        // Verify snapping to the left.
        assertThat(params.gravity).isEqualTo(Gravity.START | Gravity.TOP);
        assertThat(mAutoclickTypePanel.getCurrentCornerIndexForTesting())
        assertThat(mAutoclickTypePanel.getCurrentCornerForTesting())
                .isEqualTo(CORNER_BOTTOM_LEFT);
    }

@@ -319,7 +319,7 @@ public class AutoclickTypePanelTest {

        // Verify panel is positioned at default bottom-right corner.
        WindowManager.LayoutParams params = panel.getLayoutParamsForTesting();
        assertThat(panel.getCurrentCornerIndexForTesting()).isEqualTo(CORNER_BOTTOM_RIGHT);
        assertThat(panel.getCurrentCornerForTesting()).isEqualTo(CORNER_BOTTOM_RIGHT);
        assertThat(params.gravity).isEqualTo(Gravity.END | Gravity.BOTTOM);
        assertThat(params.x).isEqualTo(15);  // Default edge margin.
        assertThat(params.y).isEqualTo(90);  // Default bottom offset.
@@ -353,7 +353,7 @@ public class AutoclickTypePanelTest {
        assertThat(params.gravity).isEqualTo(Gravity.START | Gravity.TOP);
        assertThat(params.x).isEqualTo(15);
        assertThat(params.y).isEqualTo(30);
        assertThat(mAutoclickTypePanel.getCurrentCornerIndexForTesting()).isEqualTo(
        assertThat(mAutoclickTypePanel.getCurrentCornerForTesting()).isEqualTo(
                CORNER_TOP_LEFT);
    }

@@ -392,7 +392,7 @@ public class AutoclickTypePanelTest {
        assertThat(params.gravity).isEqualTo(Gravity.START | Gravity.TOP);
        assertThat(params.x).isEqualTo(15); // PANEL_EDGE_MARGIN
        assertThat(params.y).isEqualTo(panelLocation[1] + 10);
        assertThat(mAutoclickTypePanel.getCurrentCornerIndexForTesting()).isEqualTo(
        assertThat(mAutoclickTypePanel.getCurrentCornerForTesting()).isEqualTo(
                CORNER_BOTTOM_LEFT);
    }

@@ -453,7 +453,7 @@ public class AutoclickTypePanelTest {

    private void verifyPanelPosition(int[] expectedPosition) {
        WindowManager.LayoutParams params = mAutoclickTypePanel.getLayoutParamsForTesting();
        assertThat(mAutoclickTypePanel.getCurrentCornerIndexForTesting()).isEqualTo(
        assertThat(mAutoclickTypePanel.getCurrentCornerForTesting()).isEqualTo(
                expectedPosition[0]);
        assertThat(params.gravity).isEqualTo(expectedPosition[1]);
        assertThat(params.x).isEqualTo(expectedPosition[2]);