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