• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
20 
21 import android.app.settings.SettingsEnums;
22 import android.content.ComponentName;
23 import android.content.Context;
24 import android.os.Bundle;
25 import android.view.LayoutInflater;
26 import android.view.View;
27 import android.view.ViewGroup;
28 
29 import androidx.annotation.VisibleForTesting;
30 import androidx.preference.PreferenceCategory;
31 
32 import com.android.internal.accessibility.AccessibilityShortcutController;
33 import com.android.settings.R;
34 import com.android.settings.search.BaseSearchIndexProvider;
35 import com.android.settingslib.search.SearchIndexable;
36 
37 /** Accessibility settings for hearing aids. */
38 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
39 public class AccessibilityHearingAidsFragment extends AccessibilityShortcutPreferenceFragment {
40     private static final String TAG = "AccessibilityHearingAidsFragment";
41     private static final String KEY_HEARING_OPTIONS_CATEGORY = "hearing_options_category";
42     private static final int SHORTCUT_PREFERENCE_IN_CATEGORY_INDEX = 20;
43     private String mFeatureName;
44 
AccessibilityHearingAidsFragment()45     public AccessibilityHearingAidsFragment() {
46         super(DISALLOW_CONFIG_BLUETOOTH);
47     }
48 
49     @Override
onAttach(Context context)50     public void onAttach(Context context) {
51         super.onAttach(context);
52         use(AvailableHearingDevicePreferenceController.class).init(this);
53         use(SavedHearingDevicePreferenceController.class).init(this);
54     }
55 
56     @Override
onCreate(Bundle savedInstanceState)57     public void onCreate(Bundle savedInstanceState) {
58         mFeatureName = getContext().getString(R.string.accessibility_hearingaid_title);
59         super.onCreate(savedInstanceState);
60     }
61 
62     @Override
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)63     public View onCreateView(LayoutInflater inflater, ViewGroup container,
64             Bundle savedInstanceState) {
65         final View view = super.onCreateView(inflater, container, savedInstanceState);
66         final PreferenceCategory controlCategory = findPreference(KEY_HEARING_OPTIONS_CATEGORY);
67         // To move the shortcut preference under controlCategory need to remove the original added.
68         mShortcutPreference.setOrder(SHORTCUT_PREFERENCE_IN_CATEGORY_INDEX);
69         getPreferenceScreen().removePreference(mShortcutPreference);
70         controlCategory.addPreference(mShortcutPreference);
71         return view;
72     }
73 
74     @Override
getMetricsCategory()75     public int getMetricsCategory() {
76         return SettingsEnums.ACCESSIBILITY_HEARING_AID_SETTINGS;
77     }
78 
79     @Override
getPreferenceScreenResId()80     protected int getPreferenceScreenResId() {
81         return R.xml.accessibility_hearing_aids;
82     }
83 
84     @Override
getLogTag()85     protected String getLogTag() {
86         return TAG;
87     }
88 
89     @Override
getComponentName()90     protected ComponentName getComponentName() {
91         return AccessibilityShortcutController.ACCESSIBILITY_HEARING_AIDS_COMPONENT_NAME;
92     }
93 
94     @Override
getLabelName()95     protected CharSequence getLabelName() {
96         return mFeatureName;
97     }
98 
99     @Override
showGeneralCategory()100     protected boolean showGeneralCategory() {
101         // Have static preference under dynamically created PreferenceCategory KEY_GENERAL_CATEGORY.
102         // In order to modify that, we need to use our own PreferenceCategory for this page.
103         return false;
104     }
105 
106     @Override
getShortcutTitle()107     protected CharSequence getShortcutTitle() {
108         return getText(R.string.accessibility_hearing_device_shortcut_title);
109     }
110 
111     @VisibleForTesting
isPageSearchEnabled(Context context)112     static boolean isPageSearchEnabled(Context context) {
113         final HearingAidHelper mHelper = new HearingAidHelper(context);
114         return mHelper.isHearingAidSupported();
115     }
116 
117     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
118             new BaseSearchIndexProvider(R.xml.accessibility_hearing_aids) {
119                 @Override
120                 protected boolean isPageSearchEnabled(Context context) {
121                     if (Flags.fixA11ySettingsSearch()) {
122                         return AccessibilityHearingAidsFragment.isPageSearchEnabled(context);
123                     } else {
124                         return super.isPageSearchEnabled(context);
125                     }
126                 }
127             };
128 }
129