@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();
   }
 }
 private void updateActiveInputMethodsSummary() {
   for (Preference pref : mInputMethodPreferenceList) {
     if (pref instanceof InputMethodPreference) {
       ((InputMethodPreference) pref).updateSummary();
     }
   }
   updateCurrentImeName();
 }
  private InputMethodPreference getInputMethodPreference(InputMethodInfo imi, int imiSize) {
    final PackageManager pm = getPackageManager();
    final CharSequence label = imi.loadLabel(pm);
    // IME settings
    final Intent intent;
    final String settingsActivity = imi.getSettingsActivity();
    if (!TextUtils.isEmpty(settingsActivity)) {
      intent = new Intent(Intent.ACTION_MAIN);
      intent.setClassName(imi.getPackageName(), settingsActivity);
    } else {
      intent = null;
    }

    // Add a check box for enabling/disabling IME
    InputMethodPreference pref = new InputMethodPreference(this, intent, mImm, imi, imiSize);
    pref.setKey(imi.getId());
    pref.setTitle(label);
    return pref;
  }
 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();
   }
 }