[Physical Keyboard][A11y Page] Add Bounce keys dialog
1.Add dialog for adjust bounce key to different values. demo video: b/346949547#comment24. 2.Update summary text. 3.When receive update from content uri, update toggle state directly. 4.Rename Controller to more suitable name. Bug: 346949547 Test: atest SettingsRoboTests Flag: com.android.settings.keyboard.keyboard_and_touchpad_a11y_new_page_enabled Change-Id: I94d8d1a77528b13f59b2d67dfa30e17dd177e385
This commit is contained in:
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user