Search in sources :

Example 21 with InputMethodPreference

use of com.android.settingslib.inputmethod.InputMethodPreference in project android_packages_apps_Settings by omnirom.

the class AvailableVirtualKeyboardFragment method updateInputMethodPreferenceViews.

private void updateInputMethodPreferenceViews() {
    mInputMethodSettingValues.refreshAllInputMethodAndSubtypes();
    // Clear existing "InputMethodPreference"s
    mInputMethodPreferenceList.clear();
    List<String> permittedList = mDpm.getPermittedInputMethodsForCurrentUser();
    final Context context = getPrefContext();
    final List<InputMethodInfo> imis = mInputMethodSettingValues.getInputMethodList();
    final List<InputMethodInfo> enabledImis = mImm.getEnabledInputMethodList();
    final int numImis = (imis == null ? 0 : imis.size());
    for (int i = 0; i < numImis; ++i) {
        final InputMethodInfo imi = imis.get(i);
        // TODO (b/182876800): Move this logic out of isAllowedByOrganization and
        // into a new boolean.
        // If an input method is enabled but not included in the permitted list, then set it as
        // allowed by organization. Doing so will allow the user to disable the input method and
        // remain complaint with the organization's policy. Once disabled, the input method
        // cannot be re-enabled because it is not in the permitted list.
        final boolean isAllowedByOrganization = permittedList == null || permittedList.contains(imi.getPackageName()) || enabledImis.contains(imi);
        final InputMethodPreference pref = new InputMethodPreference(context, imi, true, isAllowedByOrganization, this);
        pref.setIcon(imi.loadIcon(context.getPackageManager()));
        mInputMethodPreferenceList.add(pref);
    }
    final Collator collator = Collator.getInstance();
    mInputMethodPreferenceList.sort((lhs, rhs) -> lhs.compareTo(rhs, collator));
    getPreferenceScreen().removeAll();
    for (int i = 0; i < numImis; ++i) {
        final InputMethodPreference pref = mInputMethodPreferenceList.get(i);
        pref.setOrder(i);
        getPreferenceScreen().addPreference(pref);
        InputMethodAndSubtypeUtilCompat.removeUnnecessaryNonPersistentPreference(pref);
        pref.updatePreferenceViews();
    }
}
Also used : Context(android.content.Context) InputMethodPreference(com.android.settingslib.inputmethod.InputMethodPreference) InputMethodInfo(android.view.inputmethod.InputMethodInfo) Collator(java.text.Collator)

Example 22 with InputMethodPreference

use of com.android.settingslib.inputmethod.InputMethodPreference in project android_packages_apps_Settings by omnirom.

the class InputMethodPreferenceController method updateInputMethodPreferenceViews.

private void updateInputMethodPreferenceViews() {
    final List<InputMethodPreference> preferenceList = new ArrayList<>();
    final List<String> permittedList = mDpm.getPermittedInputMethodsForCurrentUser();
    final List<InputMethodInfo> imis = mImm.getEnabledInputMethodList();
    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 Drawable icon = imi.loadIcon(mContext.getPackageManager());
        final InputMethodPreference pref = new InputMethodPreference(mScreen.getContext(), imi, false, /* isImeEnabler */
        isAllowedByOrganization, null);
        pref.setIcon(icon);
        preferenceList.add(pref);
    }
    final Collator collator = Collator.getInstance();
    preferenceList.sort((lhs, rhs) -> lhs.compareTo(rhs, collator));
    mScreen.removeAll();
    for (int i = 0; i < N; ++i) {
        final InputMethodPreference pref = preferenceList.get(i);
        pref.setOrder(i);
        mScreen.addPreference(pref);
        pref.updatePreferenceViews();
    }
    mScreen.addPreference(mPreference);
}
Also used : ArrayList(java.util.ArrayList) Drawable(android.graphics.drawable.Drawable) InputMethodPreference(com.android.settingslib.inputmethod.InputMethodPreference) InputMethodInfo(android.view.inputmethod.InputMethodInfo) Collator(java.text.Collator)

Aggregations

InputMethodPreference (com.android.settingslib.inputmethod.InputMethodPreference)22 InputMethodInfo (android.view.inputmethod.InputMethodInfo)15 Collator (java.text.Collator)15 Context (android.content.Context)14 Drawable (android.graphics.drawable.Drawable)8 ColorDrawable (android.graphics.drawable.ColorDrawable)6 PackageManager (android.content.pm.PackageManager)5 ArrayList (java.util.ArrayList)1