Merge "a11y: Initialize slider position with cursor area size setting" into main
This commit is contained in:
@@ -80,7 +80,6 @@
|
||||
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"/>
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.accessibility;
|
||||
|
||||
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_MIN;
|
||||
|
||||
@@ -35,6 +36,7 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.server.accessibility.Flags;
|
||||
import com.android.settings.core.SliderPreferenceController;
|
||||
import com.android.settingslib.widget.SliderPreference;
|
||||
|
||||
/** Controller class that controls accessibility autoclick cursor area size settings. */
|
||||
public class ToggleAutoclickCursorAreaSizeController extends SliderPreferenceController
|
||||
@@ -44,6 +46,7 @@ public class ToggleAutoclickCursorAreaSizeController extends SliderPreferenceCon
|
||||
|
||||
private final ContentResolver mContentResolver;
|
||||
private final SharedPreferences mSharedPreferences;
|
||||
private SliderPreference mPreference;
|
||||
|
||||
public ToggleAutoclickCursorAreaSizeController(@NonNull Context context,
|
||||
@NonNull String preferenceKey) {
|
||||
@@ -70,6 +73,13 @@ public class ToggleAutoclickCursorAreaSizeController extends SliderPreferenceCon
|
||||
@Override
|
||||
public void displayPreference(@NonNull PreferenceScreen 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
|
||||
@@ -85,8 +95,9 @@ public class ToggleAutoclickCursorAreaSizeController extends SliderPreferenceCon
|
||||
|
||||
@Override
|
||||
public boolean setSliderPosition(int position) {
|
||||
Settings.Secure.putInt(mContentResolver,
|
||||
Settings.Secure.ACCESSIBILITY_AUTOCLICK_CURSOR_AREA_SIZE, position);
|
||||
int size = validateSize(position);
|
||||
Settings.Secure.putInt(
|
||||
mContentResolver, Settings.Secure.ACCESSIBILITY_AUTOCLICK_CURSOR_AREA_SIZE, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -95,10 +106,7 @@ public class ToggleAutoclickCursorAreaSizeController extends SliderPreferenceCon
|
||||
int size = Settings.Secure.getInt(mContentResolver,
|
||||
Settings.Secure.ACCESSIBILITY_AUTOCLICK_CURSOR_AREA_SIZE,
|
||||
AccessibilityManager.AUTOCLICK_CURSOR_AREA_SIZE_DEFAULT);
|
||||
// Make sure the size is between min and max allowed value.
|
||||
size = Math.min(size, AUTOCLICK_CURSOR_AREA_SIZE_MAX);
|
||||
size = Math.max(size, AUTOCLICK_CURSOR_AREA_SIZE_MIN);
|
||||
return size;
|
||||
return validateSize(size);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -110,4 +118,10 @@ public class ToggleAutoclickCursorAreaSizeController extends SliderPreferenceCon
|
||||
public int getMin() {
|
||||
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;
|
||||
|
||||
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 org.mockito.ArgumentMatchers.anyInt;
|
||||
@@ -32,9 +35,11 @@ import android.platform.test.flag.junit.SetFlagsRule;
|
||||
import android.provider.Settings;
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.widget.SliderPreference;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
@@ -106,21 +111,74 @@ public class ToggleAutoclickCursorAreaSizeControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getProgress_matchesSetting() {
|
||||
assertThat(mController.getSliderPosition()).isEqualTo(readSetting());
|
||||
public void getProgress_matchesSetting_inRangeValue() {
|
||||
// TODO(388844952): Use parameter testing.
|
||||
for (int size : ImmutableList.of(20, 40, 60, 80, 100)) {
|
||||
updateSetting(size);
|
||||
|
||||
assertThat(mController.getSliderPosition()).isEqualTo(size);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setProgress_updatesSetting() {
|
||||
for (int size : ImmutableList.of(20, 40, 60, 80, 100)) {
|
||||
mController.setSliderPosition(size);
|
||||
assertThat(readSetting()).isEqualTo(size);
|
||||
public void getProgress_matchesSetting_aboveMaxValue() {
|
||||
updateSetting(120);
|
||||
|
||||
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() {
|
||||
return Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
Settings.Secure.ACCESSIBILITY_AUTOCLICK_CURSOR_AREA_SIZE,
|
||||
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