Search in sources :

Example 81 with InputMethodSubtype

use of android.view.inputmethod.InputMethodSubtype in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class RichInputMethodManager method switchToNextInputMethodAndSubtype.

private boolean switchToNextInputMethodAndSubtype(final IBinder token) {
    final InputMethodManager imm = mImmWrapper.mImm;
    final List<InputMethodInfo> enabledImis = imm.getEnabledInputMethodList();
    final int currentIndex = getImiIndexInList(getInputMethodInfoOfThisIme(), enabledImis);
    if (currentIndex == INDEX_NOT_FOUND) {
        Log.w(TAG, "Can't find current IME in enabled IMEs: IME package=" + getInputMethodInfoOfThisIme().getPackageName());
        return false;
    }
    final InputMethodInfo nextImi = getNextNonAuxiliaryIme(currentIndex, enabledImis);
    final List<InputMethodSubtype> enabledSubtypes = getEnabledInputMethodSubtypeList(nextImi, true);
    if (enabledSubtypes.isEmpty()) {
        // The next IME has no subtype.
        imm.setInputMethod(token, nextImi.getId());
        return true;
    }
    final InputMethodSubtype firstSubtype = enabledSubtypes.get(0);
    imm.setInputMethodAndSubtype(token, nextImi.getId(), firstSubtype);
    return true;
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) InputMethodManager(android.view.inputmethod.InputMethodManager) InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 82 with InputMethodSubtype

use of android.view.inputmethod.InputMethodSubtype in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class RichInputMethodManager method switchToNextInputSubtypeInThisIme.

private boolean switchToNextInputSubtypeInThisIme(final IBinder token, final boolean onlyCurrentIme) {
    final InputMethodManager imm = mImmWrapper.mImm;
    final InputMethodSubtype currentSubtype = imm.getCurrentInputMethodSubtype();
    final List<InputMethodSubtype> enabledSubtypes = getMyEnabledInputMethodSubtypeList(true);
    final int currentIndex = getSubtypeIndexInList(currentSubtype, enabledSubtypes);
    if (currentIndex == INDEX_NOT_FOUND) {
        Log.w(TAG, "Can't find current subtype in enabled subtypes: subtype=" + SubtypeLocaleUtils.getSubtypeNameForLogging(currentSubtype));
        return false;
    }
    final int nextIndex = (currentIndex + 1) % enabledSubtypes.size();
    if (nextIndex <= currentIndex && !onlyCurrentIme) {
        // next IME.
        return false;
    }
    final InputMethodSubtype nextSubtype = enabledSubtypes.get(nextIndex);
    setInputMethodAndSubtype(token, nextSubtype);
    return true;
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) InputMethodManager(android.view.inputmethod.InputMethodManager)

Example 83 with InputMethodSubtype

use of android.view.inputmethod.InputMethodSubtype in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class RichInputMethodManager method initInternal.

private void initInternal(final Context context) {
    if (isInitialized()) {
        return;
    }
    mImmWrapper = new InputMethodManagerCompatWrapper(context);
    mContext = context;
    mInputMethodInfoCache = new InputMethodInfoCache(mImmWrapper.mImm, context.getPackageName());
    // Initialize additional subtypes.
    SubtypeLocaleUtils.init(context);
    final InputMethodSubtype[] additionalSubtypes = getAdditionalSubtypes();
    mImmWrapper.mImm.setAdditionalInputMethodSubtypes(getInputMethodIdOfThisIme(), additionalSubtypes);
    // Initialize the current input method subtype and the shortcut IME.
    refreshSubtypeCaches();
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) InputMethodManagerCompatWrapper(com.android.inputmethod.compat.InputMethodManagerCompatWrapper)

Example 84 with InputMethodSubtype

use of android.view.inputmethod.InputMethodSubtype in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class RichInputMethodManager method isSystemLocaleSameAsLocaleOfAllEnabledSubtypesOfEnabledImes.

public boolean isSystemLocaleSameAsLocaleOfAllEnabledSubtypesOfEnabledImes() {
    final Locale systemLocale = mContext.getResources().getConfiguration().locale;
    final Set<InputMethodSubtype> enabledSubtypesOfEnabledImes = new HashSet<>();
    final InputMethodManager inputMethodManager = getInputMethodManager();
    final List<InputMethodInfo> enabledInputMethodInfoList = inputMethodManager.getEnabledInputMethodList();
    for (final InputMethodInfo info : enabledInputMethodInfoList) {
        final List<InputMethodSubtype> enabledSubtypes = inputMethodManager.getEnabledInputMethodSubtypeList(info, true);
        if (enabledSubtypes.isEmpty()) {
            // An IME with no subtypes is found.
            return false;
        }
        enabledSubtypesOfEnabledImes.addAll(enabledSubtypes);
    }
    for (final InputMethodSubtype subtype : enabledSubtypesOfEnabledImes) {
        if (!subtype.isAuxiliary() && !subtype.getLocale().isEmpty() && !systemLocale.equals(SubtypeLocaleUtils.getSubtypeLocale(subtype))) {
            return false;
        }
    }
    return true;
}
Also used : Locale(java.util.Locale) InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) InputMethodManager(android.view.inputmethod.InputMethodManager) InputMethodInfo(android.view.inputmethod.InputMethodInfo) HashSet(java.util.HashSet)

Example 85 with InputMethodSubtype

use of android.view.inputmethod.InputMethodSubtype in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class SystemBroadcastReceiver method onReceive.

@Override
public void onReceive(final Context context, final Intent intent) {
    final String intentAction = intent.getAction();
    if (Intent.ACTION_MY_PACKAGE_REPLACED.equals(intentAction)) {
        Log.i(TAG, "Package has been replaced: " + context.getPackageName());
        // Need to restore additional subtypes because system always clears additional
        // subtypes when the package is replaced.
        RichInputMethodManager.init(context);
        final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
        final InputMethodSubtype[] additionalSubtypes = richImm.getAdditionalSubtypes();
        richImm.setAdditionalInputMethodSubtypes(additionalSubtypes);
        toggleAppIcon(context);
        // Remove all the previously scheduled downloads. This will also makes sure
        // that any erroneously stuck downloads will get cleared. (b/21797386)
        removeOldDownloads(context);
    // b/21797386
    // downloadLatestDictionaries(context);
    } else if (Intent.ACTION_BOOT_COMPLETED.equals(intentAction)) {
        Log.i(TAG, "Boot has been completed");
        toggleAppIcon(context);
    } else if (Intent.ACTION_LOCALE_CHANGED.equals(intentAction)) {
        Log.i(TAG, "System locale changed");
        KeyboardLayoutSet.onSystemLocaleChanged();
    }
    // The process that hosts this broadcast receiver is invoked and remains alive even after
    // 1) the package has been re-installed,
    // 2) the device has just booted,
    // 3) a new user has been created.
    // There is no good reason to keep the process alive if this IME isn't a current IME.
    final InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    // Called to check whether this IME has been triggered by the current user or not
    final boolean isInputMethodManagerValidForUserOfThisProcess = !imm.getInputMethodList().isEmpty();
    final boolean isCurrentImeOfCurrentUser = isInputMethodManagerValidForUserOfThisProcess && UncachedInputMethodManagerUtils.isThisImeCurrent(context, imm);
    if (!isCurrentImeOfCurrentUser) {
        final int myPid = Process.myPid();
        Log.i(TAG, "Killing my process: pid=" + myPid);
        Process.killProcess(myPid);
    }
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) InputMethodManager(android.view.inputmethod.InputMethodManager)

Aggregations

InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)216 InputMethodInfo (android.view.inputmethod.InputMethodInfo)112 ArrayList (java.util.ArrayList)49 InputMethodManager (android.view.inputmethod.InputMethodManager)21 Locale (java.util.Locale)17 LocaleList (android.os.LocaleList)15 ImeSubtypeListItem (com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem)15 Context (android.content.Context)12 SmallTest (android.test.suitebuilder.annotation.SmallTest)10 Cursor (android.database.Cursor)9 PreferenceScreen (android.support.v7.preference.PreferenceScreen)9 View (android.view.View)9 TextView (android.widget.TextView)9 TreeSet (java.util.TreeSet)9 PreferenceCategory (android.support.v7.preference.PreferenceCategory)8 RichInputMethodSubtype (com.android.inputmethod.latin.RichInputMethodSubtype)8 List (java.util.List)8 Intent (android.content.Intent)7 Pair (android.util.Pair)7 AlertDialog (android.app.AlertDialog)6