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

Commit 89b928bd authored by Yuhan Yang's avatar Yuhan Yang
Browse files

Collapse autoclick panel once clicking outside

Screencast:
go/screencast-ndu4otm5ndyynjm0nzawohw5mtawyzezos04oq

Bug: 414442887
Test: atest AutoclickControllerTest and manually verified
Flag: com.android.server.accessibility.enable_autoclick_indicator
Change-Id: Ief2ca696dc85b549d0d8c2ccf18e4752302b8120
parent 2661b0f4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1094,7 +1094,7 @@ public class AutoclickController extends BaseEventStreamTransformation {
        private void resetSelectedClickTypeIfNecessary() {
            if ((mRevertToLeftClick && mActiveClickType != AUTOCLICK_TYPE_LEFT_CLICK)
                    || mActiveClickType == AUTOCLICK_TYPE_LONG_PRESS) {
                mAutoclickTypePanel.resetSelectedClickType();
                mAutoclickTypePanel.collapsePanelWithClickType(AUTOCLICK_TYPE_LEFT_CLICK);
            }
        }

+26 −19
Original line number Diff line number Diff line
@@ -145,6 +145,7 @@ public class AutoclickTypePanel {
    private final LinearLayout mLongPressButton;

    private LinearLayout mSelectedButton;
    private int mSelectedClickType = AUTOCLICK_TYPE_LEFT_CLICK;

    private final Drawable mPauseButtonDrawable;
    private final Drawable mResumeButtonDrawable;
@@ -248,6 +249,11 @@ public class AutoclickTypePanel {
                }
                mIsDragging = false;
                return true;
            case MotionEvent.ACTION_OUTSIDE:
                if (mExpanded) {
                    collapsePanelWithClickType(mSelectedClickType);
                }
                return true;
        }
        return false;
    }
@@ -306,17 +312,25 @@ public class AutoclickTypePanel {
        // The pause button calls `togglePause()` directly so it does not need extra logic.
        mPauseButton.setOnClickListener(v -> togglePause());

        resetSelectedClickType();
        collapsePanelWithClickType(AUTOCLICK_TYPE_LEFT_CLICK);

        // Remove spacing between buttons when initialized.
        adjustPanelSpacing(/* isExpanded= */ false);
    }

    /** Reset panel as collapsed state and only displays the left click button. */
    public void resetSelectedClickType() {
    /** Reset panel as collapsed state and only displays selelcted button. */
    public void collapsePanelWithClickType(@AutoclickType int clickType) {
        hideAllClickTypeButtons();
        mLeftClickButton.setVisibility(View.VISIBLE);
        setSelectedClickType(AUTOCLICK_TYPE_LEFT_CLICK);
        final LinearLayout selectedButton = getButtonFromClickType(clickType);
        selectedButton.setVisibility(View.VISIBLE);

        // Sets the newly selected button.
        setSelectedClickType(clickType);

        // Remove spacing between buttons when collapsed.
        adjustPanelSpacing(/* isExpanded= */ false);

        mExpanded = false;
    }

    /** Sets the selected button and updates the newly and previously selected button styling. */
@@ -329,6 +343,7 @@ public class AutoclickTypePanel {
        }

        mSelectedButton = selectedButton;
        mSelectedClickType = clickType;
        mClickPanelController.handleAutoclickTypeChange(clickType);

        // Updates the newly selected button styling.
@@ -389,29 +404,20 @@ public class AutoclickTypePanel {

    /** Toggles the panel expanded or collapsed state. */
    private void togglePanelExpansion(@AutoclickType int clickType) {
        final LinearLayout button = getButtonFromClickType(clickType);

        if (mExpanded) {
            // If the panel is already in expanded state, we should collapse it by hiding all
            // buttons except the one user selected.
            hideAllClickTypeButtons();
            button.setVisibility(View.VISIBLE);

            // Sets the newly selected button.
            setSelectedClickType(clickType);

            // Remove spacing between buttons when collapsed.
            adjustPanelSpacing(/* isExpanded= */ false);
            collapsePanelWithClickType(clickType);
        } else {
            // If the panel is already collapsed, we just need to expand it.
            showAllClickTypeButtons();

            // Add spacing when panel is expanded.
            adjustPanelSpacing(/* isExpanded= */ true);
        }

            // Toggle the state.
        mExpanded = !mExpanded;
            mExpanded = true;
        }
    }

    private void togglePause() {
@@ -707,7 +713,8 @@ public class AutoclickTypePanel {
    private WindowManager.LayoutParams getDefaultLayoutParams() {
        final WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
        layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
        layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
        layoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
        layoutParams.privateFlags |= WindowManager.LayoutParams.SYSTEM_FLAG_SHOW_FOR_ALL_USERS;
        layoutParams.setFitInsetsTypes(WindowInsets.Type.statusBars());
        layoutParams.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
+8 −3
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static com.android.server.testutils.MockitoUtilsKt.eq;
import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyFloat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
@@ -1209,7 +1210,9 @@ public class AutoclickControllerTest {
        mTestableLooper.processAllMessages();

        // Even after the click, the click type should not be reset.
        verify(mockAutoclickTypePanel, Mockito.never()).resetSelectedClickType();
        assertThat(mController.getActiveClickTypeForTest())
                .isEqualTo(AutoclickTypePanel.AUTOCLICK_TYPE_DRAG);
        verify(mockAutoclickTypePanel, Mockito.never()).collapsePanelWithClickType(anyInt());
    }

    @Test
@@ -1241,7 +1244,8 @@ public class AutoclickControllerTest {
        mController.exitScrollMode();

        // Verify click type is reset when exiting scroll mode.
        verify(mockAutoclickTypePanel).resetSelectedClickType();
        verify(mockAutoclickTypePanel).collapsePanelWithClickType(
                AutoclickTypePanel.AUTOCLICK_TYPE_LEFT_CLICK);
    }

    @Test
@@ -1349,7 +1353,8 @@ public class AutoclickControllerTest {
                MotionEvent.ACTION_DOWN, MotionEvent.ACTION_BUTTON_PRESS,
                MotionEvent.ACTION_BUTTON_RELEASE, MotionEvent.ACTION_UP);

        verify(mockAutoclickTypePanel).resetSelectedClickType();
        verify(mockAutoclickTypePanel).collapsePanelWithClickType(
                AutoclickTypePanel.AUTOCLICK_TYPE_LEFT_CLICK);
    }

    @Test