[Physical Keyboard] Move Dialog to DialogFragment
Move Bounce key and Slow key Dialog to DialogFragment, dialog will not be dismissed when screen rotate. Bug: 390243451 Bug: 374037603 Flag: com.android.settings.keyboard.keyboard_and_touchpad_a11y_new_page_enabled Test: atest packages/apps/Settings/tests/robotests/src/com/android/settings/inputmethod/ Change-Id: Ide87dbf8214f411941114281e7a5e8c81f75bdd4
This commit is contained in:
@@ -25,36 +25,29 @@ import android.database.ContentObserver;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.view.View;
|
|
||||||
import android.widget.RadioButton;
|
|
||||||
import android.widget.RadioGroup;
|
|
||||||
import android.widget.SeekBar;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.lifecycle.LifecycleObserver;
|
import androidx.lifecycle.LifecycleObserver;
|
||||||
import androidx.lifecycle.OnLifecycleEvent;
|
import androidx.lifecycle.OnLifecycleEvent;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.core.TogglePreferenceController;
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
import com.android.settings.keyboard.Flags;
|
import com.android.settings.keyboard.Flags;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||||
|
|
||||||
import java.text.NumberFormat;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract class for toggle controllers of Keyboard input setting related function.
|
* Abstract class for toggle controllers of Keyboard input setting related function.
|
||||||
*/
|
*/
|
||||||
public abstract class InputSettingPreferenceController extends TogglePreferenceController implements
|
public abstract class InputSettingPreferenceController extends TogglePreferenceController implements
|
||||||
LifecycleObserver {
|
LifecycleObserver {
|
||||||
private static final int CUSTOM_PROGRESS_INTERVAL = 100;
|
|
||||||
private static final long MILLISECOND_IN_SECONDS = TimeUnit.SECONDS.toMillis(1);
|
|
||||||
private final ContentResolver mContentResolver;
|
private final ContentResolver mContentResolver;
|
||||||
protected final MetricsFeatureProvider mMetricsFeatureProvider;
|
protected final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||||
|
protected FragmentManager mFragmentManager;
|
||||||
|
|
||||||
private final ContentObserver mContentObserver = new ContentObserver(new Handler(true)) {
|
private final ContentObserver mContentObserver = new ContentObserver(new Handler(true)) {
|
||||||
@Override
|
@Override
|
||||||
public void onChange(boolean selfChange, Uri uri) {
|
public void onChange(boolean selfChange, Uri uri) {
|
||||||
@@ -72,13 +65,6 @@ public abstract class InputSettingPreferenceController extends TogglePreferenceC
|
|||||||
protected void updateInputSettingKeysValue(int thresholdTimeMillis) {
|
protected void updateInputSettingKeysValue(int thresholdTimeMillis) {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getInputSettingKeysValue() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void onCustomValueUpdated(int thresholdTimeMillis) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public InputSettingPreferenceController(@NonNull Context context,
|
public InputSettingPreferenceController(@NonNull Context context,
|
||||||
@NonNull String preferenceKey) {
|
@NonNull String preferenceKey) {
|
||||||
super(context, preferenceKey);
|
super(context, preferenceKey);
|
||||||
@@ -86,6 +72,10 @@ public abstract class InputSettingPreferenceController extends TogglePreferenceC
|
|||||||
mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
|
mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFragment(Fragment fragment) {
|
||||||
|
mFragmentManager = fragment.getParentFragmentManager();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(@NonNull Preference preference) {
|
public void updateState(@NonNull Preference preference) {
|
||||||
super.updateState(preference);
|
super.updateState(preference);
|
||||||
@@ -127,113 +117,4 @@ public abstract class InputSettingPreferenceController extends TogglePreferenceC
|
|||||||
private void unregisterSettingsObserver() {
|
private void unregisterSettingsObserver() {
|
||||||
mContentResolver.unregisterContentObserver(mContentObserver);
|
mContentResolver.unregisterContentObserver(mContentObserver);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void constructDialog(Context context, int titleRes, int subtitleRes) {
|
|
||||||
mAlertDialog = new AlertDialog.Builder(context)
|
|
||||||
.setView(R.layout.dialog_keyboard_a11y_input_setting_keys)
|
|
||||||
.setPositiveButton(android.R.string.ok,
|
|
||||||
(dialog, which) -> {
|
|
||||||
RadioGroup radioGroup =
|
|
||||||
mAlertDialog.findViewById(
|
|
||||||
R.id.input_setting_keys_value_group);
|
|
||||||
SeekBar seekbar = mAlertDialog.findViewById(
|
|
||||||
R.id.input_setting_keys_value_custom_slider);
|
|
||||||
RadioButton customRadioButton = mAlertDialog.findViewById(
|
|
||||||
R.id.input_setting_keys_value_custom);
|
|
||||||
int threshold;
|
|
||||||
if (customRadioButton.isChecked()) {
|
|
||||||
threshold = seekbar.getProgress() * CUSTOM_PROGRESS_INTERVAL;
|
|
||||||
} else {
|
|
||||||
int checkedRadioButtonId = radioGroup.getCheckedRadioButtonId();
|
|
||||||
if (checkedRadioButtonId == R.id.input_setting_keys_value_600) {
|
|
||||||
threshold = 600;
|
|
||||||
} else if (checkedRadioButtonId
|
|
||||||
== R.id.input_setting_keys_value_400) {
|
|
||||||
threshold = 400;
|
|
||||||
} else if (checkedRadioButtonId
|
|
||||||
== R.id.input_setting_keys_value_200) {
|
|
||||||
threshold = 200;
|
|
||||||
} else {
|
|
||||||
threshold = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
updateInputSettingKeysValue(threshold);
|
|
||||||
onCustomValueUpdated(threshold);
|
|
||||||
})
|
|
||||||
.setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss())
|
|
||||||
.create();
|
|
||||||
mAlertDialog.setOnShowListener(dialog -> {
|
|
||||||
RadioGroup cannedValueRadioGroup = mAlertDialog.findViewById(
|
|
||||||
R.id.input_setting_keys_value_group);
|
|
||||||
RadioButton customRadioButton = mAlertDialog.findViewById(
|
|
||||||
R.id.input_setting_keys_value_custom);
|
|
||||||
TextView customValueTextView = mAlertDialog.findViewById(
|
|
||||||
R.id.input_setting_keys_value_custom_value);
|
|
||||||
SeekBar customProgressBar = mAlertDialog.findViewById(
|
|
||||||
R.id.input_setting_keys_value_custom_slider);
|
|
||||||
TextView titleTextView = mAlertDialog.findViewById(
|
|
||||||
R.id.input_setting_keys_dialog_title);
|
|
||||||
TextView subTitleTextView = mAlertDialog.findViewById(
|
|
||||||
R.id.input_setting_keys_dialog_subtitle);
|
|
||||||
titleTextView.setText(titleRes);
|
|
||||||
subTitleTextView.setText(subtitleRes);
|
|
||||||
|
|
||||||
customProgressBar.incrementProgressBy(CUSTOM_PROGRESS_INTERVAL);
|
|
||||||
customProgressBar.setProgress(1);
|
|
||||||
View customValueView = mAlertDialog.findViewById(
|
|
||||||
R.id.input_setting_keys_custom_value_option);
|
|
||||||
customValueView.setOnClickListener(l -> customRadioButton.performClick());
|
|
||||||
customRadioButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
|
||||||
if (isChecked) {
|
|
||||||
cannedValueRadioGroup.clearCheck();
|
|
||||||
}
|
|
||||||
customValueTextView.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
|
||||||
customValueTextView.setText(
|
|
||||||
progressToThresholdInSecond(customProgressBar.getProgress()));
|
|
||||||
customProgressBar.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
|
||||||
buttonView.setChecked(isChecked);
|
|
||||||
});
|
|
||||||
cannedValueRadioGroup.setOnCheckedChangeListener(
|
|
||||||
(group, checkedId) -> customRadioButton.setChecked(false));
|
|
||||||
customProgressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
|
||||||
customValueTextView.setText(progressToThresholdInSecond(progress));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
initStateBasedOnThreshold(cannedValueRadioGroup, customRadioButton, customValueTextView,
|
|
||||||
customProgressBar);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String progressToThresholdInSecond(int progress) {
|
|
||||||
return NumberFormat.getInstance().format((float) progress * CUSTOM_PROGRESS_INTERVAL
|
|
||||||
/ MILLISECOND_IN_SECONDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initStateBasedOnThreshold(RadioGroup cannedValueRadioGroup,
|
|
||||||
RadioButton customRadioButton, TextView customValueTextView,
|
|
||||||
SeekBar customProgressBar) {
|
|
||||||
int inputSettingKeysThreshold = getInputSettingKeysValue();
|
|
||||||
switch (inputSettingKeysThreshold) {
|
|
||||||
case 600 -> cannedValueRadioGroup.check(R.id.input_setting_keys_value_600);
|
|
||||||
case 400 -> cannedValueRadioGroup.check(R.id.input_setting_keys_value_400);
|
|
||||||
case 0, 200 -> cannedValueRadioGroup.check(R.id.input_setting_keys_value_200);
|
|
||||||
default -> {
|
|
||||||
customValueTextView.setText(
|
|
||||||
String.valueOf(
|
|
||||||
(double) inputSettingKeysThreshold / MILLISECOND_IN_SECONDS));
|
|
||||||
customProgressBar.setProgress(inputSettingKeysThreshold / CUSTOM_PROGRESS_INTERVAL);
|
|
||||||
customRadioButton.setChecked(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.inputmethod;
|
package com.android.settings.inputmethod;
|
||||||
|
|
||||||
import static android.app.settings.SettingsEnums.ACTION_BOUNCE_KEYS_CUSTOM_VALUE_CHANGE;
|
|
||||||
import static android.app.settings.SettingsEnums.ACTION_BOUNCE_KEYS_DISABLED;
|
import static android.app.settings.SettingsEnums.ACTION_BOUNCE_KEYS_DISABLED;
|
||||||
import static android.app.settings.SettingsEnums.ACTION_BOUNCE_KEYS_ENABLED;
|
import static android.app.settings.SettingsEnums.ACTION_BOUNCE_KEYS_ENABLED;
|
||||||
|
|
||||||
@@ -32,13 +31,13 @@ import androidx.lifecycle.LifecycleObserver;
|
|||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settingslib.PrimarySwitchPreference;
|
import com.android.settingslib.PrimarySwitchPreference;
|
||||||
|
|
||||||
public class KeyboardAccessibilityBounceKeysController extends
|
public class KeyboardAccessibilityBounceKeysController extends
|
||||||
InputSettingPreferenceController implements
|
InputSettingPreferenceController implements
|
||||||
LifecycleObserver {
|
LifecycleObserver {
|
||||||
public static final int BOUNCE_KEYS_THRESHOLD = 500;
|
public static final int BOUNCE_KEYS_THRESHOLD = 500;
|
||||||
|
private static final String KEY_TAG = "bounce_keys_dialog_tag";
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private PrimarySwitchPreference mPrimaryPreference;
|
private PrimarySwitchPreference mPrimaryPreference;
|
||||||
@@ -46,8 +45,6 @@ public class KeyboardAccessibilityBounceKeysController extends
|
|||||||
public KeyboardAccessibilityBounceKeysController(@NonNull Context context,
|
public KeyboardAccessibilityBounceKeysController(@NonNull Context context,
|
||||||
@NonNull String key) {
|
@NonNull String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
constructDialog(context, R.string.bounce_keys_dialog_title,
|
|
||||||
R.string.bounce_keys_dialog_subtitle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -65,12 +62,11 @@ public class KeyboardAccessibilityBounceKeysController extends
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handlePreferenceTreeClick(@NonNull Preference preference) {
|
public boolean handlePreferenceTreeClick(@NonNull Preference preference) {
|
||||||
if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
|
if (!TextUtils.equals(preference.getKey(), getPreferenceKey())
|
||||||
|
|| mFragmentManager == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (mAlertDialog != null) {
|
KeyboardAccessibilityBounceKeysDialogFragment.getInstance().show(mFragmentManager, KEY_TAG);
|
||||||
mAlertDialog.show();
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,12 +83,6 @@ public class KeyboardAccessibilityBounceKeysController extends
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCustomValueUpdated(int thresholdTimeMillis) {
|
|
||||||
mMetricsFeatureProvider.action(mContext, ACTION_BOUNCE_KEYS_CUSTOM_VALUE_CHANGE,
|
|
||||||
thresholdTimeMillis);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onInputSettingUpdated() {
|
protected void onInputSettingUpdated() {
|
||||||
if (mPrimaryPreference != null) {
|
if (mPrimaryPreference != null) {
|
||||||
@@ -111,9 +101,4 @@ public class KeyboardAccessibilityBounceKeysController extends
|
|||||||
protected void updateInputSettingKeysValue(int thresholdTimeMillis) {
|
protected void updateInputSettingKeysValue(int thresholdTimeMillis) {
|
||||||
InputSettings.setAccessibilityBounceKeysThreshold(mContext, thresholdTimeMillis);
|
InputSettings.setAccessibilityBounceKeysThreshold(mContext, thresholdTimeMillis);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getInputSettingKeysValue() {
|
|
||||||
return InputSettings.getAccessibilityBounceKeysThreshold(mContext);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2025 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.inputmethod;
|
||||||
|
|
||||||
|
import static android.app.settings.SettingsEnums.ACTION_BOUNCE_KEYS_CUSTOM_VALUE_CHANGE;
|
||||||
|
|
||||||
|
import android.hardware.input.InputSettings;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
|
public class KeyboardAccessibilityBounceKeysDialogFragment extends
|
||||||
|
KeyboardAccessibilityKeysDialogFragment {
|
||||||
|
|
||||||
|
static KeyboardAccessibilityBounceKeysDialogFragment getInstance() {
|
||||||
|
final KeyboardAccessibilityBounceKeysDialogFragment result =
|
||||||
|
new KeyboardAccessibilityBounceKeysDialogFragment();
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putInt(EXTRA_TITLE_RES, R.string.bounce_keys_dialog_title);
|
||||||
|
bundle.putInt(EXTRA_SUBTITLE_RES, R.string.bounce_keys_dialog_subtitle);
|
||||||
|
result.setArguments(bundle);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateInputSettingKeysValue(int thresholdTimeMillis) {
|
||||||
|
InputSettings.setAccessibilityBounceKeysThreshold(getContext(), thresholdTimeMillis);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCustomValueUpdated(int thresholdTimeMillis) {
|
||||||
|
mMetricsFeatureProvider.action(getContext(), ACTION_BOUNCE_KEYS_CUSTOM_VALUE_CHANGE,
|
||||||
|
thresholdTimeMillis);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getInputSettingKeysValue() {
|
||||||
|
return InputSettings.getAccessibilityBounceKeysThreshold(getContext());
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,187 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2025 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.inputmethod;
|
||||||
|
|
||||||
|
import static android.view.WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.Window;
|
||||||
|
import android.widget.RadioButton;
|
||||||
|
import android.widget.RadioGroup;
|
||||||
|
import android.widget.SeekBar;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.fragment.app.DialogFragment;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||||
|
|
||||||
|
import org.jspecify.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public abstract class KeyboardAccessibilityKeysDialogFragment extends DialogFragment {
|
||||||
|
private static final int CUSTOM_PROGRESS_INTERVAL = 100;
|
||||||
|
private static final long MILLISECOND_IN_SECONDS = TimeUnit.SECONDS.toMillis(1);
|
||||||
|
protected static final String EXTRA_TITLE_RES = "extra_title_res";
|
||||||
|
protected static final String EXTRA_SUBTITLE_RES = "extra_subtitle_res";
|
||||||
|
|
||||||
|
protected final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||||
|
|
||||||
|
public KeyboardAccessibilityKeysDialogFragment() {
|
||||||
|
mMetricsFeatureProvider = FeatureFactory.getFeatureFactory().getMetricsFeatureProvider();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void updateInputSettingKeysValue(int thresholdTimeMillis) {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onCustomValueUpdated(int thresholdTimeMillis) {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getInputSettingKeysValue() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreateDialog(savedInstanceState);
|
||||||
|
int titleRes = getArguments().getInt(EXTRA_TITLE_RES);
|
||||||
|
int subtitleRes = getArguments().getInt(EXTRA_SUBTITLE_RES);
|
||||||
|
|
||||||
|
Activity activity = getActivity();
|
||||||
|
View dialoglayout =
|
||||||
|
LayoutInflater.from(activity).inflate(
|
||||||
|
R.layout.dialog_keyboard_a11y_input_setting_keys, null);
|
||||||
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity);
|
||||||
|
dialogBuilder.setView(dialoglayout);
|
||||||
|
dialogBuilder.setPositiveButton(android.R.string.ok,
|
||||||
|
(dialog, which) -> {
|
||||||
|
RadioGroup radioGroup =
|
||||||
|
dialoglayout.findViewById(
|
||||||
|
R.id.input_setting_keys_value_group);
|
||||||
|
SeekBar seekbar = dialoglayout.findViewById(
|
||||||
|
R.id.input_setting_keys_value_custom_slider);
|
||||||
|
RadioButton customRadioButton = dialoglayout.findViewById(
|
||||||
|
R.id.input_setting_keys_value_custom);
|
||||||
|
int threshold;
|
||||||
|
if (customRadioButton.isChecked()) {
|
||||||
|
threshold = seekbar.getProgress() * CUSTOM_PROGRESS_INTERVAL;
|
||||||
|
} else {
|
||||||
|
int checkedRadioButtonId = radioGroup.getCheckedRadioButtonId();
|
||||||
|
if (checkedRadioButtonId == R.id.input_setting_keys_value_600) {
|
||||||
|
threshold = 600;
|
||||||
|
} else if (checkedRadioButtonId
|
||||||
|
== R.id.input_setting_keys_value_400) {
|
||||||
|
threshold = 400;
|
||||||
|
} else if (checkedRadioButtonId
|
||||||
|
== R.id.input_setting_keys_value_200) {
|
||||||
|
threshold = 200;
|
||||||
|
} else {
|
||||||
|
threshold = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateInputSettingKeysValue(threshold);
|
||||||
|
onCustomValueUpdated(threshold);
|
||||||
|
})
|
||||||
|
.setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss());
|
||||||
|
AlertDialog accessibilityKeyDialog = dialogBuilder.create();
|
||||||
|
accessibilityKeyDialog.setOnShowListener(dialog -> {
|
||||||
|
RadioGroup cannedValueRadioGroup = accessibilityKeyDialog.findViewById(
|
||||||
|
R.id.input_setting_keys_value_group);
|
||||||
|
RadioButton customRadioButton = accessibilityKeyDialog.findViewById(
|
||||||
|
R.id.input_setting_keys_value_custom);
|
||||||
|
TextView customValueTextView = accessibilityKeyDialog.findViewById(
|
||||||
|
R.id.input_setting_keys_value_custom_value);
|
||||||
|
SeekBar customProgressBar = accessibilityKeyDialog.findViewById(
|
||||||
|
R.id.input_setting_keys_value_custom_slider);
|
||||||
|
TextView titleTextView = accessibilityKeyDialog.findViewById(
|
||||||
|
R.id.input_setting_keys_dialog_title);
|
||||||
|
TextView subTitleTextView = accessibilityKeyDialog.findViewById(
|
||||||
|
R.id.input_setting_keys_dialog_subtitle);
|
||||||
|
titleTextView.setText(titleRes);
|
||||||
|
subTitleTextView.setText(subtitleRes);
|
||||||
|
|
||||||
|
customProgressBar.incrementProgressBy(CUSTOM_PROGRESS_INTERVAL);
|
||||||
|
customProgressBar.setProgress(1);
|
||||||
|
View customValueView = accessibilityKeyDialog.findViewById(
|
||||||
|
R.id.input_setting_keys_custom_value_option);
|
||||||
|
customValueView.setOnClickListener(l -> customRadioButton.performClick());
|
||||||
|
customRadioButton.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||||
|
if (isChecked) {
|
||||||
|
cannedValueRadioGroup.clearCheck();
|
||||||
|
}
|
||||||
|
customValueTextView.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
||||||
|
customValueTextView.setText(
|
||||||
|
progressToThresholdInSecond(customProgressBar.getProgress()));
|
||||||
|
customProgressBar.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
||||||
|
buttonView.setChecked(isChecked);
|
||||||
|
});
|
||||||
|
cannedValueRadioGroup.setOnCheckedChangeListener(
|
||||||
|
(group, checkedId) -> customRadioButton.setChecked(false));
|
||||||
|
customProgressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||||
|
customValueTextView.setText(progressToThresholdInSecond(progress));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
initStateBasedOnThreshold(cannedValueRadioGroup, customRadioButton, customValueTextView,
|
||||||
|
customProgressBar);
|
||||||
|
});
|
||||||
|
|
||||||
|
final Window window = accessibilityKeyDialog.getWindow();
|
||||||
|
window.setType(TYPE_SYSTEM_DIALOG);
|
||||||
|
|
||||||
|
return accessibilityKeyDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String progressToThresholdInSecond(int progress) {
|
||||||
|
return String.valueOf((double) progress * CUSTOM_PROGRESS_INTERVAL
|
||||||
|
/ MILLISECOND_IN_SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initStateBasedOnThreshold(RadioGroup cannedValueRadioGroup,
|
||||||
|
RadioButton customRadioButton, TextView customValueTextView,
|
||||||
|
SeekBar customProgressBar) {
|
||||||
|
int inputSettingKeysThreshold = getInputSettingKeysValue();
|
||||||
|
switch (inputSettingKeysThreshold) {
|
||||||
|
case 600 -> cannedValueRadioGroup.check(R.id.input_setting_keys_value_600);
|
||||||
|
case 400 -> cannedValueRadioGroup.check(R.id.input_setting_keys_value_400);
|
||||||
|
case 0, 200 -> cannedValueRadioGroup.check(R.id.input_setting_keys_value_200);
|
||||||
|
default -> {
|
||||||
|
customValueTextView.setText(
|
||||||
|
String.valueOf(
|
||||||
|
(double) inputSettingKeysThreshold / MILLISECOND_IN_SECONDS));
|
||||||
|
customProgressBar.setProgress(inputSettingKeysThreshold / CUSTOM_PROGRESS_INTERVAL);
|
||||||
|
customRadioButton.setChecked(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.inputmethod;
|
package com.android.settings.inputmethod;
|
||||||
|
|
||||||
import static android.app.settings.SettingsEnums.ACTION_SLOW_KEYS_CUSTOM_VALUE_CHANGE;
|
|
||||||
import static android.app.settings.SettingsEnums.ACTION_SLOW_KEYS_DISABLED;
|
import static android.app.settings.SettingsEnums.ACTION_SLOW_KEYS_DISABLED;
|
||||||
import static android.app.settings.SettingsEnums.ACTION_SLOW_KEYS_ENABLED;
|
import static android.app.settings.SettingsEnums.ACTION_SLOW_KEYS_ENABLED;
|
||||||
|
|
||||||
@@ -32,20 +31,19 @@ import androidx.lifecycle.LifecycleObserver;
|
|||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settingslib.PrimarySwitchPreference;
|
import com.android.settingslib.PrimarySwitchPreference;
|
||||||
|
|
||||||
public class KeyboardAccessibilitySlowKeysController extends
|
public class KeyboardAccessibilitySlowKeysController extends
|
||||||
InputSettingPreferenceController implements
|
InputSettingPreferenceController implements
|
||||||
LifecycleObserver {
|
LifecycleObserver {
|
||||||
public static final int SLOW_KEYS_THRESHOLD = 500;
|
public static final int SLOW_KEYS_THRESHOLD = 500;
|
||||||
|
private static final String KEY_TAG = "slow_keys_dialog_tag";
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private PrimarySwitchPreference mPrimarySwitchPreference;
|
private PrimarySwitchPreference mPrimarySwitchPreference;
|
||||||
|
|
||||||
public KeyboardAccessibilitySlowKeysController(@NonNull Context context, @NonNull String key) {
|
public KeyboardAccessibilitySlowKeysController(@NonNull Context context, @NonNull String key) {
|
||||||
super(context, key);
|
super(context, key);
|
||||||
constructDialog(context, R.string.slow_keys, R.string.slow_keys_summary);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -90,12 +88,11 @@ public class KeyboardAccessibilitySlowKeysController extends
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handlePreferenceTreeClick(@NonNull Preference preference) {
|
public boolean handlePreferenceTreeClick(@NonNull Preference preference) {
|
||||||
if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
|
if (!TextUtils.equals(preference.getKey(), getPreferenceKey())
|
||||||
|
|| mFragmentManager == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (mAlertDialog != null) {
|
KeyboardAccessibilitySlowKeysDialogFragment.getInstance().show(mFragmentManager, KEY_TAG);
|
||||||
mAlertDialog.show();
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,15 +100,4 @@ public class KeyboardAccessibilitySlowKeysController extends
|
|||||||
protected void updateInputSettingKeysValue(int thresholdTimeMillis) {
|
protected void updateInputSettingKeysValue(int thresholdTimeMillis) {
|
||||||
InputSettings.setAccessibilitySlowKeysThreshold(mContext, thresholdTimeMillis);
|
InputSettings.setAccessibilitySlowKeysThreshold(mContext, thresholdTimeMillis);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCustomValueUpdated(int thresholdTimeMillis) {
|
|
||||||
mMetricsFeatureProvider.action(mContext,
|
|
||||||
ACTION_SLOW_KEYS_CUSTOM_VALUE_CHANGE, thresholdTimeMillis);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getInputSettingKeysValue() {
|
|
||||||
return InputSettings.getAccessibilitySlowKeysThreshold(mContext);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2025 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.inputmethod;
|
||||||
|
|
||||||
|
import static android.app.settings.SettingsEnums.ACTION_SLOW_KEYS_CUSTOM_VALUE_CHANGE;
|
||||||
|
|
||||||
|
import android.hardware.input.InputSettings;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
|
public class KeyboardAccessibilitySlowKeysDialogFragment extends
|
||||||
|
KeyboardAccessibilityKeysDialogFragment {
|
||||||
|
|
||||||
|
static KeyboardAccessibilitySlowKeysDialogFragment getInstance() {
|
||||||
|
final KeyboardAccessibilitySlowKeysDialogFragment result =
|
||||||
|
new KeyboardAccessibilitySlowKeysDialogFragment();
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putInt(EXTRA_TITLE_RES, R.string.slow_keys);
|
||||||
|
bundle.putInt(EXTRA_SUBTITLE_RES, R.string.slow_keys_summary);
|
||||||
|
result.setArguments(bundle);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateInputSettingKeysValue(int thresholdTimeMillis) {
|
||||||
|
InputSettings.setAccessibilitySlowKeysThreshold(getContext(), thresholdTimeMillis);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCustomValueUpdated(int thresholdTimeMillis) {
|
||||||
|
mMetricsFeatureProvider.action(getContext(),
|
||||||
|
ACTION_SLOW_KEYS_CUSTOM_VALUE_CHANGE, thresholdTimeMillis);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getInputSettingKeysValue() {
|
||||||
|
return InputSettings.getAccessibilitySlowKeysThreshold(getContext());
|
||||||
|
}
|
||||||
|
}
|
@@ -51,6 +51,8 @@ public class PhysicalKeyboardA11yFragment extends DashboardFragment
|
|||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
mInputManager = Preconditions.checkNotNull(getActivity()
|
mInputManager = Preconditions.checkNotNull(getActivity()
|
||||||
.getSystemService(InputManager.class));
|
.getSystemService(InputManager.class));
|
||||||
|
use(KeyboardAccessibilitySlowKeysController.class).setFragment(this /*parent*/);
|
||||||
|
use(KeyboardAccessibilityBounceKeysController.class).setFragment(this /*parent*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -18,6 +18,9 @@ package com.android.settings.inputmethod;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -25,12 +28,12 @@ import android.hardware.input.InputSettings;
|
|||||||
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.widget.RadioGroup;
|
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
import androidx.fragment.app.FragmentTransaction;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settings.keyboard.Flags;
|
import com.android.settings.keyboard.Flags;
|
||||||
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
|
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
|
||||||
@@ -45,10 +48,13 @@ import org.mockito.junit.MockitoRule;
|
|||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
import org.robolectric.shadows.ShadowLooper;
|
import org.robolectric.annotation.Implementation;
|
||||||
|
import org.robolectric.annotation.Implements;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@Config(shadows = {
|
@Config(shadows = {
|
||||||
|
KeyboardAccessibilityBounceKeysControllerTest
|
||||||
|
.ShadowKeyboardAccessibilityBounceKeysDialogFragment.class,
|
||||||
com.android.settings.testutils.shadow.ShadowFragment.class,
|
com.android.settings.testutils.shadow.ShadowFragment.class,
|
||||||
ShadowAlertDialogCompat.class,
|
ShadowAlertDialogCompat.class,
|
||||||
})
|
})
|
||||||
@@ -60,6 +66,15 @@ public class KeyboardAccessibilityBounceKeysControllerTest {
|
|||||||
private static final String PREFERENCE_KEY = "keyboard_a11y_page_bounce_keys";
|
private static final String PREFERENCE_KEY = "keyboard_a11y_page_bounce_keys";
|
||||||
@Mock
|
@Mock
|
||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
|
@Mock
|
||||||
|
private Fragment mFragment;
|
||||||
|
@Mock
|
||||||
|
private FragmentManager mFragmentManager;
|
||||||
|
@Mock
|
||||||
|
private FragmentTransaction mFragmentTransaction;
|
||||||
|
@Mock
|
||||||
|
private KeyboardAccessibilityBounceKeysDialogFragment
|
||||||
|
mKeyboardAccessibilityBounceKeysDialogFragment;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private KeyboardAccessibilityBounceKeysController mKeyboardAccessibilityBounceKeysController;
|
private KeyboardAccessibilityBounceKeysController mKeyboardAccessibilityBounceKeysController;
|
||||||
|
|
||||||
@@ -71,6 +86,11 @@ public class KeyboardAccessibilityBounceKeysControllerTest {
|
|||||||
mContext,
|
mContext,
|
||||||
PREFERENCE_KEY);
|
PREFERENCE_KEY);
|
||||||
when(mPreference.getKey()).thenReturn(PREFERENCE_KEY);
|
when(mPreference.getKey()).thenReturn(PREFERENCE_KEY);
|
||||||
|
when(mFragment.getParentFragmentManager()).thenReturn(mFragmentManager);
|
||||||
|
when(mFragmentManager.beginTransaction()).thenReturn(mFragmentTransaction);
|
||||||
|
mKeyboardAccessibilityBounceKeysController.setFragment(mFragment);
|
||||||
|
ShadowKeyboardAccessibilityBounceKeysDialogFragment.setInstance(
|
||||||
|
mKeyboardAccessibilityBounceKeysDialogFragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -107,23 +127,25 @@ public class KeyboardAccessibilityBounceKeysControllerTest {
|
|||||||
public void handlePreferenceTreeClick_dialogShows() {
|
public void handlePreferenceTreeClick_dialogShows() {
|
||||||
mKeyboardAccessibilityBounceKeysController.handlePreferenceTreeClick(mPreference);
|
mKeyboardAccessibilityBounceKeysController.handlePreferenceTreeClick(mPreference);
|
||||||
|
|
||||||
AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
verify(mKeyboardAccessibilityBounceKeysDialogFragment).show(any(FragmentManager.class),
|
||||||
|
anyString());
|
||||||
assertThat(alertDialog.isShowing()).isTrue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
/**
|
||||||
public void handlePreferenceTreeClick_performClickOn200_updatesBounceKeysThreshold() {
|
* Note: Actually, shadow of KeyboardAccessibilitySlowKeysDialogFragment will not be used.
|
||||||
mKeyboardAccessibilityBounceKeysController.handlePreferenceTreeClick(mPreference);
|
* Instance that returned with {@link #getInstance} should be set with {@link #setInstance}
|
||||||
AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
*/
|
||||||
RadioGroup radioGroup = alertDialog.findViewById(R.id.input_setting_keys_value_group);
|
@Implements(KeyboardAccessibilityBounceKeysDialogFragment.class)
|
||||||
radioGroup.check(R.id.input_setting_keys_value_200);
|
public static class ShadowKeyboardAccessibilityBounceKeysDialogFragment {
|
||||||
|
static KeyboardAccessibilityBounceKeysDialogFragment sInstance = null;
|
||||||
|
|
||||||
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).performClick();
|
@Implementation
|
||||||
ShadowLooper.idleMainLooper();
|
protected static KeyboardAccessibilityBounceKeysDialogFragment getInstance() {
|
||||||
|
return sInstance;
|
||||||
|
}
|
||||||
|
|
||||||
assertThat(alertDialog.isShowing()).isFalse();
|
public static void setInstance(KeyboardAccessibilityBounceKeysDialogFragment instance) {
|
||||||
int threshold = InputSettings.getAccessibilityBounceKeysThreshold(mContext);
|
sInstance = instance;
|
||||||
assertThat(threshold).isEqualTo(200);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2025 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.inputmethod;
|
||||||
|
|
||||||
|
import static com.android.settings.inputmethod.KeyboardAccessibilityKeysDialogFragment.EXTRA_SUBTITLE_RES;
|
||||||
|
import static com.android.settings.inputmethod.KeyboardAccessibilityKeysDialogFragment.EXTRA_TITLE_RES;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.hardware.input.InputSettings;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.widget.RadioGroup;
|
||||||
|
|
||||||
|
import androidx.fragment.app.testing.FragmentScenario;
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.shadows.ShadowLooper;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
public class KeyboardAccessibilityBounceKeysDialogFragmentTest {
|
||||||
|
private AlertDialog mAlertDialog;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putInt(EXTRA_TITLE_RES, R.string.bounce_keys_dialog_title);
|
||||||
|
bundle.putInt(EXTRA_SUBTITLE_RES, R.string.bounce_keys_dialog_subtitle);
|
||||||
|
|
||||||
|
FragmentScenario<KeyboardAccessibilityBounceKeysDialogFragment> mFragmentScenario =
|
||||||
|
FragmentScenario.launch(
|
||||||
|
KeyboardAccessibilityBounceKeysDialogFragment.class,
|
||||||
|
bundle,
|
||||||
|
R.style.Theme_AlertDialog_SettingsLib,
|
||||||
|
Lifecycle.State.INITIALIZED);
|
||||||
|
mFragmentScenario.moveToState(Lifecycle.State.RESUMED);
|
||||||
|
|
||||||
|
mFragmentScenario.onFragment(fragment -> {
|
||||||
|
assertThat(fragment.getDialog()).isNotNull();
|
||||||
|
assertThat(fragment.requireDialog().isShowing()).isTrue();
|
||||||
|
assertThat(fragment.requireDialog()).isInstanceOf(AlertDialog.class);
|
||||||
|
mAlertDialog = (AlertDialog) fragment.requireDialog();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void handlePreferenceTreeClick_performClickOn200_updatesBounceKeysThreshold() {
|
||||||
|
assertThat(mAlertDialog.isShowing()).isTrue();
|
||||||
|
RadioGroup radioGroup = mAlertDialog.findViewById(R.id.input_setting_keys_value_group);
|
||||||
|
radioGroup.check(R.id.input_setting_keys_value_200);
|
||||||
|
|
||||||
|
mAlertDialog.getButton(AlertDialog.BUTTON_POSITIVE).performClick();
|
||||||
|
ShadowLooper.idleMainLooper();
|
||||||
|
|
||||||
|
assertThat(mAlertDialog.isShowing()).isFalse();
|
||||||
|
int threshold = InputSettings.getAccessibilityBounceKeysThreshold(
|
||||||
|
ApplicationProvider.getApplicationContext());
|
||||||
|
assertThat(threshold).isEqualTo(200);
|
||||||
|
}
|
||||||
|
}
|
@@ -18,6 +18,9 @@ package com.android.settings.inputmethod;
|
|||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -25,12 +28,12 @@ import android.hardware.input.InputSettings;
|
|||||||
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.widget.RadioGroup;
|
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
import androidx.fragment.app.FragmentTransaction;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settings.keyboard.Flags;
|
import com.android.settings.keyboard.Flags;
|
||||||
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
|
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
|
||||||
@@ -45,10 +48,13 @@ import org.mockito.junit.MockitoRule;
|
|||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
import org.robolectric.shadows.ShadowLooper;
|
import org.robolectric.annotation.Implementation;
|
||||||
|
import org.robolectric.annotation.Implements;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@Config(shadows = {
|
@Config(shadows = {
|
||||||
|
KeyboardAccessibilitySlowKeysControllerTest
|
||||||
|
.ShadowKeyboardAccessibilitySlowKeysDialogFragment.class,
|
||||||
com.android.settings.testutils.shadow.ShadowFragment.class,
|
com.android.settings.testutils.shadow.ShadowFragment.class,
|
||||||
ShadowAlertDialogCompat.class,
|
ShadowAlertDialogCompat.class,
|
||||||
})
|
})
|
||||||
@@ -60,6 +66,15 @@ public class KeyboardAccessibilitySlowKeysControllerTest {
|
|||||||
private static final String PREFERENCE_KEY = "keyboard_a11y_page_slow_keys";
|
private static final String PREFERENCE_KEY = "keyboard_a11y_page_slow_keys";
|
||||||
@Mock
|
@Mock
|
||||||
private Preference mPreference;
|
private Preference mPreference;
|
||||||
|
@Mock
|
||||||
|
private Fragment mFragment;
|
||||||
|
@Mock
|
||||||
|
private FragmentManager mFragmentManager;
|
||||||
|
@Mock
|
||||||
|
private FragmentTransaction mFragmentTransaction;
|
||||||
|
@Mock
|
||||||
|
private KeyboardAccessibilitySlowKeysDialogFragment
|
||||||
|
mKeyboardAccessibilitySlowKeysDialogFragment;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private KeyboardAccessibilitySlowKeysController mKeyboardAccessibilitySlowKeysController;
|
private KeyboardAccessibilitySlowKeysController mKeyboardAccessibilitySlowKeysController;
|
||||||
|
|
||||||
@@ -71,6 +86,11 @@ public class KeyboardAccessibilitySlowKeysControllerTest {
|
|||||||
mContext,
|
mContext,
|
||||||
PREFERENCE_KEY);
|
PREFERENCE_KEY);
|
||||||
when(mPreference.getKey()).thenReturn(PREFERENCE_KEY);
|
when(mPreference.getKey()).thenReturn(PREFERENCE_KEY);
|
||||||
|
when(mFragment.getParentFragmentManager()).thenReturn(mFragmentManager);
|
||||||
|
when(mFragmentManager.beginTransaction()).thenReturn(mFragmentTransaction);
|
||||||
|
mKeyboardAccessibilitySlowKeysController.setFragment(mFragment);
|
||||||
|
ShadowKeyboardAccessibilitySlowKeysDialogFragment.setInstance(
|
||||||
|
mKeyboardAccessibilitySlowKeysDialogFragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -107,23 +127,25 @@ public class KeyboardAccessibilitySlowKeysControllerTest {
|
|||||||
public void handlePreferenceTreeClick_dialogShows() {
|
public void handlePreferenceTreeClick_dialogShows() {
|
||||||
mKeyboardAccessibilitySlowKeysController.handlePreferenceTreeClick(mPreference);
|
mKeyboardAccessibilitySlowKeysController.handlePreferenceTreeClick(mPreference);
|
||||||
|
|
||||||
AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
verify(mKeyboardAccessibilitySlowKeysDialogFragment).show(any(FragmentManager.class),
|
||||||
|
anyString());
|
||||||
assertThat(alertDialog.isShowing()).isTrue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
/**
|
||||||
public void handlePreferenceTreeClick_performClickOn200_updatesSlowKeysThreshold() {
|
* Note: Actually, shadow of KeyboardAccessibilitySlowKeysDialogFragment will not be used.
|
||||||
mKeyboardAccessibilitySlowKeysController.handlePreferenceTreeClick(mPreference);
|
* Instance that returned with {@link #getInstance} should be set with {@link #setInstance}
|
||||||
AlertDialog alertDialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
*/
|
||||||
RadioGroup radioGroup = alertDialog.findViewById(R.id.input_setting_keys_value_group);
|
@Implements(KeyboardAccessibilitySlowKeysDialogFragment.class)
|
||||||
radioGroup.check(R.id.input_setting_keys_value_200);
|
public static class ShadowKeyboardAccessibilitySlowKeysDialogFragment {
|
||||||
|
static KeyboardAccessibilitySlowKeysDialogFragment sInstance = null;
|
||||||
|
|
||||||
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).performClick();
|
@Implementation
|
||||||
ShadowLooper.idleMainLooper();
|
protected static KeyboardAccessibilitySlowKeysDialogFragment getInstance() {
|
||||||
|
return sInstance;
|
||||||
|
}
|
||||||
|
|
||||||
assertThat(alertDialog.isShowing()).isFalse();
|
public static void setInstance(KeyboardAccessibilitySlowKeysDialogFragment instance) {
|
||||||
int threshold = InputSettings.getAccessibilitySlowKeysThreshold(mContext);
|
sInstance = instance;
|
||||||
assertThat(threshold).isEqualTo(200);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2025 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.inputmethod;
|
||||||
|
|
||||||
|
import static com.android.settings.inputmethod.KeyboardAccessibilityKeysDialogFragment.EXTRA_SUBTITLE_RES;
|
||||||
|
import static com.android.settings.inputmethod.KeyboardAccessibilityKeysDialogFragment.EXTRA_TITLE_RES;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.hardware.input.InputSettings;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.widget.RadioGroup;
|
||||||
|
|
||||||
|
import androidx.fragment.app.testing.FragmentScenario;
|
||||||
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.shadows.ShadowLooper;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
public class KeyboardAccessibilitySlowKeysDialogFragmentTest {
|
||||||
|
private AlertDialog mAlertDialog;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putInt(EXTRA_TITLE_RES, R.string.slow_keys);
|
||||||
|
bundle.putInt(EXTRA_SUBTITLE_RES, R.string.slow_keys_summary);
|
||||||
|
|
||||||
|
FragmentScenario<KeyboardAccessibilitySlowKeysDialogFragment> mFragmentScenario =
|
||||||
|
FragmentScenario.launch(
|
||||||
|
KeyboardAccessibilitySlowKeysDialogFragment.class,
|
||||||
|
bundle,
|
||||||
|
R.style.Theme_AlertDialog_SettingsLib,
|
||||||
|
Lifecycle.State.INITIALIZED);
|
||||||
|
mFragmentScenario.moveToState(Lifecycle.State.RESUMED);
|
||||||
|
|
||||||
|
mFragmentScenario.onFragment(fragment -> {
|
||||||
|
assertThat(fragment.getDialog()).isNotNull();
|
||||||
|
assertThat(fragment.requireDialog().isShowing()).isTrue();
|
||||||
|
assertThat(fragment.requireDialog()).isInstanceOf(AlertDialog.class);
|
||||||
|
mAlertDialog = (AlertDialog) fragment.requireDialog();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void handlePreferenceTreeClick_performClickOn200_updatesSlowKeysThreshold() {
|
||||||
|
assertThat(mAlertDialog.isShowing()).isTrue();
|
||||||
|
RadioGroup radioGroup = mAlertDialog.findViewById(R.id.input_setting_keys_value_group);
|
||||||
|
radioGroup.check(R.id.input_setting_keys_value_200);
|
||||||
|
|
||||||
|
mAlertDialog.getButton(AlertDialog.BUTTON_POSITIVE).performClick();
|
||||||
|
ShadowLooper.idleMainLooper();
|
||||||
|
|
||||||
|
assertThat(mAlertDialog.isShowing()).isFalse();
|
||||||
|
int threshold = InputSettings.getAccessibilitySlowKeysThreshold(
|
||||||
|
ApplicationProvider.getApplicationContext());
|
||||||
|
assertThat(threshold).isEqualTo(200);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user