2 * Copyright (C) 2016 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings.inputmethod;
19 import android.content.Context;
20 import android.support.v7.preference.Preference;
21 import android.support.v7.preference.PreferenceScreen;
22 import android.view.textservice.SpellCheckerInfo;
23 import android.view.textservice.TextServicesManager;
25 import com.android.settings.R;
26 import com.android.settings.core.PreferenceController;
27 import com.android.settingslib.inputmethod.InputMethodAndSubtypeUtil;
29 public class SpellCheckerPreferenceController extends PreferenceController {
31 public static final String KEY_SPELL_CHECKERS = "spellcheckers_settings";
33 private final TextServicesManager mTextServicesManager;
35 public SpellCheckerPreferenceController(Context context) {
37 mTextServicesManager = (TextServicesManager) context.getSystemService(
38 Context.TEXT_SERVICES_MANAGER_SERVICE);
42 public void displayPreference(PreferenceScreen screen) {
43 super.displayPreference(screen);
44 final Preference preference = screen.findPreference(KEY_SPELL_CHECKERS);
45 if (preference != null) {
46 InputMethodAndSubtypeUtil.removeUnnecessaryNonPersistentPreference(preference);
51 public boolean isAvailable() {
56 public String getPreferenceKey() {
57 return KEY_SPELL_CHECKERS;
61 public void updateState(Preference preference) {
62 if (preference == null) {
65 if (!mTextServicesManager.isSpellCheckerEnabled()) {
66 preference.setSummary(R.string.switch_off_text);
68 final SpellCheckerInfo sci = mTextServicesManager.getCurrentSpellChecker();
70 preference.setSummary(sci.loadLabel(mContext.getPackageManager()));
72 preference.setSummary(R.string.spell_checker_not_selected);