Java Code Examples for android.view.inputmethod.InputMethodInfo#getId()

The following examples show how to use android.view.inputmethod.InputMethodInfo#getId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InputMethodManagerService.java    From TvRemoteControl with Apache License 2.0 5 votes vote down vote up
@Override
public int compare(InputMethodInfo imi1, InputMethodInfo imi2) {
    if (imi2 == null) return 0;
    if (imi1 == null) return 1;
    if (mPm == null) {
        return imi1.getId().compareTo(imi2.getId());
    }
    CharSequence imiId1 = imi1.loadLabel(mPm) + "/" + imi1.getId();
    CharSequence imiId2 = imi2.loadLabel(mPm) + "/" + imi2.getId();
    return imiId1.toString().compareTo(imiId2.toString());
}
 
Example 2
Source File: MyUiAutomatorTestCase.java    From PUMA with Apache License 2.0 5 votes vote down vote up
private void setDummyIme() throws RemoteException {
	IInputMethodManager im = IInputMethodManager.Stub.asInterface(ServiceManager.getService(Context.INPUT_METHOD_SERVICE));
	List<InputMethodInfo> infos = im.getInputMethodList();
	String id = null;
	for (InputMethodInfo info : infos) {
		if (DUMMY_IME_PACKAGE.equals(info.getComponent().getPackageName())) {
			id = info.getId();
		}
	}
	if (id == null) {
		throw new RuntimeException(String.format("Required testing fixture missing: IME package (%s)", DUMMY_IME_PACKAGE));
	}
	im.setInputMethod(null, id);
}
 
Example 3
Source File: InputMethodManagerService.java    From TvRemoteControl with Apache License 2.0 4 votes vote down vote up
InputBindResult startInputInnerLocked() {
    if (mCurMethodId == null) {
        return mNoBinding;
    }

    if (!mSystemReady) {
        // If the system is not yet ready, we shouldn't be running third
        // party code.
        return new InputBindResult(null, null, mCurMethodId, mCurSeq);
    }

    InputMethodInfo info = mMethodMap.get(mCurMethodId);
    if (info == null) {
        throw new IllegalArgumentException("Unknown id: " + mCurMethodId);
    }

    unbindCurrentMethodLocked(false, true);

    mCurIntent = new Intent(InputMethod.SERVICE_INTERFACE);
    mCurIntent.setComponent(info.getComponent());
    mCurIntent.putExtra(Intent.EXTRA_CLIENT_LABEL,
            com.android.internal.R.string.input_method_binding_label);
    mCurIntent.putExtra(Intent.EXTRA_CLIENT_INTENT, PendingIntent.getActivity(
            mContext, 0, new Intent(Settings.ACTION_INPUT_METHOD_SETTINGS), 0));
    if (bindCurrentInputMethodService(mCurIntent, this, Context.BIND_AUTO_CREATE
            | Context.BIND_NOT_VISIBLE | Context.BIND_SHOWING_UI)) {
        mLastBindTime = SystemClock.uptimeMillis();
        mHaveConnection = true;
        mCurId = info.getId();
        mCurToken = new Binder();
        try {
            if (true || DEBUG) Slog.v(TAG, "Adding window token: " + mCurToken);
            mIWindowManager.addWindowToken(mCurToken,
                    WindowManager.LayoutParams.TYPE_INPUT_METHOD);
        } catch (RemoteException e) {
        }
        return new InputBindResult(null, null, mCurId, mCurSeq);
    } else {
        mCurIntent = null;
        Slog.w(TAG, "Failure connecting to input method service: "
                + mCurIntent);
    }
    return null;
}
 
Example 4
Source File: InputMethodManagerService.java    From TvRemoteControl with Apache License 2.0 4 votes vote down vote up
@Override
public boolean switchToLastInputMethod(IBinder token) {
    if (!calledFromValidUser()) {
        return false;
    }
    synchronized (mMethodMap) {
        final Pair<String, String> lastIme = mSettings.getLastInputMethodAndSubtypeLocked();
        final InputMethodInfo lastImi;
        if (lastIme != null) {
            lastImi = mMethodMap.get(lastIme.first);
        } else {
            lastImi = null;
        }
        String targetLastImiId = null;
        int subtypeId = NOT_A_SUBTYPE_ID;
        if (lastIme != null && lastImi != null) {
            final boolean imiIdIsSame = lastImi.getId().equals(mCurMethodId);
            final int lastSubtypeHash = Integer.valueOf(lastIme.second);
            final int currentSubtypeHash = mCurrentSubtype == null ? NOT_A_SUBTYPE_ID
                    : mCurrentSubtype.hashCode();
            // If the last IME is the same as the current IME and the last subtype is not
            // defined, there is no need to switch to the last IME.
            if (!imiIdIsSame || lastSubtypeHash != currentSubtypeHash) {
                targetLastImiId = lastIme.first;
                subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(lastImi, lastSubtypeHash);
            }
        }

        if (TextUtils.isEmpty(targetLastImiId)
                && !InputMethodUtils.canAddToLastInputMethod(mCurrentSubtype)) {
            // This is a safety net. If the currentSubtype can't be added to the history
            // and the framework couldn't find the last ime, we will make the last ime be
            // the most applicable enabled keyboard subtype of the system imes.
            final List<InputMethodInfo> enabled = mSettings.getEnabledInputMethodListLocked();
            if (enabled != null) {
                final int N = enabled.size();
                final String locale = mCurrentSubtype == null
                        ? mRes.getConfiguration().locale.toString()
                        : mCurrentSubtype.getLocale();
                for (int i = 0; i < N; ++i) {
                    final InputMethodInfo imi = enabled.get(i);
                    if (imi.getSubtypeCount() > 0 && InputMethodUtils.isSystemIme(imi)) {
                        InputMethodSubtype keyboardSubtype =
                                InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes,
                                        InputMethodUtils.getSubtypes(imi),
                                        InputMethodUtils.SUBTYPE_MODE_KEYBOARD, locale, true);
                        if (keyboardSubtype != null) {
                            targetLastImiId = imi.getId();
                            subtypeId = InputMethodUtils.getSubtypeIdFromHashCode(
                                    imi, keyboardSubtype.hashCode());
                            if(keyboardSubtype.getLocale().equals(locale)) {
                                break;
                            }
                        }
                    }
                }
            }
        }

        if (!TextUtils.isEmpty(targetLastImiId)) {
            if (DEBUG) {
                Slog.d(TAG, "Switch to: " + lastImi.getId() + ", " + lastIme.second
                        + ", from: " + mCurMethodId + ", " + subtypeId);
            }
            setInputMethodWithSubtypeId(token, targetLastImiId, subtypeId);
            return true;
        } else {
            return false;
        }
    }
}
 
Example 5
Source File: InputMethodManagerService.java    From TvRemoteControl with Apache License 2.0 4 votes vote down vote up
private Pair<InputMethodInfo, InputMethodSubtype>
        findLastResortApplicableShortcutInputMethodAndSubtypeLocked(String mode) {
    List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked();
    InputMethodInfo mostApplicableIMI = null;
    InputMethodSubtype mostApplicableSubtype = null;
    boolean foundInSystemIME = false;

    // Search applicable subtype for each InputMethodInfo
    for (InputMethodInfo imi: imis) {
        final String imiId = imi.getId();
        if (foundInSystemIME && !imiId.equals(mCurMethodId)) {
            continue;
        }
        InputMethodSubtype subtype = null;
        final List<InputMethodSubtype> enabledSubtypes =
                mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true);
        // 1. Search by the current subtype's locale from enabledSubtypes.
        if (mCurrentSubtype != null) {
            subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
                    mRes, enabledSubtypes, mode, mCurrentSubtype.getLocale(), false);
        }
        // 2. Search by the system locale from enabledSubtypes.
        // 3. Search the first enabled subtype matched with mode from enabledSubtypes.
        if (subtype == null) {
            subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
                    mRes, enabledSubtypes, mode, null, true);
        }
        final ArrayList<InputMethodSubtype> overridingImplicitlyEnabledSubtypes =
                InputMethodUtils.getOverridingImplicitlyEnabledSubtypes(imi, mode);
        final ArrayList<InputMethodSubtype> subtypesForSearch =
                overridingImplicitlyEnabledSubtypes.isEmpty()
                        ? InputMethodUtils.getSubtypes(imi)
                        : overridingImplicitlyEnabledSubtypes;
        // 4. Search by the current subtype's locale from all subtypes.
        if (subtype == null && mCurrentSubtype != null) {
            subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
                    mRes, subtypesForSearch, mode, mCurrentSubtype.getLocale(), false);
        }
        // 5. Search by the system locale from all subtypes.
        // 6. Search the first enabled subtype matched with mode from all subtypes.
        if (subtype == null) {
            subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(
                    mRes, subtypesForSearch, mode, null, true);
        }
        if (subtype != null) {
            if (imiId.equals(mCurMethodId)) {
                // The current input method is the most applicable IME.
                mostApplicableIMI = imi;
                mostApplicableSubtype = subtype;
                break;
            } else if (!foundInSystemIME) {
                // The system input method is 2nd applicable IME.
                mostApplicableIMI = imi;
                mostApplicableSubtype = subtype;
                if ((imi.getServiceInfo().applicationInfo.flags
                        & ApplicationInfo.FLAG_SYSTEM) != 0) {
                    foundInSystemIME = true;
                }
            }
        }
    }
    if (DEBUG) {
        if (mostApplicableIMI != null) {
            Slog.w(TAG, "Most applicable shortcut input method was:"
                    + mostApplicableIMI.getId());
            if (mostApplicableSubtype != null) {
                Slog.w(TAG, "Most applicable shortcut input method subtype was:"
                        + "," + mostApplicableSubtype.getMode() + ","
                        + mostApplicableSubtype.getLocale());
            }
        }
    }
    if (mostApplicableIMI != null) {
        return new Pair<InputMethodInfo, InputMethodSubtype> (mostApplicableIMI,
                mostApplicableSubtype);
    } else {
        return null;
    }
}