jasonwshsu | 1cc2ccc | 2022-12-06 00:48:18 +0800 | [diff] [blame] | 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 | |
jasonwshsu | 6a2db7e | 2023-03-12 20:20:31 +0800 | [diff] [blame] | 21 | import android.app.settings.SettingsEnums; |
jasonwshsu | ad6351d | 2022-12-09 02:12:56 +0800 | [diff] [blame] | 22 | import android.content.ComponentName; |
jasonwshsu | c1fb0ae | 2022-12-30 03:11:48 +0800 | [diff] [blame] | 23 | import android.content.Context; |
jasonwshsu | 1cc2ccc | 2022-12-06 00:48:18 +0800 | [diff] [blame] | 24 | import android.os.Bundle; |
| 25 | import android.view.LayoutInflater; |
| 26 | import android.view.View; |
| 27 | import android.view.ViewGroup; |
| 28 | |
jasonwshsu | ad6351d | 2022-12-09 02:12:56 +0800 | [diff] [blame] | 29 | import androidx.preference.PreferenceCategory; |
| 30 | |
| 31 | import com.android.internal.accessibility.AccessibilityShortcutController; |
jasonwshsu | 1cc2ccc | 2022-12-06 00:48:18 +0800 | [diff] [blame] | 32 | import com.android.settings.R; |
jasonwshsu | 1cc2ccc | 2022-12-06 00:48:18 +0800 | [diff] [blame] | 33 | import com.android.settings.search.BaseSearchIndexProvider; |
| 34 | import com.android.settingslib.search.SearchIndexable; |
| 35 | |
| 36 | /** Accessibility settings for hearing aids. */ |
| 37 | @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC) |
jasonwshsu | ad6351d | 2022-12-09 02:12:56 +0800 | [diff] [blame] | 38 | public class AccessibilityHearingAidsFragment extends AccessibilityShortcutPreferenceFragment { |
jasonwshsu | 1cc2ccc | 2022-12-06 00:48:18 +0800 | [diff] [blame] | 39 | |
| 40 | private static final String TAG = "AccessibilityHearingAidsFragment"; |
jasonwshsu | 1b0a454 | 2023-03-13 17:07:52 +0800 | [diff] [blame] | 41 | private static final String KEY_HEARING_OPTIONS_CATEGORY = "hearing_options_category"; |
jasonwshsu | 212470d | 2023-05-11 20:25:10 +0800 | [diff] [blame] | 42 | private static final int SHORTCUT_PREFERENCE_IN_CATEGORY_INDEX = 20; |
jasonwshsu | ad6351d | 2022-12-09 02:12:56 +0800 | [diff] [blame] | 43 | private String mFeatureName; |
jasonwshsu | 1cc2ccc | 2022-12-06 00:48:18 +0800 | [diff] [blame] | 44 | |
| 45 | public AccessibilityHearingAidsFragment() { |
| 46 | super(DISALLOW_CONFIG_BLUETOOTH); |
| 47 | } |
| 48 | |
| 49 | @Override |
jasonwshsu | c1fb0ae | 2022-12-30 03:11:48 +0800 | [diff] [blame] | 50 | public void onAttach(Context context) { |
| 51 | super.onAttach(context); |
jasonwshsu | 23417c3 | 2023-01-04 21:38:01 +0800 | [diff] [blame] | 52 | use(AvailableHearingDevicePreferenceController.class).init(this); |
jasonwshsu | c1fb0ae | 2022-12-30 03:11:48 +0800 | [diff] [blame] | 53 | use(SavedHearingDevicePreferenceController.class).init(this); |
| 54 | } |
| 55 | |
| 56 | @Override |
jasonwshsu | ad6351d | 2022-12-09 02:12:56 +0800 | [diff] [blame] | 57 | public void onCreate(Bundle savedInstanceState) { |
| 58 | mFeatureName = getContext().getString(R.string.accessibility_hearingaid_title); |
| 59 | super.onCreate(savedInstanceState); |
| 60 | } |
| 61 | |
| 62 | @Override |
jasonwshsu | 1cc2ccc | 2022-12-06 00:48:18 +0800 | [diff] [blame] | 63 | public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 64 | Bundle savedInstanceState) { |
jasonwshsu | ad6351d | 2022-12-09 02:12:56 +0800 | [diff] [blame] | 65 | final View view = super.onCreateView(inflater, container, savedInstanceState); |
jasonwshsu | 1b0a454 | 2023-03-13 17:07:52 +0800 | [diff] [blame] | 66 | final PreferenceCategory controlCategory = findPreference(KEY_HEARING_OPTIONS_CATEGORY); |
| 67 | // To move the shortcut preference under controlCategory need to remove the original added. |
jasonwshsu | 212470d | 2023-05-11 20:25:10 +0800 | [diff] [blame] | 68 | mShortcutPreference.setOrder(SHORTCUT_PREFERENCE_IN_CATEGORY_INDEX); |
jasonwshsu | ad6351d | 2022-12-09 02:12:56 +0800 | [diff] [blame] | 69 | getPreferenceScreen().removePreference(mShortcutPreference); |
| 70 | controlCategory.addPreference(mShortcutPreference); |
| 71 | return view; |
jasonwshsu | 1cc2ccc | 2022-12-06 00:48:18 +0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public int getMetricsCategory() { |
jasonwshsu | 6a2db7e | 2023-03-12 20:20:31 +0800 | [diff] [blame] | 76 | return SettingsEnums.ACCESSIBILITY_HEARING_AID_SETTINGS; |
jasonwshsu | 1cc2ccc | 2022-12-06 00:48:18 +0800 | [diff] [blame] | 77 | } |
| 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 | |
jasonwshsu | ad6351d | 2022-12-09 02:12:56 +0800 | [diff] [blame] | 89 | @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() { |
jasonwshsu | 1b0a454 | 2023-03-13 17:07:52 +0800 | [diff] [blame] | 113 | // 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. |
jasonwshsu | ad6351d | 2022-12-09 02:12:56 +0800 | [diff] [blame] | 115 | return false; |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | protected CharSequence getShortcutTitle() { |
| 120 | return getText(R.string.accessibility_hearing_device_shortcut_title); |
| 121 | } |
| 122 | |
jasonwshsu | 1cc2ccc | 2022-12-06 00:48:18 +0800 | [diff] [blame] | 123 | public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = |
| 124 | new BaseSearchIndexProvider(R.xml.accessibility_hearing_aids); |
| 125 | } |