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.preference.PreferenceCategory; 30 31 import com.android.internal.accessibility.AccessibilityShortcutController; 32 import com.android.settings.R; 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) 38 public class AccessibilityHearingAidsFragment extends AccessibilityShortcutPreferenceFragment { 39 private static final String TAG = "AccessibilityHearingAidsFragment"; 40 private static final String KEY_HEARING_OPTIONS_CATEGORY = "hearing_options_category"; 41 private static final int SHORTCUT_PREFERENCE_IN_CATEGORY_INDEX = 20; 42 private String mFeatureName; 43 AccessibilityHearingAidsFragment()44 public AccessibilityHearingAidsFragment() { 45 super(DISALLOW_CONFIG_BLUETOOTH); 46 } 47 48 @Override onAttach(Context context)49 public void onAttach(Context context) { 50 super.onAttach(context); 51 use(AvailableHearingDevicePreferenceController.class).init(this); 52 use(SavedHearingDevicePreferenceController.class).init(this); 53 } 54 55 @Override onCreate(Bundle savedInstanceState)56 public void onCreate(Bundle savedInstanceState) { 57 mFeatureName = getContext().getString(R.string.accessibility_hearingaid_title); 58 super.onCreate(savedInstanceState); 59 } 60 61 @Override onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)62 public View onCreateView(LayoutInflater inflater, ViewGroup container, 63 Bundle savedInstanceState) { 64 final View view = super.onCreateView(inflater, container, savedInstanceState); 65 final PreferenceCategory controlCategory = findPreference(KEY_HEARING_OPTIONS_CATEGORY); 66 // To move the shortcut preference under controlCategory need to remove the original added. 67 mShortcutPreference.setOrder(SHORTCUT_PREFERENCE_IN_CATEGORY_INDEX); 68 getPreferenceScreen().removePreference(mShortcutPreference); 69 controlCategory.addPreference(mShortcutPreference); 70 return view; 71 } 72 73 @Override getMetricsCategory()74 public int getMetricsCategory() { 75 return SettingsEnums.ACCESSIBILITY_HEARING_AID_SETTINGS; 76 } 77 78 @Override getPreferenceScreenResId()79 protected int getPreferenceScreenResId() { 80 return R.xml.accessibility_hearing_aids; 81 } 82 83 @Override getLogTag()84 protected String getLogTag() { 85 return TAG; 86 } 87 88 @Override getComponentName()89 protected ComponentName getComponentName() { 90 return AccessibilityShortcutController.ACCESSIBILITY_HEARING_AIDS_COMPONENT_NAME; 91 } 92 93 @Override getLabelName()94 protected CharSequence getLabelName() { 95 return mFeatureName; 96 } 97 98 @Override getTileComponentName()99 protected ComponentName getTileComponentName() { 100 return AccessibilityShortcutController.ACCESSIBILITY_HEARING_AIDS_TILE_COMPONENT_NAME; 101 } 102 103 @Override getTileTooltipContent(int type)104 protected CharSequence getTileTooltipContent(int type) { 105 // No tooltip to be shown 106 return null; 107 } 108 109 @Override showGeneralCategory()110 protected boolean showGeneralCategory() { 111 // Have static preference under dynamically created PreferenceCategory KEY_GENERAL_CATEGORY. 112 // In order to modify that, we need to use our own PreferenceCategory for this page. 113 return false; 114 } 115 116 @Override getShortcutTitle()117 protected CharSequence getShortcutTitle() { 118 return getText(R.string.accessibility_hearing_device_shortcut_title); 119 } 120 121 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 122 new BaseSearchIndexProvider(R.xml.accessibility_hearing_aids); 123 } 124