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.inputmethod;
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.settings.SettingsEnums;
24 import android.content.Context;
25 import android.os.Bundle;
26 
27 import androidx.annotation.NonNull;
28 import androidx.annotation.Nullable;
29 
30 import com.android.settings.R;
31 import com.android.settings.dashboard.DashboardFragment;
32 import com.android.settings.language.PointerSpeedController;
33 import com.android.settings.search.BaseSearchIndexProvider;
34 import com.android.settings.widget.PreferenceCategoryController;
35 import com.android.settingslib.core.AbstractPreferenceController;
36 import com.android.settingslib.core.lifecycle.Lifecycle;
37 import com.android.settingslib.search.SearchIndexable;
38 
39 import java.util.ArrayList;
40 import java.util.Arrays;
41 import java.util.List;
42 
43 @SearchIndexable
44 public class KeyboardSettings extends DashboardFragment {
45 
46     private static final String TAG = "KeyboardSettings";
47 
48     private static final String KEY_KEYBOARDS_CATEGORY = "keyboards_category";
49     private static final String KEY_POINTER_CATEGORY = "pointer_category";
50 
51     @Override
getMetricsCategory()52     public int getMetricsCategory() {
53         return SettingsEnums.SETTINGS_KEYBOARDS_CATEGORY;
54     }
55 
56     @Override
getLogTag()57     protected String getLogTag() {
58         return TAG;
59     }
60 
61     @Override
onCreate(Bundle icicle)62     public void onCreate(Bundle icicle) {
63         super.onCreate(icicle);
64         replaceEnterpriseStringTitle("language_and_input_for_work_category",
65                 WORK_PROFILE_KEYBOARDS_AND_TOOLS,
66                 R.string.language_and_input_for_work_category_title);
67         replaceEnterpriseStringTitle("spellcheckers_settings_for_work_pref",
68                 SPELL_CHECKER_FOR_WORK,
69                 R.string.spellcheckers_settings_for_work_title);
70         replaceEnterpriseStringTitle("user_dictionary_settings_for_work_pref",
71                 PERSONAL_DICTIONARY_FOR_WORK,
72                 R.string.user_dict_settings_for_work_title);
73     }
74 
75     @Override
getPreferenceScreenResId()76     protected int getPreferenceScreenResId() {
77         return R.xml.keyboard_settings;
78     }
79 
80     @Override
createPreferenceControllers(Context context)81     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
82         return buildPreferenceControllers(context, getSettingsLifecycle());
83     }
84 
buildPreferenceControllers( @onNull Context context, @Nullable Lifecycle lifecycle)85     private static List<AbstractPreferenceController> buildPreferenceControllers(
86             @NonNull Context context, @Nullable Lifecycle lifecycle) {
87         final List<AbstractPreferenceController> controllers = new ArrayList<>();
88         // Input
89         final VirtualKeyboardPreferenceController virtualKeyboardPreferenceController =
90                 new VirtualKeyboardPreferenceController(context);
91         final PhysicalKeyboardPreferenceController physicalKeyboardPreferenceController =
92                 new PhysicalKeyboardPreferenceController(context, lifecycle);
93         controllers.add(virtualKeyboardPreferenceController);
94         controllers.add(physicalKeyboardPreferenceController);
95         controllers.add(new PreferenceCategoryController(context,
96                 KEY_KEYBOARDS_CATEGORY).setChildren(
97                 Arrays.asList(virtualKeyboardPreferenceController,
98                         physicalKeyboardPreferenceController)));
99 
100         // Pointer
101         final PointerSpeedController pointerController = new PointerSpeedController(context);
102         controllers.add(pointerController);
103         controllers.add(new PreferenceCategoryController(context,
104                 KEY_POINTER_CATEGORY).setChildren(Arrays.asList(pointerController)));
105 
106         // Input Assistance
107         controllers.add(new SpellCheckerPreferenceController(context));
108 
109         return controllers;
110     }
111 
112     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
113             new BaseSearchIndexProvider(R.xml.keyboard_settings);
114 }