• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.inputmethod;
18 
19 import android.content.Context;
20 import android.hardware.input.InputSettings;
21 
22 import androidx.annotation.NonNull;
23 
24 import com.android.internal.annotations.VisibleForTesting;
25 import com.android.settings.core.SliderPreferenceController;
26 
27 import com.google.common.collect.ImmutableList;
28 
29 public class KeyboardRepeatKeysTimeOutPreferenceController extends SliderPreferenceController {
30     @VisibleForTesting
31     static final ImmutableList<Integer> REPEAT_KEY_TIMEOUT_VALUE_LIST = ImmutableList.of(2000, 1500,
32             1000, 400, 300, 200, 150);
33 
KeyboardRepeatKeysTimeOutPreferenceController( @onNull Context context, @NonNull String preferenceKey)34     public KeyboardRepeatKeysTimeOutPreferenceController(
35             @NonNull Context context,
36             @NonNull String preferenceKey) {
37         super(context, preferenceKey);
38     }
39 
40     @Override
getSliderPosition()41     public int getSliderPosition() {
42         return REPEAT_KEY_TIMEOUT_VALUE_LIST.indexOf(InputSettings.getRepeatKeysTimeout(mContext));
43     }
44 
45     @Override
setSliderPosition(int position)46     public boolean setSliderPosition(int position) {
47         InputSettings.setRepeatKeysTimeout(mContext, REPEAT_KEY_TIMEOUT_VALUE_LIST.get(position));
48         return true;
49     }
50 
51     @Override
getMax()52     public int getMax() {
53         return REPEAT_KEY_TIMEOUT_VALUE_LIST.size() - 1;
54     }
55 
56     @Override
getMin()57     public int getMin() {
58         return 0;
59     }
60 
61     @Override
getAvailabilityStatus()62     public int getAvailabilityStatus() {
63         return InputSettings.isRepeatKeysFeatureFlagEnabled()
64                 ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
65     }
66 }
67