@Override public void onResume() { super.onResume(); mSettingsObserver.resume(); mIm.registerInputDeviceListener(this, null); if (!mIsOnlyImeSettings) { if (mLanguagePref != null) { Configuration conf = getResources().getConfiguration(); String language = conf.locale.getLanguage(); String localeString; // TODO: This is not an accurate way to display the locale, as it is // just working around the fact that we support limited dialects // and want to pretend that the language is valid for all locales. // We need a way to support languages that aren't tied to a particular // locale instead of hiding the locale qualifier. if (hasOnlyOneLanguageInstance(language, Resources.getSystem().getAssets().getLocales())) { localeString = conf.locale.getDisplayLanguage(conf.locale); } else { localeString = conf.locale.getDisplayName(conf.locale); } if (localeString.length() > 1) { localeString = Character.toUpperCase(localeString.charAt(0)) + localeString.substring(1); mLanguagePref.setSummary(localeString); } } updateUserDictionaryPreference(findPreference(KEY_USER_DICTIONARY_SETTINGS)); if (SHOW_INPUT_METHOD_SWITCHER_SETTINGS) { mShowInputMethodSelectorPref.setOnPreferenceChangeListener(this); } } if (mStatusBarImeSwitcher != null) { mStatusBarImeSwitcher.setChecked( Settings.System.getInt( getActivity().getContentResolver(), Settings.System.STATUS_BAR_IME_SWITCHER, 1) != 0); } // Hard keyboard if (!mHardKeyboardPreferenceList.isEmpty()) { for (int i = 0; i < sHardKeyboardKeys.length; ++i) { CheckBoxPreference chkPref = (CheckBoxPreference) mHardKeyboardCategory.findPreference(sHardKeyboardKeys[i]); chkPref.setChecked(System.getInt(getContentResolver(), sSystemSettingNames[i], 1) > 0); } } updateInputDevices(); // IME InputMethodAndSubtypeUtil.loadInputMethodSubtypeList(this, getContentResolver(), mImis, null); updateActiveInputMethodsSummary(); }
@Override public void onSaveInputMethodPreference(final InputMethodPreference pref) { final boolean hasHardwareKeyboard = getResources().getConfiguration().keyboard == Configuration.KEYBOARD_QWERTY; InputMethodAndSubtypeUtil.saveInputMethodSubtypeList( this, getContentResolver(), mImm.getInputMethodList(), hasHardwareKeyboard); // Update input method settings and preference list. mInputMethodSettingValues.refreshAllInputMethodAndSubtypes(); for (final InputMethodPreference p : mInputMethodPreferenceList) { p.updatePreferenceViews(); } }
@Override public void onPause() { super.onPause(); mIm.unregisterInputDeviceListener(this); mSettingsObserver.pause(); if (SHOW_INPUT_METHOD_SWITCHER_SETTINGS) { mShowInputMethodSelectorPref.setOnPreferenceChangeListener(null); } InputMethodAndSubtypeUtil.saveInputMethodSubtypeList( this, getContentResolver(), mImis, !mHardKeyboardPreferenceList.isEmpty()); }
private void updateCurrentImeName() { final Context context = getActivity(); if (context == null || mImm == null) return; final Preference curPref = getPreferenceScreen().findPreference(KEY_CURRENT_INPUT_METHOD); if (curPref != null) { final CharSequence curIme = InputMethodAndSubtypeUtil.getCurrentInputMethodName( context, getContentResolver(), mImm, mImis, getPackageManager()); if (!TextUtils.isEmpty(curIme)) { synchronized (this) { curPref.setSummary(curIme); } } } }
private void updateInputMethodPreferenceViews() { mInputMethodSettingValues.refreshAllInputMethodAndSubtypes(); // Clear existing "InputMethodPreference"s mInputMethodPreferenceList.clear(); List<String> permittedList = mDpm.getPermittedInputMethodsForCurrentUser(); final Context context = getPrefContext(); final PackageManager packageManager = getActivity().getPackageManager(); final List<InputMethodInfo> imis = mInputMethodSettingValues.getInputMethodList(); final int N = (imis == null ? 0 : imis.size()); for (int i = 0; i < N; ++i) { final InputMethodInfo imi = imis.get(i); final boolean isAllowedByOrganization = permittedList == null || permittedList.contains(imi.getPackageName()); final InputMethodPreference pref = new InputMethodPreference(context, imi, true, isAllowedByOrganization, this); pref.setIcon(getInputMethodIcon(packageManager, imi)); mInputMethodPreferenceList.add(pref); } final Collator collator = Collator.getInstance(); Collections.sort( mInputMethodPreferenceList, new Comparator<InputMethodPreference>() { @Override public int compare(InputMethodPreference lhs, InputMethodPreference rhs) { return lhs.compareTo(rhs, collator); } }); getPreferenceScreen().removeAll(); for (int i = 0; i < N; ++i) { final InputMethodPreference pref = mInputMethodPreferenceList.get(i); pref.setOrder(i); getPreferenceScreen().addPreference(pref); InputMethodAndSubtypeUtil.removeUnnecessaryNonPersistentPreference(pref); pref.updatePreferenceViews(); } }