diff options
10 files changed, 404 insertions, 10 deletions
diff --git a/core/res/res/drawable/accessibility_autoclick_button_group_rounded_background.xml b/core/res/res/drawable/accessibility_autoclick_button_group_rounded_background.xml new file mode 100644 index 000000000000..87f7cdd61f16 --- /dev/null +++ b/core/res/res/drawable/accessibility_autoclick_button_group_rounded_background.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright 2025 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<shape xmlns:android="http://schemas.android.com/apk/res/android"> + <solid android:color="@color/materialColorSurfaceContainer" /> + <corners android:radius="30dp" /> +</shape> diff --git a/core/res/res/drawable/accessibility_autoclick_double_click.xml b/core/res/res/drawable/accessibility_autoclick_double_click.xml new file mode 100644 index 000000000000..ea28bc28dbe1 --- /dev/null +++ b/core/res/res/drawable/accessibility_autoclick_double_click.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright 2025 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="20dp" + android:height="20dp" + android:viewportWidth="20" + android:viewportHeight="20"> + <path + android:pathData="M9.7 16C8.1 15.9167 6.75 15.3 5.65 14.15C4.55 13 4 11.6167 4 10C4 8.33333 4.58333 6.91667 5.75 5.75C6.91667 4.58333 8.33333 4 10 4C11.6167 4 13 4.55 14.15 5.65C15.3 6.75 15.9167 8.1 16 9.7L13.9 9.075C13.6833 8.175 13.2167 7.44167 12.5 6.875C11.7833 6.29167 10.95 6 10 6C8.9 6 7.95833 6.39167 7.175 7.175C6.39167 7.95833 6 8.9 6 10C6 10.95 6.28333 11.7833 6.85 12.5C7.43333 13.2167 8.175 13.6833 9.075 13.9L9.7 16ZM10.9 19.95C10.75 19.9833 10.6 20 10.45 20C10.3 20 10.15 20 10 20C8.61667 20 7.31667 19.7417 6.1 19.225C4.88333 18.6917 3.825 17.975 2.925 17.075C2.025 16.175 1.30833 15.1167 0.775 13.9C0.258333 12.6833 0.0000000596046 11.3833 0.0000000596046 10C0.0000000596046 8.61667 0.258333 7.31667 0.775 6.1C1.30833 4.88333 2.025 3.825 2.925 2.925C3.825 2.025 4.88333 1.31667 6.1 0.799999C7.31667 0.266666 8.61667 -0.000000476837 10 -0.000000476837C11.3833 -0.000000476837 12.6833 0.266666 13.9 0.799999C15.1167 1.31667 16.175 2.025 17.075 2.925C17.975 3.825 18.6833 4.88333 19.2 6.1C19.7333 7.31667 20 8.61667 20 10C20 10.15 20 10.3 20 10.45C20 10.6 19.9833 10.75 19.95 10.9L18 10.3V10C18 7.76667 17.225 5.875 15.675 4.325C14.125 2.775 12.2333 2 10 2C7.76667 2 5.875 2.775 4.325 4.325C2.775 5.875 2 7.76667 2 10C2 12.2333 2.775 14.125 4.325 15.675C5.875 17.225 7.76667 18 10 18C10.05 18 10.1 18 10.15 18C10.2 18 10.25 18 10.3 18L10.9 19.95ZM18.525 20.5L14.25 16.225L13 20L10 10L20 13L16.225 14.25L20.5 18.525L18.525 20.5Z" + android:fillColor="@color/materialColorPrimary" /> +</vector> diff --git a/core/res/res/drawable/accessibility_autoclick_drag.xml b/core/res/res/drawable/accessibility_autoclick_drag.xml new file mode 100644 index 000000000000..02d90bc83b5f --- /dev/null +++ b/core/res/res/drawable/accessibility_autoclick_drag.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright 2025 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="20dp" + android:height="20dp" + android:viewportWidth="20" + android:viewportHeight="20"> + <path + android:pathData="M10 20L5.75 15.75L7.175 14.325L9 16.15V11H3.875L5.7 12.8L4.25 14.25L0.0000000596046 10L4.225 5.775L5.65 7.2L3.85 9H9V3.85L7.175 5.675L5.75 4.25L10 -0.000000476837L14.25 4.25L12.825 5.675L11 3.85V9H16.125L14.3 7.2L15.75 5.75L20 10L15.75 14.25L14.325 12.825L16.15 11H11V16.125L12.8 14.3L14.25 15.75L10 20Z" + android:fillColor="@color/materialColorPrimary" /> +</vector> diff --git a/core/res/res/drawable/accessibility_autoclick_right_click.xml b/core/res/res/drawable/accessibility_autoclick_right_click.xml new file mode 100644 index 000000000000..a5e296614501 --- /dev/null +++ b/core/res/res/drawable/accessibility_autoclick_right_click.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright 2025 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="18dp" + android:height="18dp" + android:viewportWidth="18" + android:viewportHeight="18"> + <path + android:pathData="M11.3 12L11.925 9.9C12.825 9.68333 13.5583 9.21667 14.125 8.5C14.7083 7.78333 15 6.95 15 6C15 4.9 14.6083 3.95833 13.825 3.175C13.0417 2.39167 12.1 2 11 2C10.05 2 9.21667 2.29167 8.5 2.875C7.78333 3.44167 7.31667 4.175 7.1 5.075L5 5.7C5.08333 4.1 5.7 2.75 6.85 1.65C8 0.549999 9.38333 -0.00000143051 11 -0.00000143051C12.6667 -0.00000143051 14.0833 0.583332 15.25 1.75C16.4167 2.91667 17 4.33333 17 6C17 7.61667 16.45 9 15.35 10.15C14.25 11.3 12.9 11.9167 11.3 12ZM2.475 16.5L0.5 14.525L4.775 10.25L1 9L11 6L8 16L6.75 12.225L2.475 16.5Z" + android:fillColor="@color/materialColorPrimary" /> +</vector> diff --git a/core/res/res/drawable/accessibility_autoclick_scroll.xml b/core/res/res/drawable/accessibility_autoclick_scroll.xml new file mode 100644 index 000000000000..8b6da25be2ff --- /dev/null +++ b/core/res/res/drawable/accessibility_autoclick_scroll.xml @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright 2025 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="12dp" + android:height="20dp" + android:viewportWidth="12" + android:viewportHeight="20"> + <path + android:pathData="M10 15L5 20L-0.000000953674 15L1.4 13.6L4 16.175L4 3.825L1.4 6.4L-0.000000953674 5L5 -0.000000476837L10 5L8.6 6.4L6 3.825L6 16.175L8.6 13.6L10 15Z" + android:fillColor="@color/materialColorPrimary" /> +</vector> diff --git a/core/res/res/layout/accessibility_autoclick_type_panel.xml b/core/res/res/layout/accessibility_autoclick_type_panel.xml index 9aa47cc8d68b..cedbdc175488 100644 --- a/core/res/res/layout/accessibility_autoclick_type_panel.xml +++ b/core/res/res/layout/accessibility_autoclick_type_panel.xml @@ -27,26 +27,81 @@ android:padding="16dp"> <LinearLayout + android:id="@+id/accessibility_autoclick_button_group_container" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:orientation="horizontal"> <LinearLayout - android:id="@+id/accessibility_autoclick_left_click_layout" - style="@style/AccessibilityAutoclickPanelButtonLayoutStyle" - android:layout_marginEnd="@dimen/accessibility_autoclick_type_panel_button_spacing"> + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_horizontal" + android:background="@drawable/accessibility_autoclick_button_group_rounded_background" + android:orientation="horizontal" + android:padding="3dp"> + + <LinearLayout + android:id="@+id/accessibility_autoclick_drag_layout" + style="@style/AccessibilityAutoclickPanelButtonLayoutStyle"> + + <ImageButton + android:id="@+id/accessibility_autoclick_drag_button" + style="@style/AccessibilityAutoclickPanelImageButtonStyle" + android:contentDescription="@string/accessibility_autoclick_drag" + android:src="@drawable/accessibility_autoclick_drag" /> + </LinearLayout> + + <LinearLayout + android:id="@+id/accessibility_autoclick_double_click_layout" + style="@style/AccessibilityAutoclickPanelButtonLayoutStyle"> + + <ImageButton + android:id="@+id/accessibility_autoclick_double_click_button" + style="@style/AccessibilityAutoclickPanelImageButtonStyle" + android:contentDescription="@string/accessibility_autoclick_double_click" + android:src="@drawable/accessibility_autoclick_double_click" /> + </LinearLayout> + + <LinearLayout + android:id="@+id/accessibility_autoclick_right_click_layout" + style="@style/AccessibilityAutoclickPanelButtonLayoutStyle"> + + <ImageButton + android:id="@+id/accessibility_autoclick_right_click_button" + style="@style/AccessibilityAutoclickPanelImageButtonStyle" + android:contentDescription="@string/accessibility_autoclick_right_click" + android:src="@drawable/accessibility_autoclick_right_click" /> + </LinearLayout> + + <LinearLayout + android:id="@+id/accessibility_autoclick_scroll_layout" + style="@style/AccessibilityAutoclickPanelButtonLayoutStyle"> + + <ImageButton + android:id="@+id/accessibility_autoclick_scroll_button" + style="@style/AccessibilityAutoclickPanelImageButtonStyle" + android:contentDescription="@string/accessibility_autoclick_scroll" + android:src="@drawable/accessibility_autoclick_scroll" /> + </LinearLayout> + + <LinearLayout + android:id="@+id/accessibility_autoclick_left_click_layout" + style="@style/AccessibilityAutoclickPanelButtonLayoutStyle"> + + <ImageButton + android:id="@+id/accessibility_autoclick_left_click_button" + style="@style/AccessibilityAutoclickPanelImageButtonStyle" + android:contentDescription="@string/accessibility_autoclick_left_click" + android:src="@drawable/accessibility_autoclick_left_click" /> + </LinearLayout> - <ImageButton - android:id="@+id/accessibility_autoclick_left_click_button" - style="@style/AccessibilityAutoclickPanelImageButtonStyle" - android:contentDescription="@string/accessibility_autoclick_left_click" - android:src="@drawable/accessibility_autoclick_left_click" /> </LinearLayout> <View android:layout_width="@dimen/accessibility_autoclick_type_panel_divider_width" android:layout_height="@dimen/accessibility_autoclick_type_panel_divider_height" + android:layout_marginStart="@dimen/accessibility_autoclick_type_panel_button_spacing" android:layout_marginEnd="@dimen/accessibility_autoclick_type_panel_button_spacing" android:background="@color/materialColorSurfaceContainer" /> diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index db806a1d79cb..abbba9d1bffa 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -6164,6 +6164,14 @@ <string name="accessibility_autoclick_type_settings_panel_title">Autoclick type settings panel</string> <!-- Label for autoclick left click button [CHAR LIMIT=NONE] --> <string name="accessibility_autoclick_left_click">Left click</string> + <!-- Label for autoclick right click button [CHAR LIMIT=NONE] --> + <string name="accessibility_autoclick_right_click">Right click</string> + <!-- Label for autoclick double click button [CHAR LIMIT=NONE] --> + <string name="accessibility_autoclick_double_click">Double click</string> + <!-- Label for autoclick drag button [CHAR LIMIT=NONE] --> + <string name="accessibility_autoclick_drag">Drag</string> + <!-- Label for autoclick scroll button [CHAR LIMIT=NONE] --> + <string name="accessibility_autoclick_scroll">Scroll</string> <!-- Label for autoclick pause button [CHAR LIMIT=NONE] --> <string name="accessibility_autoclick_pause">Pause</string> <!-- Label for autoclick position button [CHAR LIMIT=NONE] --> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 8dbed4ca380c..800f98d9a234 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -5617,6 +5617,10 @@ <java-symbol type="layout" name="accessibility_autoclick_type_panel" /> <java-symbol type="string" name="accessibility_autoclick_type_settings_panel_title" /> <java-symbol type="string" name="accessibility_autoclick_left_click" /> + <java-symbol type="string" name="accessibility_autoclick_right_click" /> + <java-symbol type="string" name="accessibility_autoclick_double_click" /> + <java-symbol type="string" name="accessibility_autoclick_drag" /> + <java-symbol type="string" name="accessibility_autoclick_scroll" /> <java-symbol type="string" name="accessibility_autoclick_pause" /> <java-symbol type="string" name="accessibility_autoclick_position" /> <java-symbol type="dimen" name="accessibility_autoclick_type_panel_button_spacing" /> @@ -5624,8 +5628,17 @@ <java-symbol type="dimen" name="accessibility_autoclick_type_panel_divider_height" /> <java-symbol type="dimen" name="accessibility_autoclick_type_panel_divider_width" /> <java-symbol type="id" name="accessibility_autoclick_type_panel" /> + <java-symbol type="id" name="accessibility_autoclick_button_group_container" /> <java-symbol type="id" name="accessibility_autoclick_left_click_layout" /> <java-symbol type="id" name="accessibility_autoclick_left_click_button" /> + <java-symbol type="id" name="accessibility_autoclick_right_click_layout" /> + <java-symbol type="id" name="accessibility_autoclick_right_click_button" /> + <java-symbol type="id" name="accessibility_autoclick_double_click_layout" /> + <java-symbol type="id" name="accessibility_autoclick_double_click_button" /> + <java-symbol type="id" name="accessibility_autoclick_drag_layout" /> + <java-symbol type="id" name="accessibility_autoclick_drag_button" /> + <java-symbol type="id" name="accessibility_autoclick_scroll_layout" /> + <java-symbol type="id" name="accessibility_autoclick_scroll_button" /> <java-symbol type="id" name="accessibility_autoclick_pause_layout" /> <java-symbol type="id" name="accessibility_autoclick_pause_button" /> <java-symbol type="id" name="accessibility_autoclick_position_layout" /> diff --git a/services/accessibility/java/com/android/server/accessibility/autoclick/AutoclickTypePanel.java b/services/accessibility/java/com/android/server/accessibility/autoclick/AutoclickTypePanel.java index 1ba574559918..0354d2be60c9 100644 --- a/services/accessibility/java/com/android/server/accessibility/autoclick/AutoclickTypePanel.java +++ b/services/accessibility/java/com/android/server/accessibility/autoclick/AutoclickTypePanel.java @@ -25,8 +25,10 @@ import android.view.LayoutInflater; import android.view.View; import android.view.WindowInsets; import android.view.WindowManager; +import android.widget.LinearLayout; import androidx.annotation.NonNull; +import androidx.annotation.VisibleForTesting; import com.android.internal.R; @@ -40,12 +42,44 @@ public class AutoclickTypePanel { private final WindowManager mWindowManager; + // Whether the panel is expanded or not. + private boolean mExpanded = false; + + private final LinearLayout mLeftClickButton; + private final LinearLayout mRightClickButton; + private final LinearLayout mDoubleClickButton; + private final LinearLayout mDragButton; + private final LinearLayout mScrollButton; + public AutoclickTypePanel(Context context, WindowManager windowManager) { mContext = context; mWindowManager = windowManager; - mContentView = LayoutInflater.from(context).inflate( - R.layout.accessibility_autoclick_type_panel, null); + mContentView = + LayoutInflater.from(context) + .inflate(R.layout.accessibility_autoclick_type_panel, null); + mLeftClickButton = + mContentView.findViewById(R.id.accessibility_autoclick_left_click_layout); + mRightClickButton = + mContentView.findViewById(R.id.accessibility_autoclick_right_click_layout); + mDoubleClickButton = + mContentView.findViewById(R.id.accessibility_autoclick_double_click_layout); + mScrollButton = mContentView.findViewById(R.id.accessibility_autoclick_scroll_layout); + mDragButton = mContentView.findViewById(R.id.accessibility_autoclick_drag_layout); + + initializeButtonState(); + } + + private void initializeButtonState() { + mLeftClickButton.setOnClickListener(v -> togglePanelExpansion(mLeftClickButton)); + mRightClickButton.setOnClickListener(v -> togglePanelExpansion(mRightClickButton)); + mDoubleClickButton.setOnClickListener(v -> togglePanelExpansion(mDoubleClickButton)); + mScrollButton.setOnClickListener(v -> togglePanelExpansion(mScrollButton)); + mDragButton.setOnClickListener(v -> togglePanelExpansion(mDragButton)); + + // Initializes panel as collapsed state and only displays the left click button. + hideAllClickTypeButtons(); + mLeftClickButton.setVisibility(View.VISIBLE); } public void show() { @@ -56,6 +90,51 @@ public class AutoclickTypePanel { mWindowManager.removeView(mContentView); } + /** Toggles the panel expanded or collapsed state. */ + private void togglePanelExpansion(LinearLayout button) { + 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); + } else { + // If the panel is already collapsed, we just need to expand it. + showAllClickTypeButtons(); + } + + // Toggle the state. + mExpanded = !mExpanded; + } + + /** Hide all buttons on the panel except pause and position buttons. */ + private void hideAllClickTypeButtons() { + mLeftClickButton.setVisibility(View.GONE); + mRightClickButton.setVisibility(View.GONE); + mDoubleClickButton.setVisibility(View.GONE); + mDragButton.setVisibility(View.GONE); + mScrollButton.setVisibility(View.GONE); + } + + /** Show all buttons on the panel except pause and position buttons. */ + private void showAllClickTypeButtons() { + mLeftClickButton.setVisibility(View.VISIBLE); + mRightClickButton.setVisibility(View.VISIBLE); + mDoubleClickButton.setVisibility(View.VISIBLE); + mDragButton.setVisibility(View.VISIBLE); + mScrollButton.setVisibility(View.VISIBLE); + } + + @VisibleForTesting + boolean getExpansionStateForTesting() { + return mExpanded; + } + + @VisibleForTesting + @NonNull + View getContentViewForTesting() { + return mContentView; + } + /** * Retrieves the layout params for AutoclickIndicatorView, used when it's added to the Window * Manager. diff --git a/services/tests/servicestests/src/com/android/server/accessibility/autoclick/AutoclickTypePanelTest.java b/services/tests/servicestests/src/com/android/server/accessibility/autoclick/AutoclickTypePanelTest.java new file mode 100644 index 000000000000..f0334598bd30 --- /dev/null +++ b/services/tests/servicestests/src/com/android/server/accessibility/autoclick/AutoclickTypePanelTest.java @@ -0,0 +1,119 @@ +/* + * Copyright 2025 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.server.accessibility.autoclick; + +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; + +import static com.google.common.truth.Truth.assertThat; + +import android.content.Context; +import android.testing.AndroidTestingRunner; +import android.testing.TestableContext; +import android.testing.TestableLooper; +import android.view.View; +import android.view.WindowManager; +import android.widget.LinearLayout; + +import com.android.internal.R; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; + +/** Test cases for {@link AutoclickTypePanel}. */ +@RunWith(AndroidTestingRunner.class) +@TestableLooper.RunWithLooper(setAsMainLooper = true) +public class AutoclickTypePanelTest { + @Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule(); + + @Rule + public TestableContext mTestableContext = + new TestableContext(getInstrumentation().getContext()); + + private AutoclickTypePanel mAutoclickTypePanel; + @Mock private WindowManager mMockWindowManager; + private LinearLayout mLeftClickButton; + private LinearLayout mRightClickButton; + private LinearLayout mDoubleClickButton; + private LinearLayout mDragButton; + private LinearLayout mScrollButton; + + @Before + public void setUp() { + mTestableContext.addMockSystemService(Context.WINDOW_SERVICE, mMockWindowManager); + + mAutoclickTypePanel = new AutoclickTypePanel(mTestableContext, mMockWindowManager); + View contentView = mAutoclickTypePanel.getContentViewForTesting(); + mLeftClickButton = contentView.findViewById(R.id.accessibility_autoclick_left_click_layout); + mRightClickButton = + contentView.findViewById(R.id.accessibility_autoclick_right_click_layout); + mDoubleClickButton = + contentView.findViewById(R.id.accessibility_autoclick_double_click_layout); + mScrollButton = contentView.findViewById(R.id.accessibility_autoclick_scroll_layout); + mDragButton = contentView.findViewById(R.id.accessibility_autoclick_drag_layout); + } + + @Test + public void AutoclickTypePanel_initialState_expandedFalse() { + assertThat(mAutoclickTypePanel.getExpansionStateForTesting()).isFalse(); + } + + @Test + public void AutoclickTypePanel_initialState_correctButtonVisibility() { + // On initialization, only left button is visible. + assertThat(mLeftClickButton.getVisibility()).isEqualTo(View.VISIBLE); + assertThat(mRightClickButton.getVisibility()).isEqualTo(View.GONE); + assertThat(mDoubleClickButton.getVisibility()).isEqualTo(View.GONE); + assertThat(mDragButton.getVisibility()).isEqualTo(View.GONE); + assertThat(mScrollButton.getVisibility()).isEqualTo(View.GONE); + } + + @Test + public void togglePanelExpansion_onClick_expandedTrue() { + // On clicking left click button, the panel is expanded and all buttons are visible. + mLeftClickButton.callOnClick(); + + assertThat(mAutoclickTypePanel.getExpansionStateForTesting()).isTrue(); + assertThat(mLeftClickButton.getVisibility()).isEqualTo(View.VISIBLE); + assertThat(mRightClickButton.getVisibility()).isEqualTo(View.VISIBLE); + assertThat(mDoubleClickButton.getVisibility()).isEqualTo(View.VISIBLE); + assertThat(mDragButton.getVisibility()).isEqualTo(View.VISIBLE); + assertThat(mScrollButton.getVisibility()).isEqualTo(View.VISIBLE); + } + + @Test + public void togglePanelExpansion_onClickAgain_expandedFalse() { + // By first click, the panel is expanded. + mLeftClickButton.callOnClick(); + assertThat(mAutoclickTypePanel.getExpansionStateForTesting()).isTrue(); + + // Clicks any button in the expanded state, the panel is expected to collapse + // with only the clicked button visible. + mScrollButton.callOnClick(); + + assertThat(mAutoclickTypePanel.getExpansionStateForTesting()).isFalse(); + assertThat(mScrollButton.getVisibility()).isEqualTo(View.VISIBLE); + assertThat(mRightClickButton.getVisibility()).isEqualTo(View.GONE); + assertThat(mLeftClickButton.getVisibility()).isEqualTo(View.GONE); + assertThat(mDoubleClickButton.getVisibility()).isEqualTo(View.GONE); + assertThat(mDragButton.getVisibility()).isEqualTo(View.GONE); + } +} |