a11y: Initialize slider position with cursor area size setting
When the preference loads, initialize the slider position using the cursor area size value from settings. In addition, match slider seekbar range and the cursor area size range. Change-Id: Ib6a8ca8463358a3e2de5ae6be8afd5113a5826be Bug: b/383901288 Test: ToggleAutoclickCursorAreaSizeControllerTest Flag: com.android.server.accessibility.enable_autoclick_indicator
This commit is contained in:
@@ -80,7 +80,6 @@
|
|||||||
android:key="accessibility_control_autoclick_cursor_area_size"
|
android:key="accessibility_control_autoclick_cursor_area_size"
|
||||||
android:title="@string/autoclick_cursor_area_size_title"
|
android:title="@string/autoclick_cursor_area_size_title"
|
||||||
android:summary="@string/autoclick_cursor_area_size_summary"
|
android:summary="@string/autoclick_cursor_area_size_summary"
|
||||||
settings:seekBarIncrement="20"
|
|
||||||
android:selectable="false"
|
android:selectable="false"
|
||||||
settings:searchable="false"
|
settings:searchable="false"
|
||||||
settings:controller="com.android.settings.accessibility.ToggleAutoclickCursorAreaSizeController"/>
|
settings:controller="com.android.settings.accessibility.ToggleAutoclickCursorAreaSizeController"/>
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
package com.android.settings.accessibility;
|
package com.android.settings.accessibility;
|
||||||
|
|
||||||
import static android.content.Context.MODE_PRIVATE;
|
import static android.content.Context.MODE_PRIVATE;
|
||||||
|
import static android.view.accessibility.AccessibilityManager.AUTOCLICK_CURSOR_AREA_INCREMENT_SIZE;
|
||||||
import static android.view.accessibility.AccessibilityManager.AUTOCLICK_CURSOR_AREA_SIZE_MAX;
|
import static android.view.accessibility.AccessibilityManager.AUTOCLICK_CURSOR_AREA_SIZE_MAX;
|
||||||
import static android.view.accessibility.AccessibilityManager.AUTOCLICK_CURSOR_AREA_SIZE_MIN;
|
import static android.view.accessibility.AccessibilityManager.AUTOCLICK_CURSOR_AREA_SIZE_MIN;
|
||||||
|
|
||||||
@@ -35,6 +36,7 @@ import androidx.preference.PreferenceScreen;
|
|||||||
|
|
||||||
import com.android.server.accessibility.Flags;
|
import com.android.server.accessibility.Flags;
|
||||||
import com.android.settings.core.SliderPreferenceController;
|
import com.android.settings.core.SliderPreferenceController;
|
||||||
|
import com.android.settingslib.widget.SliderPreference;
|
||||||
|
|
||||||
/** Controller class that controls accessibility autoclick cursor area size settings. */
|
/** Controller class that controls accessibility autoclick cursor area size settings. */
|
||||||
public class ToggleAutoclickCursorAreaSizeController extends SliderPreferenceController
|
public class ToggleAutoclickCursorAreaSizeController extends SliderPreferenceController
|
||||||
@@ -44,6 +46,7 @@ public class ToggleAutoclickCursorAreaSizeController extends SliderPreferenceCon
|
|||||||
|
|
||||||
private final ContentResolver mContentResolver;
|
private final ContentResolver mContentResolver;
|
||||||
private final SharedPreferences mSharedPreferences;
|
private final SharedPreferences mSharedPreferences;
|
||||||
|
private SliderPreference mPreference;
|
||||||
|
|
||||||
public ToggleAutoclickCursorAreaSizeController(@NonNull Context context,
|
public ToggleAutoclickCursorAreaSizeController(@NonNull Context context,
|
||||||
@NonNull String preferenceKey) {
|
@NonNull String preferenceKey) {
|
||||||
@@ -70,6 +73,13 @@ public class ToggleAutoclickCursorAreaSizeController extends SliderPreferenceCon
|
|||||||
@Override
|
@Override
|
||||||
public void displayPreference(@NonNull PreferenceScreen screen) {
|
public void displayPreference(@NonNull PreferenceScreen screen) {
|
||||||
super.displayPreference(screen);
|
super.displayPreference(screen);
|
||||||
|
mPreference = screen.findPreference(getPreferenceKey());
|
||||||
|
if (mPreference != null) {
|
||||||
|
mPreference.setMin(getMin());
|
||||||
|
mPreference.setMax(getMax());
|
||||||
|
mPreference.setSliderIncrement(AUTOCLICK_CURSOR_AREA_INCREMENT_SIZE);
|
||||||
|
mPreference.setValue(getSliderPosition());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -85,8 +95,9 @@ public class ToggleAutoclickCursorAreaSizeController extends SliderPreferenceCon
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setSliderPosition(int position) {
|
public boolean setSliderPosition(int position) {
|
||||||
Settings.Secure.putInt(mContentResolver,
|
int size = validateSize(position);
|
||||||
Settings.Secure.ACCESSIBILITY_AUTOCLICK_CURSOR_AREA_SIZE, position);
|
Settings.Secure.putInt(
|
||||||
|
mContentResolver, Settings.Secure.ACCESSIBILITY_AUTOCLICK_CURSOR_AREA_SIZE, size);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,10 +106,7 @@ public class ToggleAutoclickCursorAreaSizeController extends SliderPreferenceCon
|
|||||||
int size = Settings.Secure.getInt(mContentResolver,
|
int size = Settings.Secure.getInt(mContentResolver,
|
||||||
Settings.Secure.ACCESSIBILITY_AUTOCLICK_CURSOR_AREA_SIZE,
|
Settings.Secure.ACCESSIBILITY_AUTOCLICK_CURSOR_AREA_SIZE,
|
||||||
AccessibilityManager.AUTOCLICK_CURSOR_AREA_SIZE_DEFAULT);
|
AccessibilityManager.AUTOCLICK_CURSOR_AREA_SIZE_DEFAULT);
|
||||||
// Make sure the size is between min and max allowed value.
|
return validateSize(size);
|
||||||
size = Math.min(size, AUTOCLICK_CURSOR_AREA_SIZE_MAX);
|
|
||||||
size = Math.max(size, AUTOCLICK_CURSOR_AREA_SIZE_MIN);
|
|
||||||
return size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -110,4 +118,10 @@ public class ToggleAutoclickCursorAreaSizeController extends SliderPreferenceCon
|
|||||||
public int getMin() {
|
public int getMin() {
|
||||||
return AUTOCLICK_CURSOR_AREA_SIZE_MIN;
|
return AUTOCLICK_CURSOR_AREA_SIZE_MIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int validateSize(int size) {
|
||||||
|
size = Math.min(size, AUTOCLICK_CURSOR_AREA_SIZE_MAX);
|
||||||
|
size = Math.max(size, AUTOCLICK_CURSOR_AREA_SIZE_MIN);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
package com.android.settings.accessibility;
|
package com.android.settings.accessibility;
|
||||||
|
|
||||||
|
import static android.view.accessibility.AccessibilityManager.AUTOCLICK_CURSOR_AREA_SIZE_MAX;
|
||||||
|
import static android.view.accessibility.AccessibilityManager.AUTOCLICK_CURSOR_AREA_SIZE_MIN;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
@@ -32,9 +35,11 @@ import android.platform.test.flag.junit.SetFlagsRule;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.view.accessibility.AccessibilityManager;
|
import android.view.accessibility.AccessibilityManager;
|
||||||
|
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settingslib.widget.SliderPreference;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
@@ -106,21 +111,74 @@ public class ToggleAutoclickCursorAreaSizeControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getProgress_matchesSetting() {
|
public void getProgress_matchesSetting_inRangeValue() {
|
||||||
assertThat(mController.getSliderPosition()).isEqualTo(readSetting());
|
// TODO(388844952): Use parameter testing.
|
||||||
|
for (int size : ImmutableList.of(20, 40, 60, 80, 100)) {
|
||||||
|
updateSetting(size);
|
||||||
|
|
||||||
|
assertThat(mController.getSliderPosition()).isEqualTo(size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setProgress_updatesSetting() {
|
public void getProgress_matchesSetting_aboveMaxValue() {
|
||||||
for (int size : ImmutableList.of(20, 40, 60, 80, 100)) {
|
updateSetting(120);
|
||||||
mController.setSliderPosition(size);
|
|
||||||
assertThat(readSetting()).isEqualTo(size);
|
assertThat(mController.getSliderPosition()).isEqualTo(AUTOCLICK_CURSOR_AREA_SIZE_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getProgress_matchesSetting_belowMinValue() {
|
||||||
|
updateSetting(0);
|
||||||
|
|
||||||
|
assertThat(mController.getSliderPosition()).isEqualTo(AUTOCLICK_CURSOR_AREA_SIZE_MIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setProgress_updatesSetting_inRangeValue() {
|
||||||
|
// TODO(388844952): Use parameter testing.
|
||||||
|
for (int position : ImmutableList.of(20, 40, 60, 80, 100)) {
|
||||||
|
mController.setSliderPosition(position);
|
||||||
|
|
||||||
|
assertThat(readSetting()).isEqualTo(position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setProgress_updatesSetting_aboveMaxValue() {
|
||||||
|
mController.setSliderPosition(120);
|
||||||
|
|
||||||
|
assertThat(readSetting()).isEqualTo(AUTOCLICK_CURSOR_AREA_SIZE_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setProgress_updatesSetting_belowMinValue() {
|
||||||
|
mController.setSliderPosition(0);
|
||||||
|
|
||||||
|
assertThat(readSetting()).isEqualTo(AUTOCLICK_CURSOR_AREA_SIZE_MIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void sliderPreference_setCorrectInitialValue() {
|
||||||
|
SliderPreference preference = mock(SliderPreference.class);
|
||||||
|
PreferenceScreen screen = mock(PreferenceScreen.class);
|
||||||
|
doReturn(preference).when(screen).findPreference(anyString());
|
||||||
|
|
||||||
|
mController.displayPreference(screen);
|
||||||
|
|
||||||
|
verify(preference).setValue(mController.getSliderPosition());
|
||||||
|
}
|
||||||
|
|
||||||
private int readSetting() {
|
private int readSetting() {
|
||||||
return Settings.Secure.getInt(mContext.getContentResolver(),
|
return Settings.Secure.getInt(mContext.getContentResolver(),
|
||||||
Settings.Secure.ACCESSIBILITY_AUTOCLICK_CURSOR_AREA_SIZE,
|
Settings.Secure.ACCESSIBILITY_AUTOCLICK_CURSOR_AREA_SIZE,
|
||||||
AccessibilityManager.AUTOCLICK_CURSOR_AREA_SIZE_DEFAULT);
|
AccessibilityManager.AUTOCLICK_CURSOR_AREA_SIZE_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateSetting(int value) {
|
||||||
|
Settings.Secure.putInt(
|
||||||
|
mContext.getContentResolver(),
|
||||||
|
Settings.Secure.ACCESSIBILITY_AUTOCLICK_CURSOR_AREA_SIZE,
|
||||||
|
value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user