• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 static com.android.internal.accessibility.common.ShortcutConstants.UserShortcutType.SOFTWARE;
20 
21 import android.content.Context;
22 import android.content.res.Resources;
23 import android.view.accessibility.AccessibilityManager;
24 
25 import androidx.annotation.NonNull;
26 import androidx.preference.Preference;
27 import androidx.preference.PreferenceScreen;
28 
29 import com.android.settings.R;
30 import com.android.settings.core.BasePreferenceController;
31 import com.android.settingslib.search.SearchIndexableRaw;
32 
33 import java.util.List;
34 import java.util.Locale;
35 
36 /**
37  * Preference controller for accessibility button preference.
38  */
39 public class AccessibilityButtonPreferenceController extends BasePreferenceController {
AccessibilityButtonPreferenceController(Context context, String key)40     public AccessibilityButtonPreferenceController(Context context, String key) {
41         super(context, key);
42     }
43 
44     @Override
getAvailabilityStatus()45     public int getAvailabilityStatus() {
46         if (!com.android.settings.accessibility.Flags.fixA11ySettingsSearch()) {
47             return AVAILABLE;
48         } else {
49             if (mContext.getSystemService(AccessibilityManager.class)
50                     .getAccessibilityShortcutTargets(SOFTWARE).isEmpty()) {
51                 return DISABLED_DEPENDENT_SETTING;
52             } else {
53                 return AVAILABLE;
54             }
55         }
56     }
57 
58     @Override
updateState(@onNull Preference preference)59     public void updateState(@NonNull Preference preference) {
60         super.updateState(preference);
61         refreshSummary(preference);
62     }
63 
64     @Override
getSummary()65     public @NonNull CharSequence getSummary() {
66         if (getAvailabilityStatus() == AVAILABLE) {
67             return "";
68         } else {
69             return mContext.getString(
70                     R.string.accessibility_shortcut_unassigned_setting_unavailable_summary,
71                     AccessibilityUtil.getShortcutSummaryList(mContext, SOFTWARE)
72                             .toString().toLowerCase(Locale.getDefault()));
73         }
74     }
75 
76     @Override
displayPreference(PreferenceScreen screen)77     public void displayPreference(PreferenceScreen screen) {
78         super.displayPreference(screen);
79         final Preference preference = screen.findPreference(getPreferenceKey());
80         preference.setTitle(getPreferenceTitleResource());
81     }
82 
83     @Override
updateDynamicRawDataToIndex(List<SearchIndexableRaw> rawData)84     public void updateDynamicRawDataToIndex(List<SearchIndexableRaw> rawData) {
85         SearchIndexableRaw data = new SearchIndexableRaw(mContext);
86         data.key = getPreferenceKey();
87         final Resources res = mContext.getResources();
88         data.title = res.getString(getPreferenceTitleResource());
89         data.screenTitle = res.getString(R.string.accessibility_shortcuts_settings_title);
90         rawData.add(data);
91     }
92 
getPreferenceTitleResource()93     private int getPreferenceTitleResource() {
94         if (android.provider.Flags.a11yStandaloneGestureEnabled()) {
95             return R.string.accessibility_button_title;
96         } else {
97             return AccessibilityUtil.isGestureNavigateEnabled(mContext)
98                     ? R.string.accessibility_button_gesture_title
99                     : R.string.accessibility_button_title;
100         }
101     }
102 }
103