Merge "a11y: Plumb autoclick cursor area size settings to PrefController" into main

This commit is contained in:
Wenyu Zhang
2025-01-07 17:39:23 -08:00
committed by Android (Google) Code Review
2 changed files with 43 additions and 10 deletions

View File

@@ -17,9 +17,14 @@
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_SIZE_MAX;
import static android.view.accessibility.AccessibilityManager.AUTOCLICK_CURSOR_AREA_SIZE_MIN;
import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.provider.Settings;
import android.view.accessibility.AccessibilityManager;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@@ -37,15 +42,14 @@ public class ToggleAutoclickCursorAreaSizeController extends SliderPreferenceCon
public static final String TAG = ToggleAutoclickCursorAreaSizeController.class.getSimpleName(); public static final String TAG = ToggleAutoclickCursorAreaSizeController.class.getSimpleName();
private static final int MIN_SIZE = 20; private final ContentResolver mContentResolver;
private static final int MAX_SIZE = 100;
private static final int DEFAULT_SIZE = 60;
private final SharedPreferences mSharedPreferences; private final SharedPreferences mSharedPreferences;
public ToggleAutoclickCursorAreaSizeController(@NonNull Context context, public ToggleAutoclickCursorAreaSizeController(@NonNull Context context,
@NonNull String preferenceKey) { @NonNull String preferenceKey) {
super(context, preferenceKey); super(context, preferenceKey);
mContentResolver = context.getContentResolver();
mSharedPreferences = context.getSharedPreferences(context.getPackageName(), MODE_PRIVATE); mSharedPreferences = context.getSharedPreferences(context.getPackageName(), MODE_PRIVATE);
} }
@@ -76,28 +80,34 @@ public class ToggleAutoclickCursorAreaSizeController extends SliderPreferenceCon
@Override @Override
public void onSharedPreferenceChanged( public void onSharedPreferenceChanged(
@NonNull SharedPreferences sharedPreferences, @Nullable String key) { @NonNull SharedPreferences sharedPreferences, @Nullable String key) {
// TODO(b/383901288): Update slider. // TODO(b/383901288): Update slider if interested preference has changed.
} }
@Override @Override
public boolean setSliderPosition(int position) { public boolean setSliderPosition(int position) {
// TODO(b/383901288): Update settings. Settings.Secure.putInt(mContentResolver,
Settings.Secure.ACCESSIBILITY_AUTOCLICK_CURSOR_AREA_SIZE, position);
return true; return true;
} }
@Override @Override
public int getSliderPosition() { public int getSliderPosition() {
// TODO(b/383901288): retrieve from settings and fallback to default. int size = Settings.Secure.getInt(mContentResolver,
return DEFAULT_SIZE; 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;
} }
@Override @Override
public int getMax() { public int getMax() {
return MAX_SIZE; return AUTOCLICK_CURSOR_AREA_SIZE_MAX;
} }
@Override @Override
public int getMin() { public int getMin() {
return MIN_SIZE; return AUTOCLICK_CURSOR_AREA_SIZE_MIN;
} }
} }

View File

@@ -29,11 +29,15 @@ import android.content.SharedPreferences;
import android.platform.test.annotations.DisableFlags; import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags; import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule; import android.platform.test.flag.junit.SetFlagsRule;
import android.provider.Settings;
import android.view.accessibility.AccessibilityManager;
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.google.common.collect.ImmutableList;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@@ -100,4 +104,23 @@ public class ToggleAutoclickCursorAreaSizeControllerTest {
verify(prefs).unregisterOnSharedPreferenceChangeListener(controller); verify(prefs).unregisterOnSharedPreferenceChangeListener(controller);
} }
@Test
public void getProgress_matchesSetting() {
assertThat(mController.getSliderPosition()).isEqualTo(readSetting());
}
@Test
public void setProgress_updatesSetting() {
for (int size : ImmutableList.of(20, 40, 60, 80, 100)) {
mController.setSliderPosition(size);
assertThat(readSetting()).isEqualTo(size);
}
}
private int readSetting() {
return Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.ACCESSIBILITY_AUTOCLICK_CURSOR_AREA_SIZE,
AccessibilityManager.AUTOCLICK_CURSOR_AREA_SIZE_DEFAULT);
}
} }