Files
app_Settings/src/com/android/settings/inputmethod/KeyboardAccessibilityBounceKeysController.java
shaoweishen 120b2d46f7 [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
2025-02-03 09:32:02 +00:00

105 lines
3.5 KiB
Java

/*
* Copyright 2024 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_DISABLED;
import static android.app.settings.SettingsEnums.ACTION_BOUNCE_KEYS_ENABLED;
import android.content.Context;
import android.hardware.input.InputSettings;
import android.net.Uri;
import android.provider.Settings;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.LifecycleObserver;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settingslib.PrimarySwitchPreference;
public class KeyboardAccessibilityBounceKeysController extends
InputSettingPreferenceController implements
LifecycleObserver {
public static final int BOUNCE_KEYS_THRESHOLD = 500;
private static final String KEY_TAG = "bounce_keys_dialog_tag";
@Nullable
private PrimarySwitchPreference mPrimaryPreference;
public KeyboardAccessibilityBounceKeysController(@NonNull Context context,
@NonNull String key) {
super(context, key);
}
@Override
public void displayPreference(@NonNull PreferenceScreen screen) {
super.displayPreference(screen);
mPrimaryPreference = screen.findPreference(getPreferenceKey());
}
@Override
public int getAvailabilityStatus() {
return (super.getAvailabilityStatus() == AVAILABLE)
&& InputSettings.isAccessibilityBounceKeysFeatureEnabled() ? AVAILABLE
: UNSUPPORTED_ON_DEVICE;
}
@Override
public boolean handlePreferenceTreeClick(@NonNull Preference preference) {
if (!TextUtils.equals(preference.getKey(), getPreferenceKey())
|| mFragmentManager == null) {
return false;
}
KeyboardAccessibilityBounceKeysDialogFragment.getInstance().show(mFragmentManager, KEY_TAG);
return true;
}
@Override
public boolean isChecked() {
return InputSettings.isAccessibilityBounceKeysEnabled(mContext);
}
@Override
public boolean setChecked(boolean isChecked) {
updateInputSettingKeysValue(isChecked ? BOUNCE_KEYS_THRESHOLD : 0);
mMetricsFeatureProvider.action(mContext,
isChecked ? ACTION_BOUNCE_KEYS_ENABLED : ACTION_BOUNCE_KEYS_DISABLED);
return true;
}
@Override
protected void onInputSettingUpdated() {
if (mPrimaryPreference != null) {
mPrimaryPreference.setChecked(
InputSettings.isAccessibilityBounceKeysEnabled(mContext));
}
}
@Override
protected Uri getSettingUri() {
return Settings.Secure.getUriFor(
Settings.Secure.ACCESSIBILITY_BOUNCE_KEYS);
}
@Override
protected void updateInputSettingKeysValue(int thresholdTimeMillis) {
InputSettings.setAccessibilityBounceKeysThreshold(mContext, thresholdTimeMillis);
}
}