1 /* 2 * Copyright (C) 2019 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.accessibility; 18 19 import android.content.ContentResolver; 20 import android.content.Context; 21 import android.content.res.Resources; 22 23 import com.android.settings.R; 24 import com.android.settings.core.BasePreferenceController; 25 26 import com.google.common.primitives.Ints; 27 28 /** Preference controller for accessibility timeout. */ 29 public class AccessibilityTimeoutPreferenceController extends BasePreferenceController { 30 31 private final ContentResolver mContentResolver; 32 private final Resources mResources; 33 AccessibilityTimeoutPreferenceController(Context context, String preferenceKey)34 public AccessibilityTimeoutPreferenceController(Context context, String preferenceKey) { 35 super(context, preferenceKey); 36 mContentResolver = mContext.getContentResolver(); 37 mResources = mContext.getResources(); 38 } 39 40 @Override getAvailabilityStatus()41 public int getAvailabilityStatus() { 42 return AVAILABLE; 43 } 44 45 @Override getSummary()46 public CharSequence getSummary() { 47 final String[] timeoutSummaries = mResources.getStringArray( 48 R.array.accessibility_timeout_summaries); 49 final int[] timeoutValues = mResources.getIntArray( 50 R.array.accessibility_timeout_selector_values); 51 final int timeoutValue = AccessibilityTimeoutUtils.getSecureAccessibilityTimeoutValue( 52 mContentResolver); 53 final int idx = Ints.indexOf(timeoutValues, timeoutValue); 54 return timeoutSummaries[idx == -1 ? 0 : idx]; 55 } 56 } 57