Loading res/values/strings.xml +6 −0 Original line number Original line Diff line number Diff line Loading @@ -5562,6 +5562,12 @@ <string name="accessibility_autoclick_longer_desc">Longer</string> <string name="accessibility_autoclick_longer_desc">Longer</string> <!-- Description for the seekbar that adjust auto click time. [CHAR_LIMIT=NONE] --> <!-- Description for the seekbar that adjust auto click time. [CHAR_LIMIT=NONE] --> <string name="accessibility_autoclick_seekbar_desc">Auto click time</string> <string name="accessibility_autoclick_seekbar_desc">Auto click time</string> <!-- Title for the seekbar that adjust auto click cursor area size. [CHAR_LIMIT=NONE] --> <!-- TODO(b/383901288): Update string to translatable once approved by UXW. --> <string name="autoclick_cursor_area_size_title" translatable="false">Cursor area size</string> <!-- Summary for the seekbar that adjust auto click cursor area size. [CHAR_LIMIT=NONE] --> <!-- TODO(b/383901288): Update string to translatable once approved by UXW. --> <string name="autoclick_cursor_area_size_summary" translatable="false">Adjust the autoclick ring indicator area size</string> <!-- Title for preference screen for configuring vibrations. [CHAR LIMIT=NONE] --> <!-- Title for preference screen for configuring vibrations. [CHAR LIMIT=NONE] --> <string name="accessibility_vibration_settings_title">Vibration & haptics</string> <string name="accessibility_vibration_settings_title">Vibration & haptics</string> <!-- Summary for preference screen for configuring vibrations. [CHAR LIMIT=NONE] --> <!-- Summary for preference screen for configuring vibrations. [CHAR LIMIT=NONE] --> res/xml/accessibility_autoclick_settings.xml +9 −0 Original line number Original line Diff line number Diff line Loading @@ -76,6 +76,15 @@ settings:searchable="false" settings:searchable="false" settings:controller="com.android.settings.accessibility.ToggleAutoclickCustomSeekbarController"/> settings:controller="com.android.settings.accessibility.ToggleAutoclickCustomSeekbarController"/> <com.android.settingslib.widget.SliderPreference android:key="accessibility_control_autoclick_cursor_area_size" android:title="@string/autoclick_cursor_area_size_title" android:summary="@string/autoclick_cursor_area_size_summary" settings:seekBarIncrement="20" android:selectable="false" settings:searchable="false" settings:controller="com.android.settings.accessibility.ToggleAutoclickCursorAreaSizeController"/> <com.android.settings.accessibility.AccessibilityFooterPreference <com.android.settings.accessibility.AccessibilityFooterPreference android:key="accessibility_autoclick_footer" android:key="accessibility_autoclick_footer" android:title="@string/accessibility_autoclick_description" android:title="@string/accessibility_autoclick_description" Loading src/com/android/settings/accessibility/ToggleAutoclickCursorAreaSizeController.java 0 → 100644 +101 −0 Original line number Original line Diff line number Diff line /* * 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.settings.accessibility; import static android.content.Context.MODE_PRIVATE; import android.content.Context; import android.content.SharedPreferences; import androidx.annotation.Nullable; import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.OnLifecycleEvent; import androidx.preference.PreferenceScreen; import com.android.server.accessibility.Flags; import com.android.settings.core.SliderPreferenceController; /** Controller class that controls accessibility autoclick cursor area size settings. */ public class ToggleAutoclickCursorAreaSizeController extends SliderPreferenceController implements LifecycleObserver, SharedPreferences.OnSharedPreferenceChangeListener { public static final String TAG = ToggleAutoclickCursorAreaSizeController.class.getSimpleName(); private static final int MIN_SIZE = 20; private static final int MAX_SIZE = 100; private static final int DEFAULT_SIZE = 60; private final SharedPreferences mSharedPreferences; public ToggleAutoclickCursorAreaSizeController(Context context, String preferenceKey) { super(context, preferenceKey); mSharedPreferences = context.getSharedPreferences(context.getPackageName(), MODE_PRIVATE); } @OnLifecycleEvent(Lifecycle.Event.ON_START) public void onStart() { if (mSharedPreferences != null) { mSharedPreferences.registerOnSharedPreferenceChangeListener(this); } } @OnLifecycleEvent(Lifecycle.Event.ON_STOP) public void onStop() { if (mSharedPreferences != null) { mSharedPreferences.unregisterOnSharedPreferenceChangeListener(this); } } @Override public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); } @Override public int getAvailabilityStatus() { return Flags.enableAutoclickIndicator() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE; } @Override public void onSharedPreferenceChanged( SharedPreferences sharedPreferences, @Nullable String key) { // TODO(b/383901288): Update slider. } @Override public boolean setSliderPosition(int position) { // TODO(b/383901288): Update settings. return true; } @Override public int getSliderPosition() { // TODO(b/383901288): retrieve from settings and fallback to default. return DEFAULT_SIZE; } @Override public int getMax() { return MAX_SIZE; } @Override public int getMin() { return MIN_SIZE; } } tests/robotests/src/com/android/settings/accessibility/ToggleAutoclickCursorAreaSizeControllerTest.java 0 → 100644 +103 −0 Original line number Original line Diff line number Diff line /* * 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.settings.accessibility; import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.kotlin.VerificationKt.verify; import android.content.Context; import android.content.SharedPreferences; import android.platform.test.annotations.DisableFlags; import android.platform.test.annotations.EnableFlags; import android.platform.test.flag.junit.SetFlagsRule; import androidx.test.core.app.ApplicationProvider; import com.android.settings.core.BasePreferenceController; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import org.robolectric.RobolectricTestRunner; /** Tests for {@link ToggleAutoclickCursorAreaSizeController}. */ @RunWith(RobolectricTestRunner.class) public class ToggleAutoclickCursorAreaSizeControllerTest { private static final String PREFERENCE_KEY = "accessibility_control_autoclick_cursor_area_size"; private static final String PACKAGE = "package"; @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); @Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule(); private final Context mContext = ApplicationProvider.getApplicationContext(); private ToggleAutoclickCursorAreaSizeController mController; @Before public void setUp() { mController = new ToggleAutoclickCursorAreaSizeController(mContext, PREFERENCE_KEY); } @Test @EnableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_AUTOCLICK_INDICATOR) public void getAvailabilityStatus_availableWhenFlagOn() { assertThat(mController.getAvailabilityStatus()) .isEqualTo(BasePreferenceController.AVAILABLE); } @Test @DisableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_AUTOCLICK_INDICATOR) public void getAvailabilityStatus_conditionallyUnavailableWhenFlagOn() { assertThat(mController.getAvailabilityStatus()) .isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE); } @Test public void onStart_registerOnSharedPreferenceChangeListener() { final SharedPreferences prefs = mock(SharedPreferences.class); final Context context = mock(Context.class); doReturn(PACKAGE).when(context).getPackageName(); doReturn(prefs).when(context).getSharedPreferences(anyString(), anyInt()); final ToggleAutoclickCursorAreaSizeController controller = new ToggleAutoclickCursorAreaSizeController(context, PREFERENCE_KEY); controller.onStart(); verify(prefs).registerOnSharedPreferenceChangeListener(controller); } @Test public void onStop_unregisterOnSharedPreferenceChangeListener() { final SharedPreferences prefs = mock(SharedPreferences.class); final Context context = mock(Context.class); doReturn(PACKAGE).when(context).getPackageName(); doReturn(prefs).when(context).getSharedPreferences(anyString(), anyInt()); final ToggleAutoclickCursorAreaSizeController controller = new ToggleAutoclickCursorAreaSizeController(context, PREFERENCE_KEY); controller.onStop(); verify(prefs).unregisterOnSharedPreferenceChangeListener(controller); } } Loading
res/values/strings.xml +6 −0 Original line number Original line Diff line number Diff line Loading @@ -5562,6 +5562,12 @@ <string name="accessibility_autoclick_longer_desc">Longer</string> <string name="accessibility_autoclick_longer_desc">Longer</string> <!-- Description for the seekbar that adjust auto click time. [CHAR_LIMIT=NONE] --> <!-- Description for the seekbar that adjust auto click time. [CHAR_LIMIT=NONE] --> <string name="accessibility_autoclick_seekbar_desc">Auto click time</string> <string name="accessibility_autoclick_seekbar_desc">Auto click time</string> <!-- Title for the seekbar that adjust auto click cursor area size. [CHAR_LIMIT=NONE] --> <!-- TODO(b/383901288): Update string to translatable once approved by UXW. --> <string name="autoclick_cursor_area_size_title" translatable="false">Cursor area size</string> <!-- Summary for the seekbar that adjust auto click cursor area size. [CHAR_LIMIT=NONE] --> <!-- TODO(b/383901288): Update string to translatable once approved by UXW. --> <string name="autoclick_cursor_area_size_summary" translatable="false">Adjust the autoclick ring indicator area size</string> <!-- Title for preference screen for configuring vibrations. [CHAR LIMIT=NONE] --> <!-- Title for preference screen for configuring vibrations. [CHAR LIMIT=NONE] --> <string name="accessibility_vibration_settings_title">Vibration & haptics</string> <string name="accessibility_vibration_settings_title">Vibration & haptics</string> <!-- Summary for preference screen for configuring vibrations. [CHAR LIMIT=NONE] --> <!-- Summary for preference screen for configuring vibrations. [CHAR LIMIT=NONE] -->
res/xml/accessibility_autoclick_settings.xml +9 −0 Original line number Original line Diff line number Diff line Loading @@ -76,6 +76,15 @@ settings:searchable="false" settings:searchable="false" settings:controller="com.android.settings.accessibility.ToggleAutoclickCustomSeekbarController"/> settings:controller="com.android.settings.accessibility.ToggleAutoclickCustomSeekbarController"/> <com.android.settingslib.widget.SliderPreference android:key="accessibility_control_autoclick_cursor_area_size" android:title="@string/autoclick_cursor_area_size_title" android:summary="@string/autoclick_cursor_area_size_summary" settings:seekBarIncrement="20" android:selectable="false" settings:searchable="false" settings:controller="com.android.settings.accessibility.ToggleAutoclickCursorAreaSizeController"/> <com.android.settings.accessibility.AccessibilityFooterPreference <com.android.settings.accessibility.AccessibilityFooterPreference android:key="accessibility_autoclick_footer" android:key="accessibility_autoclick_footer" android:title="@string/accessibility_autoclick_description" android:title="@string/accessibility_autoclick_description" Loading
src/com/android/settings/accessibility/ToggleAutoclickCursorAreaSizeController.java 0 → 100644 +101 −0 Original line number Original line Diff line number Diff line /* * 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.settings.accessibility; import static android.content.Context.MODE_PRIVATE; import android.content.Context; import android.content.SharedPreferences; import androidx.annotation.Nullable; import androidx.lifecycle.Lifecycle; import androidx.lifecycle.LifecycleObserver; import androidx.lifecycle.OnLifecycleEvent; import androidx.preference.PreferenceScreen; import com.android.server.accessibility.Flags; import com.android.settings.core.SliderPreferenceController; /** Controller class that controls accessibility autoclick cursor area size settings. */ public class ToggleAutoclickCursorAreaSizeController extends SliderPreferenceController implements LifecycleObserver, SharedPreferences.OnSharedPreferenceChangeListener { public static final String TAG = ToggleAutoclickCursorAreaSizeController.class.getSimpleName(); private static final int MIN_SIZE = 20; private static final int MAX_SIZE = 100; private static final int DEFAULT_SIZE = 60; private final SharedPreferences mSharedPreferences; public ToggleAutoclickCursorAreaSizeController(Context context, String preferenceKey) { super(context, preferenceKey); mSharedPreferences = context.getSharedPreferences(context.getPackageName(), MODE_PRIVATE); } @OnLifecycleEvent(Lifecycle.Event.ON_START) public void onStart() { if (mSharedPreferences != null) { mSharedPreferences.registerOnSharedPreferenceChangeListener(this); } } @OnLifecycleEvent(Lifecycle.Event.ON_STOP) public void onStop() { if (mSharedPreferences != null) { mSharedPreferences.unregisterOnSharedPreferenceChangeListener(this); } } @Override public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); } @Override public int getAvailabilityStatus() { return Flags.enableAutoclickIndicator() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE; } @Override public void onSharedPreferenceChanged( SharedPreferences sharedPreferences, @Nullable String key) { // TODO(b/383901288): Update slider. } @Override public boolean setSliderPosition(int position) { // TODO(b/383901288): Update settings. return true; } @Override public int getSliderPosition() { // TODO(b/383901288): retrieve from settings and fallback to default. return DEFAULT_SIZE; } @Override public int getMax() { return MAX_SIZE; } @Override public int getMin() { return MIN_SIZE; } }
tests/robotests/src/com/android/settings/accessibility/ToggleAutoclickCursorAreaSizeControllerTest.java 0 → 100644 +103 −0 Original line number Original line Diff line number Diff line /* * 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.settings.accessibility; import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.kotlin.VerificationKt.verify; import android.content.Context; import android.content.SharedPreferences; import android.platform.test.annotations.DisableFlags; import android.platform.test.annotations.EnableFlags; import android.platform.test.flag.junit.SetFlagsRule; import androidx.test.core.app.ApplicationProvider; import com.android.settings.core.BasePreferenceController; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; import org.robolectric.RobolectricTestRunner; /** Tests for {@link ToggleAutoclickCursorAreaSizeController}. */ @RunWith(RobolectricTestRunner.class) public class ToggleAutoclickCursorAreaSizeControllerTest { private static final String PREFERENCE_KEY = "accessibility_control_autoclick_cursor_area_size"; private static final String PACKAGE = "package"; @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); @Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule(); private final Context mContext = ApplicationProvider.getApplicationContext(); private ToggleAutoclickCursorAreaSizeController mController; @Before public void setUp() { mController = new ToggleAutoclickCursorAreaSizeController(mContext, PREFERENCE_KEY); } @Test @EnableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_AUTOCLICK_INDICATOR) public void getAvailabilityStatus_availableWhenFlagOn() { assertThat(mController.getAvailabilityStatus()) .isEqualTo(BasePreferenceController.AVAILABLE); } @Test @DisableFlags(com.android.server.accessibility.Flags.FLAG_ENABLE_AUTOCLICK_INDICATOR) public void getAvailabilityStatus_conditionallyUnavailableWhenFlagOn() { assertThat(mController.getAvailabilityStatus()) .isEqualTo(BasePreferenceController.CONDITIONALLY_UNAVAILABLE); } @Test public void onStart_registerOnSharedPreferenceChangeListener() { final SharedPreferences prefs = mock(SharedPreferences.class); final Context context = mock(Context.class); doReturn(PACKAGE).when(context).getPackageName(); doReturn(prefs).when(context).getSharedPreferences(anyString(), anyInt()); final ToggleAutoclickCursorAreaSizeController controller = new ToggleAutoclickCursorAreaSizeController(context, PREFERENCE_KEY); controller.onStart(); verify(prefs).registerOnSharedPreferenceChangeListener(controller); } @Test public void onStop_unregisterOnSharedPreferenceChangeListener() { final SharedPreferences prefs = mock(SharedPreferences.class); final Context context = mock(Context.class); doReturn(PACKAGE).when(context).getPackageName(); doReturn(prefs).when(context).getSharedPreferences(anyString(), anyInt()); final ToggleAutoclickCursorAreaSizeController controller = new ToggleAutoclickCursorAreaSizeController(context, PREFERENCE_KEY); controller.onStop(); verify(prefs).unregisterOnSharedPreferenceChangeListener(controller); } }