| /* | |
| * Copyright (C) 2026 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.Manifest.permission.WRITE_SECURE_SETTINGS | |
| import android.hardware.input.InputSettings | |
| import com.android.settings.R | |
| import com.android.settings.flags.Flags as SettingsFlags | |
| import com.android.settingslib.metadata.IntroducedVersion.API_CINNAMON_BUN | |
| import com.android.settingslib.metadata.ProvidePreferenceScreen | |
| import com.android.settingslib.metadata.SensitivityLevel | |
| import com.android.settingslib.metadata.preferencesapi.PreferencesApiScreen | |
| import com.android.settingslib.metadata.preferencesapi.Stability | |
| import com.android.settingslib.metadata.preferencesapi.category.Category | |
| import com.android.settingslib.metadata.preferencesapi.preconditions.Allowed | |
| import com.android.settingslib.metadata.preferencesapi.preconditions.Custom | |
| import com.android.settingslib.metadata.preferencesapi.types.AnyBoolean | |
| import com.android.settingslib.metadata.preferencesapi.types.IntInRange | |
| // LINT.IfChange | |
| @ProvidePreferenceScreen(KeyboardRepeatKeysApiScreen.KEY) | |
| class KeyboardRepeatKeysApiScreen : | |
| PreferencesApiScreen( | |
| key = KEY, | |
| topLevelSettingsCategory = Category.SYSTEM, | |
| fragment = KeyboardRepeatKeysMainFragment::class, | |
| purpose = R.string.keyboard_repeat_keys_screen_purpose, | |
| ) { | |
| init { | |
| flag { SettingsFlags.catalystMigration26q3() } | |
| // TODO(b/464955993): Extract precondition into a first-class precondition and use here and | |
| // in screens with the same physical keyboard requirement. | |
| precondition(R.string.keyboard_repeat_keys_precondition) { | |
| if (PhysicalKeyboardFragment.getHardKeyboards(context).isNotEmpty()) { | |
| Allowed | |
| } else { | |
| Custom(R.string.keyboard_repeat_keys_unsupported, Stability.UNSTABLE) | |
| } | |
| } | |
| // Repeat Keys (Toggle) | |
| preference( | |
| key = KEY_REPEAT_KEYS_MAIN_SWITCH, | |
| type = AnyBoolean, | |
| purpose = R.string.keyboard_repeat_keys_toggle_purpose, | |
| introducedVersion = API_CINNAMON_BUN, | |
| ) { | |
| sensitivityLevel(SensitivityLevel.NO_SENSITIVITY) | |
| get { execute { InputSettings.isRepeatKeysEnabled(context) } } | |
| set { | |
| permissions(WRITE_SECURE_SETTINGS) | |
| execute { value -> InputSettings.setRepeatKeysEnabled(context, value) } | |
| } | |
| } | |
| // Delay before repeat (Slider) | |
| preference( | |
| key = KEY_REPEAT_KEYS_TIMEOUT_PREFERENCE, | |
| type = | |
| IntInRange( | |
| 0, | |
| KeyboardRepeatKeysTimeOutPreferenceController.REPEAT_KEY_TIMEOUT_VALUE_LIST | |
| .size - 1, | |
| ), | |
| purpose = R.string.keyboard_repeat_keys_timeout_purpose, | |
| introducedVersion = API_CINNAMON_BUN, | |
| ) { | |
| sensitivityLevel(SensitivityLevel.NO_SENSITIVITY) | |
| get { | |
| execute { | |
| KeyboardRepeatKeysTimeOutPreferenceController.REPEAT_KEY_TIMEOUT_VALUE_LIST | |
| .indexOf(InputSettings.getRepeatKeysTimeout(context)) | |
| .coerceAtLeast(0) | |
| } | |
| } | |
| set { | |
| permissions(WRITE_SECURE_SETTINGS) | |
| execute { value -> | |
| InputSettings.setRepeatKeysTimeout( | |
| context, | |
| KeyboardRepeatKeysTimeOutPreferenceController.REPEAT_KEY_TIMEOUT_VALUE_LIST[ | |
| value], | |
| ) | |
| } | |
| } | |
| } | |
| // Repeat rate (Slider) | |
| preference( | |
| key = KEY_REPEAT_KEYS_DELAY_PREFERENCE, | |
| type = | |
| IntInRange( | |
| 0, | |
| KeyboardRepeatKeysDelayPreferenceController.REPEAT_KEY_DELAY_VALUE_LIST.size - 1, | |
| ), | |
| purpose = R.string.keyboard_repeat_keys_delay_purpose, | |
| introducedVersion = API_CINNAMON_BUN, | |
| ) { | |
| sensitivityLevel(SensitivityLevel.NO_SENSITIVITY) | |
| get { | |
| execute { | |
| KeyboardRepeatKeysDelayPreferenceController.REPEAT_KEY_DELAY_VALUE_LIST.indexOf( | |
| InputSettings.getRepeatKeysDelay(context) | |
| ) | |
| .coerceAtLeast(0) | |
| } | |
| } | |
| set { | |
| permissions(WRITE_SECURE_SETTINGS) | |
| execute { value -> | |
| InputSettings.setRepeatKeysDelay( | |
| context, | |
| KeyboardRepeatKeysDelayPreferenceController.REPEAT_KEY_DELAY_VALUE_LIST[ | |
| value], | |
| ) | |
| } | |
| } | |
| } | |
| } | |
| companion object { | |
| const val KEY = "repeat_keys_main_page" | |
| const val KEY_REPEAT_KEYS_MAIN_SWITCH = "prf_repeat_keys_enabled" | |
| const val KEY_REPEAT_KEYS_TIMEOUT_PREFERENCE = "prf_repeat_keys_timeout" | |
| const val KEY_REPEAT_KEYS_DELAY_PREFERENCE = "prf_repeat_keys_delay" | |
| } | |
| } | |
| // LINT.ThenChange(KeyboardRepeatKeysMainFragment.java) |