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

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

Merge "Autoclick: Reduce panel size on small screens" into main

parents 1ccb65c2 643c7f72
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -157,6 +157,10 @@ public class AutoclickTypePanel {

    private int mStatusBarHeight = 0;

    // True when the fully expanded panel is wider than the screen display so certain buttons need
    // to be hidden.
    private boolean mIsExpandedPanelWiderThanScreen = false;

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

@@ -354,6 +358,14 @@ public class AutoclickTypePanel {
        updatePauseButtonAppearance();
        mContentView.post(() -> {
            updatePositionButtonIcon(getVisualCorner());

            // If the expanded panel is too wide for the display, hide the rightmost buttons.
            if (mContentView.getWidth()
                    >= mContext.getResources().getDisplayMetrics().widthPixels) {
                mIsExpandedPanelWiderThanScreen = true;
                mPauseButton.setVisibility(View.GONE);
                mPositionButton.setVisibility(View.GONE);
            }
        });
    }

@@ -474,6 +486,12 @@ public class AutoclickTypePanel {
    /** Toggles the panel expanded or collapsed state. */
    private void togglePanelExpansion(@AutoclickType int clickType) {
        if (mExpanded) {
            // When collapsing the panel show these buttons again.
            if (mIsExpandedPanelWiderThanScreen) {
                mPauseButton.setVisibility(View.VISIBLE);
                mPositionButton.setVisibility(View.VISIBLE);
            }

            // If the panel is already in expanded state, we should collapse it by hiding all
            // buttons except the one user selected.
            collapsePanelWithClickType(clickType);
@@ -484,6 +502,12 @@ public class AutoclickTypePanel {
            // Add spacing when panel is expanded.
            adjustPanelSpacing(/* isExpanded= */ true);

            // If the expanded panel is too wide for the display, hide the rightmost buttons.
            if (mIsExpandedPanelWiderThanScreen) {
                mPauseButton.setVisibility(View.GONE);
                mPositionButton.setVisibility(View.GONE);
            }

            // Toggle the state.
            mExpanded = true;
        }
@@ -970,6 +994,11 @@ public class AutoclickTypePanel {
        return mCurrentCursor;
    }

    @VisibleForTesting
    void setIsExpandedPanelWiderThanScreenForTesting(boolean isExpandedPanelWiderThanScreen) {
        mIsExpandedPanelWiderThanScreen = isExpandedPanelWiderThanScreen;
    }

    /**
     * Retrieves the layout params for AutoclickIndicatorView, used when it's added to the Window
     * Manager.
+26 −0
Original line number Diff line number Diff line
@@ -206,6 +206,32 @@ public class AutoclickTypePanelTest {
        assertThat(mActiveClickType).isEqualTo(AUTOCLICK_TYPE_SCROLL);
    }

    @Test
    public void togglePanelExpansion_largeScreen_AllButtonsShowing() {
        mAutoclickTypePanel.setIsExpandedPanelWiderThanScreenForTesting(false);

        // Close and re-expand the panel.
        mLeftClickButton.callOnClick();
        mLeftClickButton.callOnClick();

        // Expect the buttons to be shown because the screen can fit the whole panel.
        assertThat(mPauseButton.getVisibility()).isEqualTo(View.VISIBLE);
        assertThat(mPositionButton.getVisibility()).isEqualTo(View.VISIBLE);
    }

    @Test
    public void togglePanelExpansion_smallScreen_HideButtons() {
        mAutoclickTypePanel.setIsExpandedPanelWiderThanScreenForTesting(true);

        // Close and re-expand the panel.
        mLeftClickButton.callOnClick();
        mLeftClickButton.callOnClick();

        // Expect the buttons to be hidden because the screen is too small.
        assertThat(mPauseButton.getVisibility()).isEqualTo(View.GONE);
        assertThat(mPositionButton.getVisibility()).isEqualTo(View.GONE);
    }

    @Test
    public void clickLeftClickButton_resumeAutoClick() {
        // Pause autoclick.