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 KeyboardRepeatKeysDelayPreferenceController extends SliderPreferenceController { 30 @VisibleForTesting 31 static final ImmutableList<Integer> REPEAT_KEY_DELAY_VALUE_LIST = ImmutableList.of(2000, 1000, 32 500, 300, 200, 100, 50, 30, 20); 33 KeyboardRepeatKeysDelayPreferenceController(@onNull Context context, @NonNull String preferenceKey)34 public KeyboardRepeatKeysDelayPreferenceController(@NonNull Context context, 35 @NonNull String preferenceKey) { 36 super(context, preferenceKey); 37 } 38 39 @Override getSliderPosition()40 public int getSliderPosition() { 41 return REPEAT_KEY_DELAY_VALUE_LIST.indexOf(InputSettings.getRepeatKeysDelay(mContext)); 42 } 43 44 @Override setSliderPosition(int position)45 public boolean setSliderPosition(int position) { 46 InputSettings.setRepeatKeysDelay(mContext, REPEAT_KEY_DELAY_VALUE_LIST.get(position)); 47 return true; 48 } 49 50 @Override getMax()51 public int getMax() { 52 return REPEAT_KEY_DELAY_VALUE_LIST.size() - 1; 53 } 54 55 @Override getMin()56 public int getMin() { 57 return 0; 58 } 59 60 @Override getAvailabilityStatus()61 public int getAvailabilityStatus() { 62 return InputSettings.isRepeatKeysFeatureFlagEnabled() 63 ? AVAILABLE : UNSUPPORTED_ON_DEVICE; 64 } 65 } 66