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 android.app.Activity; 20 import android.app.settings.SettingsEnums; 21 import android.content.Context; 22 23 import androidx.annotation.NonNull; 24 import androidx.annotation.Nullable; 25 26 import com.android.settings.R; 27 import com.android.settings.dashboard.DashboardFragment; 28 import com.android.settings.inputmethod.PhysicalKeyboardPreferenceController; 29 import com.android.settings.inputmethod.SpellCheckerPreferenceController; 30 import com.android.settings.inputmethod.VirtualKeyboardPreferenceController; 31 import com.android.settings.search.BaseSearchIndexProvider; 32 import com.android.settings.widget.PreferenceCategoryController; 33 import com.android.settingslib.core.AbstractPreferenceController; 34 import com.android.settingslib.core.lifecycle.Lifecycle; 35 import com.android.settingslib.search.SearchIndexable; 36 37 import java.util.ArrayList; 38 import java.util.Arrays; 39 import java.util.List; 40 41 @SearchIndexable 42 public class LanguageAndInputSettings extends DashboardFragment { 43 44 private static final String TAG = "LangAndInputSettings"; 45 46 private static final String KEY_KEYBOARDS_CATEGORY = "keyboards_category"; 47 private static final String KEY_TEXT_TO_SPEECH = "tts_settings_summary"; 48 private static final String KEY_POINTER_AND_TTS_CATEGORY = "pointer_and_tts_category"; 49 50 @Override getMetricsCategory()51 public int getMetricsCategory() { 52 return SettingsEnums.SETTINGS_LANGUAGE_CATEGORY; 53 } 54 55 @Override getLogTag()56 protected String getLogTag() { 57 return TAG; 58 } 59 60 @Override onResume()61 public void onResume() { 62 super.onResume(); 63 // Hack to update action bar title. It's necessary to refresh title because this page user 64 // can change locale from here and fragment won't relaunch. Once language changes, title 65 // must display in the new language. 66 final Activity activity = getActivity(); 67 if (activity == null) { 68 return; 69 } 70 activity.setTitle(R.string.language_settings); 71 } 72 73 @Override getPreferenceScreenResId()74 protected int getPreferenceScreenResId() { 75 return R.xml.language_and_input; 76 } 77 78 @Override createPreferenceControllers(Context context)79 protected List<AbstractPreferenceController> createPreferenceControllers(Context context) { 80 return buildPreferenceControllers(context, getSettingsLifecycle()); 81 } 82 buildPreferenceControllers( @onNull Context context, @Nullable Lifecycle lifecycle)83 private static List<AbstractPreferenceController> buildPreferenceControllers( 84 @NonNull Context context, @Nullable Lifecycle lifecycle) { 85 final List<AbstractPreferenceController> controllers = new ArrayList<>(); 86 // Language 87 controllers.add(new PhoneLanguagePreferenceController(context)); 88 89 // Input 90 final VirtualKeyboardPreferenceController virtualKeyboardPreferenceController = 91 new VirtualKeyboardPreferenceController(context); 92 final PhysicalKeyboardPreferenceController physicalKeyboardPreferenceController = 93 new PhysicalKeyboardPreferenceController(context, lifecycle); 94 controllers.add(virtualKeyboardPreferenceController); 95 controllers.add(physicalKeyboardPreferenceController); 96 controllers.add(new PreferenceCategoryController(context, 97 KEY_KEYBOARDS_CATEGORY).setChildren( 98 Arrays.asList(virtualKeyboardPreferenceController, 99 physicalKeyboardPreferenceController))); 100 101 // Pointer and Tts 102 final TtsPreferenceController ttsPreferenceController = 103 new TtsPreferenceController(context, KEY_TEXT_TO_SPEECH); 104 controllers.add(ttsPreferenceController); 105 final PointerSpeedController pointerController = new PointerSpeedController(context); 106 controllers.add(pointerController); 107 controllers.add(new PreferenceCategoryController(context, 108 KEY_POINTER_AND_TTS_CATEGORY).setChildren( 109 Arrays.asList(pointerController, ttsPreferenceController))); 110 111 // Input Assistance 112 controllers.add(new SpellCheckerPreferenceController(context)); 113 114 return controllers; 115 } 116 117 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 118 new BaseSearchIndexProvider(R.xml.language_and_input) { 119 120 @Override 121 public List<AbstractPreferenceController> createPreferenceControllers( 122 Context context) { 123 return buildPreferenceControllers(context, null); 124 } 125 }; 126 } 127