FileDocCategorySizeDatePackage
InputMethodSettingsImpl.javaAPI DocAndroid 5.1 API6236Thu Mar 12 22:22:52 GMT 2015com.android.inputmethodcommon

InputMethodSettingsImpl

public class InputMethodSettingsImpl extends Object implements InputMethodSettingsInterface

Fields Summary
private android.preference.Preference
mSubtypeEnablerPreference
private int
mInputMethodSettingsCategoryTitleRes
private CharSequence
mInputMethodSettingsCategoryTitle
private int
mSubtypeEnablerTitleRes
private CharSequence
mSubtypeEnablerTitle
private int
mSubtypeEnablerIconRes
private android.graphics.drawable.Drawable
mSubtypeEnablerIcon
private android.view.inputmethod.InputMethodManager
mImm
private android.view.inputmethod.InputMethodInfo
mImi
Constructors Summary
Methods Summary
private static java.lang.StringgetEnabledSubtypesLabel(android.content.Context context, android.view.inputmethod.InputMethodManager imm, android.view.inputmethod.InputMethodInfo imi)

        if (context == null || imm == null || imi == null) return null;
        final List<InputMethodSubtype> subtypes = imm.getEnabledInputMethodSubtypeList(imi, true);
        final StringBuilder sb = new StringBuilder();
        final int N = subtypes.size();
        for (int i = 0; i < N; ++i) {
            final InputMethodSubtype subtype = subtypes.get(i);
            if (sb.length() > 0) {
                sb.append(", ");
            }
            sb.append(subtype.getDisplayName(context, imi.getPackageName(),
                    imi.getServiceInfo().applicationInfo));
        }
        return sb.toString();
    
private static android.view.inputmethod.InputMethodInfogetMyImi(android.content.Context context, android.view.inputmethod.InputMethodManager imm)

        final List<InputMethodInfo> imis = imm.getInputMethodList();
        for (int i = 0; i < imis.size(); ++i) {
            final InputMethodInfo imi = imis.get(i);
            if (imis.get(i).getPackageName().equals(context.getPackageName())) {
                return imi;
            }
        }
        return null;
    
public booleaninit(android.content.Context context, android.preference.PreferenceScreen prefScreen)
Initialize internal states of this object.

param
context the context for this application.
param
prefScreen a PreferenceScreen of PreferenceActivity or PreferenceFragment.
return
true if this application is an IME and has two or more subtypes, false otherwise.

        mImm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        mImi = getMyImi(context, mImm);
        if (mImi == null || mImi.getSubtypeCount() <= 1) {
            return false;
        }
        final Intent intent = new Intent(Settings.ACTION_INPUT_METHOD_SUBTYPE_SETTINGS);
        intent.putExtra(Settings.EXTRA_INPUT_METHOD_ID, mImi.getId());
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
                | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        mSubtypeEnablerPreference = new Preference(context);
        mSubtypeEnablerPreference.setIntent(intent);
        prefScreen.addPreference(mSubtypeEnablerPreference);
        updateSubtypeEnabler();
        return true;
    
public voidsetInputMethodSettingsCategoryTitle(int resId)
{@inheritDoc}

        mInputMethodSettingsCategoryTitleRes = resId;
        updateSubtypeEnabler();
    
public voidsetInputMethodSettingsCategoryTitle(java.lang.CharSequence title)
{@inheritDoc}

        mInputMethodSettingsCategoryTitleRes = 0;
        mInputMethodSettingsCategoryTitle = title;
        updateSubtypeEnabler();
    
public voidsetSubtypeEnablerIcon(int resId)
{@inheritDoc}

        mSubtypeEnablerIconRes = resId;
        updateSubtypeEnabler();
    
public voidsetSubtypeEnablerIcon(android.graphics.drawable.Drawable drawable)
{@inheritDoc}

        mSubtypeEnablerIconRes = 0;
        mSubtypeEnablerIcon = drawable;
        updateSubtypeEnabler();
    
public voidsetSubtypeEnablerTitle(int resId)
{@inheritDoc}

        mSubtypeEnablerTitleRes = resId;
        updateSubtypeEnabler();
    
public voidsetSubtypeEnablerTitle(java.lang.CharSequence title)
{@inheritDoc}

        mSubtypeEnablerTitleRes = 0;
        mSubtypeEnablerTitle = title;
        updateSubtypeEnabler();
    
public voidupdateSubtypeEnabler()

        final Preference pref = mSubtypeEnablerPreference;
        if (pref == null) {
            return;
        }
        final Context context = pref.getContext();
        final CharSequence title;
        if (mSubtypeEnablerTitleRes != 0) {
            title = context.getString(mSubtypeEnablerTitleRes);
        } else {
            title = mSubtypeEnablerTitle;
        }
        pref.setTitle(title);
        final Intent intent = pref.getIntent();
        if (intent != null) {
            intent.putExtra(Intent.EXTRA_TITLE, title);
        }
        final String summary = getEnabledSubtypesLabel(context, mImm, mImi);
        if (!TextUtils.isEmpty(summary)) {
            pref.setSummary(summary);
        }
        if (mSubtypeEnablerIconRes != 0) {
            pref.setIcon(mSubtypeEnablerIconRes);
        } else {
            pref.setIcon(mSubtypeEnablerIcon);
        }