1 /* 2 * Copyright (C) 2016 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.language; 18 19 import static android.app.admin.DevicePolicyResources.Strings.Settings.PERSONAL_DICTIONARY_FOR_WORK; 20 import static android.app.admin.DevicePolicyResources.Strings.Settings.SPELL_CHECKER_FOR_WORK; 21 import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_PROFILE_KEYBOARDS_AND_TOOLS; 22 23 import android.app.Activity; 24 import android.app.settings.SettingsEnums; 25 import android.content.Context; 26 import android.os.Bundle; 27 28 import androidx.annotation.NonNull; 29 import androidx.annotation.Nullable; 30 31 import com.android.settings.R; 32 import com.android.settings.dashboard.DashboardFragment; 33 import com.android.settings.inputmethod.PhysicalKeyboardPreferenceController; 34 import com.android.settings.inputmethod.SpellCheckerPreferenceController; 35 import com.android.settings.inputmethod.VirtualKeyboardPreferenceController; 36 import com.android.settings.search.BaseSearchIndexProvider; 37 import com.android.settings.widget.PreferenceCategoryController; 38 import com.android.settingslib.core.AbstractPreferenceController; 39 import com.android.settingslib.core.lifecycle.Lifecycle; 40 import com.android.settingslib.search.SearchIndexable; 41 42 import java.util.ArrayList; 43 import java.util.Arrays; 44 import java.util.List; 45 46 @SearchIndexable 47 public class LanguageAndInputSettings extends DashboardFragment { 48 49 private static final String TAG = "LangAndInputSettings"; 50 51 private static final String KEY_KEYBOARDS_CATEGORY = "keyboards_category"; 52 private static final String KEY_SPEECH_CATEGORY = "speech_category"; 53 private static final String KEY_ON_DEVICE_RECOGNITION = "odsr_settings"; 54 private static final String KEY_TEXT_TO_SPEECH = "tts_settings_summary"; 55 private static final String KEY_POINTER_CATEGORY = "pointer_category"; 56 57 @Override getMetricsCategory()58 public int getMetricsCategory() { 59 return SettingsEnums.SETTINGS_LANGUAGE_CATEGORY; 60 } 61 62 @Override getLogTag()63 protected String getLogTag() { 64 return TAG; 65 } 66 67 @Override onResume()68 public void onResume() { 69 super.onResume(); 70 // Hack to update action bar title. It's necessary to refresh title because this page user 71 // can change locale from here and fragment won't relaunch. Once language changes, title 72 // must display in the new language. 73 final Activity activity = getActivity(); 74 if (activity == null) { 75 return; 76 } 77 activity.setTitle(R.string.language_settings); 78 } 79 80 @Override onCreate(Bundle icicle)81 public void onCreate(Bundle icicle) { 82 super.onCreate(icicle); 83 replaceEnterpriseStringTitle("language_and_input_for_work_category", 84 WORK_PROFILE_KEYBOARDS_AND_TOOLS, 85 R.string.language_and_input_for_work_category_title); 86 replaceEnterpriseStringTitle("spellcheckers_settings_for_work_pref", 87 SPELL_CHECKER_FOR_WORK, 88 R.string.spellcheckers_settings_for_work_title); 89 replaceEnterpriseStringTitle("user_dictionary_settings_for_work_pref", 90 PERSONAL_DICTIONARY_FOR_WORK, 91 R.string.user_dict_settings_for_work_title); 92 } 93 94 @Override getPreferenceScreenResId()95 protected int getPreferenceScreenResId() { 96 return R.xml.language_and_input; 97 } 98 99 @Override createPreferenceControllers(Context context)100 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 101 return buildPreferenceControllers(context, getSettingsLifecycle()); 102 } 103 buildPreferenceControllers( @onNull Context context, @Nullable Lifecycle lifecycle)104 private static List<AbstractPreferenceController> buildPreferenceControllers( 105 @NonNull Context context, @Nullable Lifecycle lifecycle) { 106 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 107 // Language 108 controllers.add(new PhoneLanguagePreferenceController(context)); 109 110 // Input 111 final VirtualKeyboardPreferenceController virtualKeyboardPreferenceController = 112 new VirtualKeyboardPreferenceController(context); 113 final PhysicalKeyboardPreferenceController physicalKeyboardPreferenceController = 114 new PhysicalKeyboardPreferenceController(context, lifecycle); 115 controllers.add(virtualKeyboardPreferenceController); 116 controllers.add(physicalKeyboardPreferenceController); 117 controllers.add(new PreferenceCategoryController(context, 118 KEY_KEYBOARDS_CATEGORY).setChildren( 119 Arrays.asList(virtualKeyboardPreferenceController, 120 physicalKeyboardPreferenceController))); 121 122 // Speech 123 final DefaultVoiceInputPreferenceController defaultVoiceInputPreferenceController = 124 new DefaultVoiceInputPreferenceController(context, lifecycle); 125 final TtsPreferenceController ttsPreferenceController = 126 new TtsPreferenceController(context, KEY_TEXT_TO_SPEECH); 127 final OnDeviceRecognitionPreferenceController onDeviceRecognitionPreferenceController = 128 new OnDeviceRecognitionPreferenceController(context, KEY_ON_DEVICE_RECOGNITION); 129 130 controllers.add(defaultVoiceInputPreferenceController); 131 controllers.add(ttsPreferenceController); 132 List<AbstractPreferenceController> speechCategoryChildren = new ArrayList<>( 133 List.of(defaultVoiceInputPreferenceController, ttsPreferenceController)); 134 135 if (onDeviceRecognitionPreferenceController.isAvailable()) { 136 controllers.add(onDeviceRecognitionPreferenceController); 137 speechCategoryChildren.add(onDeviceRecognitionPreferenceController); 138 } 139 140 controllers.add(new PreferenceCategoryController(context, KEY_SPEECH_CATEGORY) 141 .setChildren(speechCategoryChildren)); 142 143 // Pointer 144 final PointerSpeedController pointerController = new PointerSpeedController(context); 145 controllers.add(pointerController); 146 controllers.add(new PreferenceCategoryController(context, 147 KEY_POINTER_CATEGORY).setChildren(Arrays.asList(pointerController))); 148 149 // Input Assistance 150 controllers.add(new SpellCheckerPreferenceController(context)); 151 152 return controllers; 153 } 154 155 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 156 new BaseSearchIndexProvider(R.xml.language_and_input) { 157 158 @Override 159 public List<AbstractPreferenceController> createPreferenceControllers( 160 Context context) { 161 return buildPreferenceControllers(context, null); 162 } 163 }; 164 } 165