Merge "[Physical Keyboard][A11y Page] Add Bounce keys dialog" into main
This commit is contained in:
@@ -35,25 +35,25 @@ import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settings.keyboard.Flags;
|
||||
|
||||
/**
|
||||
* Abstract class for toggle controllers of Keyboard accessibility related function.
|
||||
* Abstract class for toggle controllers of Keyboard input setting related function.
|
||||
*/
|
||||
public abstract class KeyboardAccessibilityController extends TogglePreferenceController implements
|
||||
public abstract class InputSettingPreferenceController extends TogglePreferenceController implements
|
||||
LifecycleObserver {
|
||||
private final ContentResolver mContentResolver;
|
||||
private final ContentObserver mContentObserver = new ContentObserver(new Handler(true)) {
|
||||
@Override
|
||||
public void onChange(boolean selfChange, Uri uri) {
|
||||
if (getSettingUri().equals(uri)) {
|
||||
updateKeyboardAccessibilitySettings();
|
||||
onInputSettingUpdated();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
protected abstract void updateKeyboardAccessibilitySettings();
|
||||
protected abstract void onInputSettingUpdated();
|
||||
|
||||
protected abstract Uri getSettingUri();
|
||||
|
||||
public KeyboardAccessibilityController(@NonNull Context context,
|
||||
public InputSettingPreferenceController(@NonNull Context context,
|
||||
@NonNull String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mContentResolver = context.getContentResolver();
|
||||
@@ -94,7 +94,7 @@ public abstract class KeyboardAccessibilityController extends TogglePreferenceCo
|
||||
false,
|
||||
mContentObserver,
|
||||
UserHandle.myUserId());
|
||||
updateKeyboardAccessibilitySettings();
|
||||
onInputSettingUpdated();
|
||||
}
|
||||
|
||||
private void unregisterSettingsObserver() {
|
@@ -20,20 +20,38 @@ import android.content.Context;
|
||||
import android.hardware.input.InputSettings;
|
||||
import android.net.Uri;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.RadioGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.PrimarySwitchPreference;
|
||||
|
||||
public class KeyboardAccessibilityBounceKeysController extends
|
||||
KeyboardAccessibilityController implements
|
||||
InputSettingPreferenceController implements
|
||||
LifecycleObserver {
|
||||
public static final int BOUNCE_KEYS_THRESHOLD = 500;
|
||||
|
||||
private AlertDialog mAlertDialog;
|
||||
@Nullable
|
||||
private PrimarySwitchPreference mPrimaryPreference;
|
||||
|
||||
public KeyboardAccessibilityBounceKeysController(@NonNull Context context,
|
||||
@NonNull String key) {
|
||||
super(context, key);
|
||||
constructDialog(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(@NonNull PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPrimaryPreference = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,6 +61,17 @@ public class KeyboardAccessibilityBounceKeysController extends
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
|
||||
return false;
|
||||
}
|
||||
if (mAlertDialog != null) {
|
||||
mAlertDialog.show();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return InputSettings.isAccessibilityBounceKeysEnabled(mContext);
|
||||
@@ -55,16 +84,12 @@ public class KeyboardAccessibilityBounceKeysController extends
|
||||
return true;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mContext.getString(R.string.bounce_keys_summary, BOUNCE_KEYS_THRESHOLD);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateKeyboardAccessibilitySettings() {
|
||||
setChecked(
|
||||
InputSettings.isAccessibilityBounceKeysEnabled(mContext));
|
||||
protected void onInputSettingUpdated() {
|
||||
if (mPrimaryPreference != null) {
|
||||
mPrimaryPreference.setChecked(
|
||||
InputSettings.isAccessibilityBounceKeysEnabled(mContext));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,4 +97,31 @@ public class KeyboardAccessibilityBounceKeysController extends
|
||||
return Settings.Secure.getUriFor(
|
||||
Settings.Secure.ACCESSIBILITY_BOUNCE_KEYS);
|
||||
}
|
||||
|
||||
private void constructDialog(Context context) {
|
||||
mAlertDialog = new AlertDialog.Builder(context)
|
||||
.setView(R.layout.dialog_a11y_bounce_key)
|
||||
.setPositiveButton(android.R.string.ok,
|
||||
(dialog, which) -> {
|
||||
RadioGroup radioGroup =
|
||||
mAlertDialog.findViewById(R.id.bounce_key_value_group);
|
||||
int checkedRadioButtonId = radioGroup.getCheckedRadioButtonId();
|
||||
int threshold = checkedRadioButtonId == R.id.bounce_key_value_600 ? 600
|
||||
: checkedRadioButtonId == R.id.bounce_key_value_400 ? 400
|
||||
: checkedRadioButtonId == R.id.bounce_key_value_200
|
||||
? 200 : 0;
|
||||
InputSettings.setAccessibilityBounceKeysThreshold(context, threshold);
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss())
|
||||
.create();
|
||||
mAlertDialog.setOnShowListener(dialog -> {
|
||||
RadioGroup radioGroup = mAlertDialog.findViewById(R.id.bounce_key_value_group);
|
||||
int bounceKeysThreshold = InputSettings.getAccessibilityBounceKeysThreshold(context);
|
||||
switch (bounceKeysThreshold) {
|
||||
case 600 -> radioGroup.check(R.id.bounce_key_value_600);
|
||||
case 400 -> radioGroup.check(R.id.bounce_key_value_400);
|
||||
default -> radioGroup.check(R.id.bounce_key_value_200);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -23,14 +23,25 @@ import android.provider.Settings;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
public class KeyboardAccessibilityMouseKeysController extends
|
||||
KeyboardAccessibilityController implements
|
||||
InputSettingPreferenceController implements
|
||||
LifecycleObserver {
|
||||
|
||||
private TwoStatePreference mTwoStatePreference;
|
||||
|
||||
public KeyboardAccessibilityMouseKeysController(@NonNull Context context, @NonNull String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(@NonNull PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mTwoStatePreference = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return InputSettings.isAccessibilityMouseKeysEnabled(mContext);
|
||||
@@ -51,9 +62,11 @@ public class KeyboardAccessibilityMouseKeysController extends
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateKeyboardAccessibilitySettings() {
|
||||
setChecked(
|
||||
InputSettings.isAccessibilityMouseKeysEnabled(mContext));
|
||||
protected void onInputSettingUpdated() {
|
||||
if (mTwoStatePreference != null) {
|
||||
mTwoStatePreference.setChecked(
|
||||
InputSettings.isAccessibilityMouseKeysEnabled(mContext));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -23,18 +23,26 @@ import android.provider.Settings;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
|
||||
import com.android.settings.R;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
public class KeyboardAccessibilitySlowKeysController extends
|
||||
KeyboardAccessibilityController implements
|
||||
InputSettingPreferenceController implements
|
||||
LifecycleObserver {
|
||||
public static final int SLOW_KEYS_THRESHOLD = 500;
|
||||
|
||||
private TwoStatePreference mTwoStatePreference;
|
||||
|
||||
public KeyboardAccessibilitySlowKeysController(@NonNull Context context, @NonNull String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(@NonNull PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mTwoStatePreference = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return InputSettings.isAccessibilitySlowKeysEnabled(mContext);
|
||||
@@ -54,16 +62,12 @@ public class KeyboardAccessibilitySlowKeysController extends
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mContext.getString(R.string.slow_keys_summary, SLOW_KEYS_THRESHOLD);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateKeyboardAccessibilitySettings() {
|
||||
setChecked(
|
||||
InputSettings.isAccessibilitySlowKeysEnabled(mContext));
|
||||
protected void onInputSettingUpdated() {
|
||||
if (mTwoStatePreference != null) {
|
||||
mTwoStatePreference.setChecked(
|
||||
InputSettings.isAccessibilitySlowKeysEnabled(mContext));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -23,15 +23,26 @@ import android.provider.Settings;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.TwoStatePreference;
|
||||
|
||||
public class KeyboardAccessibilityStickyKeysController extends
|
||||
KeyboardAccessibilityController implements
|
||||
InputSettingPreferenceController implements
|
||||
LifecycleObserver {
|
||||
|
||||
private TwoStatePreference mTwoStatePreference;
|
||||
|
||||
public KeyboardAccessibilityStickyKeysController(@NonNull Context context,
|
||||
@NonNull String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(@NonNull PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mTwoStatePreference = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return InputSettings.isAccessibilityStickyKeysEnabled(mContext);
|
||||
@@ -52,9 +63,11 @@ public class KeyboardAccessibilityStickyKeysController extends
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateKeyboardAccessibilitySettings() {
|
||||
setChecked(
|
||||
InputSettings.isAccessibilityStickyKeysEnabled(mContext));
|
||||
protected void onInputSettingUpdated() {
|
||||
if (mTwoStatePreference != null) {
|
||||
mTwoStatePreference.setChecked(
|
||||
InputSettings.isAccessibilityStickyKeysEnabled(mContext));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user