blob: 33fef62f2052588fba635eebc30c942a8c2ed9d5 [file] [log] [blame]
jasonwshsu1cc2ccc2022-12-06 00:48:18 +08001/*
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
17package com.android.settings.accessibility;
18
19import static android.os.UserManager.DISALLOW_CONFIG_BLUETOOTH;
20
jasonwshsu6a2db7e2023-03-12 20:20:31 +080021import android.app.settings.SettingsEnums;
jasonwshsuad6351d2022-12-09 02:12:56 +080022import android.content.ComponentName;
jasonwshsuc1fb0ae2022-12-30 03:11:48 +080023import android.content.Context;
jasonwshsu1cc2ccc2022-12-06 00:48:18 +080024import android.os.Bundle;
25import android.view.LayoutInflater;
26import android.view.View;
27import android.view.ViewGroup;
28
jasonwshsuad6351d2022-12-09 02:12:56 +080029import androidx.preference.PreferenceCategory;
30
31import com.android.internal.accessibility.AccessibilityShortcutController;
jasonwshsu1cc2ccc2022-12-06 00:48:18 +080032import com.android.settings.R;
jasonwshsu1cc2ccc2022-12-06 00:48:18 +080033import com.android.settings.search.BaseSearchIndexProvider;
34import com.android.settingslib.search.SearchIndexable;
35
36/** Accessibility settings for hearing aids. */
37@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
jasonwshsuad6351d2022-12-09 02:12:56 +080038public class AccessibilityHearingAidsFragment extends AccessibilityShortcutPreferenceFragment {
jasonwshsu1cc2ccc2022-12-06 00:48:18 +080039
40 private static final String TAG = "AccessibilityHearingAidsFragment";
jasonwshsu1b0a4542023-03-13 17:07:52 +080041 private static final String KEY_HEARING_OPTIONS_CATEGORY = "hearing_options_category";
jasonwshsu212470d2023-05-11 20:25:10 +080042 private static final int SHORTCUT_PREFERENCE_IN_CATEGORY_INDEX = 20;
jasonwshsuad6351d2022-12-09 02:12:56 +080043 private String mFeatureName;
jasonwshsu1cc2ccc2022-12-06 00:48:18 +080044
45 public AccessibilityHearingAidsFragment() {
46 super(DISALLOW_CONFIG_BLUETOOTH);
47 }
48
49 @Override
jasonwshsuc1fb0ae2022-12-30 03:11:48 +080050 public void onAttach(Context context) {
51 super.onAttach(context);
jasonwshsu23417c32023-01-04 21:38:01 +080052 use(AvailableHearingDevicePreferenceController.class).init(this);
jasonwshsuc1fb0ae2022-12-30 03:11:48 +080053 use(SavedHearingDevicePreferenceController.class).init(this);
54 }
55
56 @Override
jasonwshsuad6351d2022-12-09 02:12:56 +080057 public void onCreate(Bundle savedInstanceState) {
58 mFeatureName = getContext().getString(R.string.accessibility_hearingaid_title);
59 super.onCreate(savedInstanceState);
60 }
61
62 @Override
jasonwshsu1cc2ccc2022-12-06 00:48:18 +080063 public View onCreateView(LayoutInflater inflater, ViewGroup container,
64 Bundle savedInstanceState) {
jasonwshsuad6351d2022-12-09 02:12:56 +080065 final View view = super.onCreateView(inflater, container, savedInstanceState);
jasonwshsu1b0a4542023-03-13 17:07:52 +080066 final PreferenceCategory controlCategory = findPreference(KEY_HEARING_OPTIONS_CATEGORY);
67 // To move the shortcut preference under controlCategory need to remove the original added.
jasonwshsu212470d2023-05-11 20:25:10 +080068 mShortcutPreference.setOrder(SHORTCUT_PREFERENCE_IN_CATEGORY_INDEX);
jasonwshsuad6351d2022-12-09 02:12:56 +080069 getPreferenceScreen().removePreference(mShortcutPreference);
70 controlCategory.addPreference(mShortcutPreference);
71 return view;
jasonwshsu1cc2ccc2022-12-06 00:48:18 +080072 }
73
74 @Override
75 public int getMetricsCategory() {
jasonwshsu6a2db7e2023-03-12 20:20:31 +080076 return SettingsEnums.ACCESSIBILITY_HEARING_AID_SETTINGS;
jasonwshsu1cc2ccc2022-12-06 00:48:18 +080077 }
78
79 @Override
80 protected int getPreferenceScreenResId() {
81 return R.xml.accessibility_hearing_aids;
82 }
83
84 @Override
85 protected String getLogTag() {
86 return TAG;
87 }
88
jasonwshsuad6351d2022-12-09 02:12:56 +080089 @Override
90 protected ComponentName getComponentName() {
91 return AccessibilityShortcutController.ACCESSIBILITY_HEARING_AIDS_COMPONENT_NAME;
92 }
93
94 @Override
95 protected CharSequence getLabelName() {
96 return mFeatureName;
97 }
98
99 @Override
100 protected ComponentName getTileComponentName() {
101 // Don't have quick settings tile for now.
102 return null;
103 }
104
105 @Override
106 protected CharSequence getTileTooltipContent(int type) {
107 // Don't have quick settings tile for now.
108 return null;
109 }
110
111 @Override
112 protected boolean showGeneralCategory() {
jasonwshsu1b0a4542023-03-13 17:07:52 +0800113 // Have static preference under dynamically created PreferenceCategory KEY_GENERAL_CATEGORY.
114 // In order to modify that, we need to use our own PreferenceCategory for this page.
jasonwshsuad6351d2022-12-09 02:12:56 +0800115 return false;
116 }
117
118 @Override
119 protected CharSequence getShortcutTitle() {
120 return getText(R.string.accessibility_hearing_device_shortcut_title);
121 }
122
jasonwshsu1cc2ccc2022-12-06 00:48:18 +0800123 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
124 new BaseSearchIndexProvider(R.xml.accessibility_hearing_aids);
125}