Search in sources :

Example 6 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project android_frameworks_base by ParanoidAndroid.

the class KeyguardPasswordView method hasMultipleEnabledIMEsOrSubtypes.

/**
     * Method adapted from com.android.inputmethod.latin.Utils
     *
     * @param imm The input method manager
     * @param shouldIncludeAuxiliarySubtypes
     * @return true if we have multiple IMEs to choose from
     */
private boolean hasMultipleEnabledIMEsOrSubtypes(InputMethodManager imm, final boolean shouldIncludeAuxiliarySubtypes) {
    final List<InputMethodInfo> enabledImis = imm.getEnabledInputMethodList();
    // Number of the filtered IMEs
    int filteredImisCount = 0;
    for (InputMethodInfo imi : enabledImis) {
        // We can return true immediately after we find two or more filtered IMEs.
        if (filteredImisCount > 1)
            return true;
        final List<InputMethodSubtype> subtypes = imm.getEnabledInputMethodSubtypeList(imi, true);
        // IMEs that have no subtypes should be counted.
        if (subtypes.isEmpty()) {
            ++filteredImisCount;
            continue;
        }
        int auxCount = 0;
        for (InputMethodSubtype subtype : subtypes) {
            if (subtype.isAuxiliary()) {
                ++auxCount;
            }
        }
        final int nonAuxCount = subtypes.size() - auxCount;
        // subtypes should be counted as well.
        if (nonAuxCount > 0 || (shouldIncludeAuxiliarySubtypes && auxCount > 1)) {
            ++filteredImisCount;
            continue;
        }
    }
    return filteredImisCount > 1 || // input method subtype (The current IME should be LatinIME.)
    imm.getEnabledInputMethodSubtypeList(null, false).size() > 1;
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 7 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project android_frameworks_base by ParanoidAndroid.

the class InputMethodManagerService method buildInputMethodListLocked.

void buildInputMethodListLocked(ArrayList<InputMethodInfo> list, HashMap<String, InputMethodInfo> map, boolean resetDefaultEnabledIme) {
    if (DEBUG) {
        Slog.d(TAG, "--- re-buildInputMethodList reset = " + resetDefaultEnabledIme + " \n ------ \n" + getStackTrace());
    }
    list.clear();
    map.clear();
    // Use for queryIntentServicesAsUser
    final PackageManager pm = mContext.getPackageManager();
    String disabledSysImes = mSettings.getDisabledSystemInputMethods();
    if (disabledSysImes == null)
        disabledSysImes = "";
    final List<ResolveInfo> services = pm.queryIntentServicesAsUser(new Intent(InputMethod.SERVICE_INTERFACE), PackageManager.GET_META_DATA | PackageManager.GET_DISABLED_UNTIL_USED_COMPONENTS, mSettings.getCurrentUserId());
    final HashMap<String, List<InputMethodSubtype>> additionalSubtypes = mFileManager.getAllAdditionalInputMethodSubtypes();
    for (int i = 0; i < services.size(); ++i) {
        ResolveInfo ri = services.get(i);
        ServiceInfo si = ri.serviceInfo;
        ComponentName compName = new ComponentName(si.packageName, si.name);
        if (!android.Manifest.permission.BIND_INPUT_METHOD.equals(si.permission)) {
            Slog.w(TAG, "Skipping input method " + compName + ": it does not require the permission " + android.Manifest.permission.BIND_INPUT_METHOD);
            continue;
        }
        if (DEBUG)
            Slog.d(TAG, "Checking " + compName);
        try {
            InputMethodInfo p = new InputMethodInfo(mContext, ri, additionalSubtypes);
            list.add(p);
            final String id = p.getId();
            map.put(id, p);
            if (DEBUG) {
                Slog.d(TAG, "Found an input method " + p);
            }
        } catch (XmlPullParserException e) {
            Slog.w(TAG, "Unable to load input method " + compName, e);
        } catch (IOException e) {
            Slog.w(TAG, "Unable to load input method " + compName, e);
        }
    }
    if (resetDefaultEnabledIme) {
        final ArrayList<InputMethodInfo> defaultEnabledIme = InputMethodUtils.getDefaultEnabledImes(mContext, mSystemReady, list);
        for (int i = 0; i < defaultEnabledIme.size(); ++i) {
            final InputMethodInfo imi = defaultEnabledIme.get(i);
            if (DEBUG) {
                Slog.d(TAG, "--- enable ime = " + imi);
            }
            setInputMethodEnabledLocked(imi.getId(), true);
        }
    }
    final String defaultImiId = mSettings.getSelectedInputMethod();
    if (!TextUtils.isEmpty(defaultImiId)) {
        if (!map.containsKey(defaultImiId)) {
            Slog.w(TAG, "Default IME is uninstalled. Choose new default IME.");
            if (chooseNewDefaultIMELocked()) {
                updateFromSettingsLocked(true);
            }
        } else {
            // Double check that the default IME is certainly enabled.
            setInputMethodEnabledLocked(defaultImiId, true);
        }
    }
}
Also used : PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) IOException(java.io.IOException) InputMethodInfo(android.view.inputmethod.InputMethodInfo) ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) PackageManager(android.content.pm.PackageManager) IPackageManager(android.content.pm.IPackageManager) ArrayList(java.util.ArrayList) List(java.util.List) ComponentName(android.content.ComponentName) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 8 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project android_frameworks_base by ParanoidAndroid.

the class InputMethodManagerService method getLastInputMethodSubtype.

@Override
public InputMethodSubtype getLastInputMethodSubtype() {
    if (!calledFromValidUser()) {
        return null;
    }
    synchronized (mMethodMap) {
        final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked();
        // TODO: Handle the case of the last IME with no subtypes
        if (lastIme == null || TextUtils.isEmpty(lastIme.first) || TextUtils.isEmpty(lastIme.second))
            return null;
        final InputMethodInfo lastImi = mMethodMap.get(lastIme.first);
        if (lastImi == null)
            return null;
        try {
            final int lastSubtypeHash = Integer.valueOf(lastIme.second);
            final int lastSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash);
            if (lastSubtypeId < 0 || lastSubtypeId >= lastImi.getSubtypeCount()) {
                return null;
            }
            return lastImi.getSubtypeAt(lastSubtypeId);
        } catch (NumberFormatException e) {
            return null;
        }
    }
}
Also used : InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 9 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project android_frameworks_base by ParanoidAndroid.

the class InputMethodManagerService method showInputMethodMenuInternal.

private void showInputMethodMenuInternal(boolean showSubtypes) {
    if (DEBUG)
        Slog.v(TAG, "Show switching menu");
    final Context context = getUiContext();
    final boolean isScreenLocked = isScreenLocked();
    final String lastInputMethodId = mSettings.getSelectedInputMethod();
    int lastInputMethodSubtypeId = mSettings.getSelectedInputMethodSubtypeId(lastInputMethodId);
    if (DEBUG)
        Slog.v(TAG, "Current IME: " + lastInputMethodId);
    synchronized (mMethodMap) {
        final HashMap<InputMethodInfo, List<InputMethodSubtype>> immis = getExplicitlyOrImplicitlyEnabledInputMethodsAndSubtypeListLocked();
        if (immis == null || immis.size() == 0) {
            return;
        }
        hideInputMethodMenuLocked();
        final List<ImeSubtypeListItem> imList = mImListManager.getSortedInputMethodAndSubtypeList(showSubtypes, mInputShown, isScreenLocked);
        if (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID) {
            final InputMethodSubtype currentSubtype = getCurrentInputMethodSubtypeLocked();
            if (currentSubtype != null) {
                final InputMethodInfo currentImi = mMethodMap.get(mCurMethodId);
                lastInputMethodSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(currentImi, currentSubtype.hashCode());
            }
        }
        final int N = imList.size();
        mIms = new InputMethodInfo[N];
        mSubtypeIds = new int[N];
        int checkedItem = 0;
        for (int i = 0; i < N; ++i) {
            final ImeSubtypeListItem item = imList.get(i);
            mIms[i] = item.mImi;
            mSubtypeIds[i] = item.mSubtypeId;
            if (mIms[i].getId().equals(lastInputMethodId)) {
                int subtypeId = mSubtypeIds[i];
                if ((subtypeId == NOT_A_SUBTYPE_ID) || (lastInputMethodSubtypeId == NOT_A_SUBTYPE_ID && subtypeId == 0) || (subtypeId == lastInputMethodSubtypeId)) {
                    checkedItem = i;
                }
            }
        }
        final TypedArray a = context.obtainStyledAttributes(null, com.android.internal.R.styleable.DialogPreference, com.android.internal.R.attr.alertDialogStyle, 0);
        mDialogBuilder = new AlertDialog.Builder(context).setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface dialog) {
                hideInputMethodMenu();
            }
        }).setIcon(a.getDrawable(com.android.internal.R.styleable.DialogPreference_dialogTitle));
        a.recycle();
        final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final View tv = inflater.inflate(com.android.internal.R.layout.input_method_switch_dialog_title, null);
        mDialogBuilder.setCustomTitle(tv);
        // Setup layout for a toggle switch of the hardware keyboard
        mSwitchingDialogTitleView = tv;
        mSwitchingDialogTitleView.findViewById(com.android.internal.R.id.hard_keyboard_section).setVisibility(mWindowManagerService.isHardKeyboardAvailable() ? View.VISIBLE : View.GONE);
        final Switch hardKeySwitch = ((Switch) mSwitchingDialogTitleView.findViewById(com.android.internal.R.id.hard_keyboard_switch));
        hardKeySwitch.setChecked(mWindowManagerService.isHardKeyboardEnabled());
        hardKeySwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                mWindowManagerService.setHardKeyboardEnabled(isChecked);
                // Ensure that the input method dialog is dismissed when changing
                // the hardware keyboard state.
                hideInputMethodMenu();
            }
        });
        final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(context, com.android.internal.R.layout.simple_list_item_2_single_choice, imList, checkedItem);
        mDialogBuilder.setSingleChoiceItems(adapter, checkedItem, new AlertDialog.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                synchronized (mMethodMap) {
                    if (mIms == null || mIms.length <= which || mSubtypeIds == null || mSubtypeIds.length <= which) {
                        return;
                    }
                    InputMethodInfo im = mIms[which];
                    int subtypeId = mSubtypeIds[which];
                    adapter.mCheckedItem = which;
                    adapter.notifyDataSetChanged();
                    hideInputMethodMenu();
                    if (im != null) {
                        if ((subtypeId < 0) || (subtypeId >= im.getSubtypeCount())) {
                            subtypeId = NOT_A_SUBTYPE_ID;
                        }
                        setInputMethodLocked(im.getId(), subtypeId);
                    }
                }
            }
        });
        if (showSubtypes && !isScreenLocked) {
            mDialogBuilder.setPositiveButton(com.android.internal.R.string.configure_input_methods, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int whichButton) {
                    showConfigureInputMethods();
                }
            });
        }
        mSwitchingDialog = mDialogBuilder.create();
        mSwitchingDialog.setCanceledOnTouchOutside(true);
        mSwitchingDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_INPUT_METHOD_DIALOG);
        mSwitchingDialog.getWindow().getAttributes().privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
        mSwitchingDialog.getWindow().getAttributes().setTitle("Select input method");
        mSwitchingDialog.show();
    }
}
Also used : IInputContext(com.android.internal.view.IInputContext) Context(android.content.Context) AlertDialog(android.app.AlertDialog) InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) DialogInterface(android.content.DialogInterface) View(android.view.View) TextView(android.widget.TextView) InputMethodInfo(android.view.inputmethod.InputMethodInfo) Switch(android.widget.Switch) TypedArray(android.content.res.TypedArray) LayoutInflater(android.view.LayoutInflater) ArrayList(java.util.ArrayList) List(java.util.List) CompoundButton(android.widget.CompoundButton) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Example 10 with InputMethodInfo

use of android.view.inputmethod.InputMethodInfo in project android_frameworks_base by ParanoidAndroid.

the class InputMethodManagerService method resetSelectedInputMethodAndSubtypeLocked.

private void resetSelectedInputMethodAndSubtypeLocked(String newDefaultIme) {
    InputMethodInfo imi = mMethodMap.get(newDefaultIme);
    int lastSubtypeId = NOT_A_SUBTYPE_ID;
    // newDefaultIme is empty when there is no candidate for the selected IME.
    if (imi != null && !TextUtils.isEmpty(newDefaultIme)) {
        String subtypeHashCode = mSettings.getLastSubtypeForInputMethodLocked(newDefaultIme);
        if (subtypeHashCode != null) {
            try {
                lastSubtypeId = InputMethodUtils.getSubtypeIdFromHashCode(imi, Integer.valueOf(subtypeHashCode));
            } catch (NumberFormatException e) {
                Slog.w(TAG, "HashCode for subtype looks broken: " + subtypeHashCode, e);
            }
        }
    }
    setSelectedInputMethodAndSubtypeLocked(imi, lastSubtypeId, false);
}
Also used : InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Aggregations

InputMethodInfo (android.view.inputmethod.InputMethodInfo)309 InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)113 ArrayList (java.util.ArrayList)80 RemoteException (android.os.RemoteException)53 ServiceInfo (android.content.pm.ServiceInfo)34 ComponentName (android.content.ComponentName)33 Intent (android.content.Intent)33 Context (android.content.Context)32 InputMethodManager (android.view.inputmethod.InputMethodManager)29 ApplicationInfo (android.content.pm.ApplicationInfo)27 PendingIntent (android.app.PendingIntent)24 Test (org.junit.Test)24 ResolveInfo (android.content.pm.ResolveInfo)19 ImeSubtypeListItem (com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem)15 InputMethodPreference (com.android.settingslib.inputmethod.InputMethodPreference)14 List (java.util.List)14 PackageManager (android.content.pm.PackageManager)13 Drawable (android.graphics.drawable.Drawable)13 SmallTest (android.test.suitebuilder.annotation.SmallTest)12 Printer (android.util.Printer)12