1 /* 2 * Copyright (C) 2021 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.Context; 20 import android.content.res.Resources; 21 22 import androidx.preference.Preference; 23 import androidx.preference.PreferenceScreen; 24 25 import com.android.settings.R; 26 import com.android.settings.core.BasePreferenceController; 27 import com.android.settingslib.search.SearchIndexableRaw; 28 29 import java.util.List; 30 31 /** 32 * Preference controller for accessibility button preference. 33 */ 34 public class AccessibilityButtonPreferenceController extends BasePreferenceController { 35 AccessibilityButtonPreferenceController(Context context, String key)36 public AccessibilityButtonPreferenceController(Context context, String key) { 37 super(context, key); 38 } 39 40 @Override getAvailabilityStatus()41 public int getAvailabilityStatus() { 42 return AVAILABLE; 43 } 44 45 @Override displayPreference(PreferenceScreen screen)46 public void displayPreference(PreferenceScreen screen) { 47 super.displayPreference(screen); 48 final Preference preference = screen.findPreference(getPreferenceKey()); 49 preference.setTitle(getPreferenceTitleResource()); 50 51 } 52 53 @Override updateDynamicRawDataToIndex(List<SearchIndexableRaw> rawData)54 public void updateDynamicRawDataToIndex(List<SearchIndexableRaw> rawData) { 55 SearchIndexableRaw data = new SearchIndexableRaw(mContext); 56 data.key = getPreferenceKey(); 57 final Resources res = mContext.getResources(); 58 data.title = res.getString(getPreferenceTitleResource()); 59 data.screenTitle = res.getString(R.string.accessibility_shortcuts_settings_title); 60 rawData.add(data); 61 } 62 getPreferenceTitleResource()63 private int getPreferenceTitleResource() { 64 return AccessibilityUtil.isGestureNavigateEnabled(mContext) 65 ? R.string.accessibility_button_gesture_title : R.string.accessibility_button_title; 66 } 67 } 68