[Physical Keyboard] Add Repeat key toggle

Add repeat key toggle under Physical keybaord setting.

Bug: 345399212
Test: atest SettingsRoboTests
Flag: com.android.input.flags.keyboard_repeat_keys
Change-Id: Ib986301d108b1ad30d96d7309189e9507d38c25a
This commit is contained in:
shaoweishen
2024-10-06 09:28:59 +00:00
parent 899a6d8f75
commit cffb21b17f
5 changed files with 186 additions and 2 deletions

View File

@@ -0,0 +1,76 @@
/*
* 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 android.content.Context;
import android.hardware.input.InputSettings;
import android.net.Uri;
import android.provider.Settings;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.LifecycleObserver;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreferenceCompat;
public class KeyboardRepeatKeysController extends
InputSettingPreferenceController implements
LifecycleObserver {
@Nullable
private SwitchPreferenceCompat mSwitchPreferenceCompat;
public KeyboardRepeatKeysController(@NonNull Context context,
@NonNull String key) {
super(context, key);
}
@Override
public void displayPreference(@NonNull PreferenceScreen screen) {
super.displayPreference(screen);
mSwitchPreferenceCompat = screen.findPreference(getPreferenceKey());
}
@Override
public int getAvailabilityStatus() {
return InputSettings.isRepeatKeysFeatureFlagEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
@Override
public boolean isChecked() {
return InputSettings.isRepeatKeysEnabled(mContext);
}
@Override
public boolean setChecked(boolean isChecked) {
InputSettings.setRepeatKeysEnabled(mContext, isChecked);
return true;
}
@Override
protected void onInputSettingUpdated() {
if (mSwitchPreferenceCompat != null) {
mSwitchPreferenceCompat.setChecked(InputSettings.isRepeatKeysEnabled(mContext));
}
}
@Override
protected Uri getSettingUri() {
return Settings.Secure.getUriFor(
Settings.Secure.KEY_REPEAT_ENABLED);
}
}

View File

@@ -48,8 +48,8 @@ import androidx.preference.TwoStatePreference;
import com.android.internal.util.Preconditions;
import com.android.settings.R;
import com.android.settings.Settings;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.keyboard.Flags;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
@@ -65,7 +65,7 @@ import java.util.Objects;
// TODO(b/327638540): Update implementation of preference here and reuse key preferences and
// controllers between here and A11y Setting page.
@SearchIndexable
public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
public final class PhysicalKeyboardFragment extends DashboardFragment
implements InputManager.InputDeviceListener,
KeyboardLayoutDialogFragment.OnSetupKeyboardLayoutsListener {
@@ -79,6 +79,7 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
private static final String KEYBOARD_SHORTCUTS_HELPER = "keyboard_shortcuts_helper";
private static final String MODIFIER_KEYS_SETTINGS = "modifier_keys_settings";
private static final String EXTRA_AUTO_SELECTION = "auto_selection";
private static final String TAG = "KeyboardAndTouchA11yFragment";
private static final Uri sVirtualKeyboardSettingsUri = Secure.getUriFor(
Secure.SHOW_IME_WITH_HARD_KEYBOARD);
private static final Uri sAccessibilityBounceKeysUri = Secure.getUriFor(
@@ -118,6 +119,16 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
static final String EXTRA_BT_ADDRESS = "extra_bt_address";
private String mBluetoothAddress;
@Override
protected String getLogTag() {
return TAG;
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.physical_keyboard_settings;
}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putParcelable(EXTRA_AUTO_SELECTION, mAutoInputDeviceIdentifier);
@@ -126,6 +137,7 @@ public final class PhysicalKeyboardFragment extends SettingsPreferenceFragment
@Override
public void onCreatePreferences(Bundle bundle, String s) {
super.onCreatePreferences(bundle, s);
Activity activity = Preconditions.checkNotNull(getActivity());
addPreferencesFromResource(R.xml.physical_keyboard_settings);
mIm = Preconditions.checkNotNull(activity.getSystemService(InputManager.class));