Search in sources :

Example 51 with InputMethodSubtype

use of android.view.inputmethod.InputMethodSubtype in project android_frameworks_base by crdroidandroid.

the class InputMethodUtils method findLastResortApplicableSubtypeLocked.

/**
     * If there are no selected subtypes, tries finding the most applicable one according to the
     * given locale.
     * @param subtypes this function will search the most applicable subtype in subtypes
     * @param mode subtypes will be filtered by mode
     * @param locale subtypes will be filtered by locale
     * @param canIgnoreLocaleAsLastResort if this function can't find the most applicable subtype,
     * it will return the first subtype matched with mode
     * @return the most applicable subtypeId
     */
public static InputMethodSubtype findLastResortApplicableSubtypeLocked(Resources res, List<InputMethodSubtype> subtypes, String mode, String locale, boolean canIgnoreLocaleAsLastResort) {
    if (subtypes == null || subtypes.size() == 0) {
        return null;
    }
    if (TextUtils.isEmpty(locale)) {
        locale = res.getConfiguration().locale.toString();
    }
    final String language = getLanguageFromLocaleString(locale);
    boolean partialMatchFound = false;
    InputMethodSubtype applicableSubtype = null;
    InputMethodSubtype firstMatchedModeSubtype = null;
    final int N = subtypes.size();
    for (int i = 0; i < N; ++i) {
        InputMethodSubtype subtype = subtypes.get(i);
        final String subtypeLocale = subtype.getLocale();
        final String subtypeLanguage = getLanguageFromLocaleString(subtypeLocale);
        // and all subtypes with all modes can be candidates.
        if (mode == null || subtypes.get(i).getMode().equalsIgnoreCase(mode)) {
            if (firstMatchedModeSubtype == null) {
                firstMatchedModeSubtype = subtype;
            }
            if (locale.equals(subtypeLocale)) {
                // Exact match (e.g. system locale is "en_US" and subtype locale is "en_US")
                applicableSubtype = subtype;
                break;
            } else if (!partialMatchFound && language.equals(subtypeLanguage)) {
                // Partial match (e.g. system locale is "en_US" and subtype locale is "en")
                applicableSubtype = subtype;
                partialMatchFound = true;
            }
        }
    }
    if (applicableSubtype == null && canIgnoreLocaleAsLastResort) {
        return firstMatchedModeSubtype;
    }
    // subtype.
    if (DEBUG) {
        if (applicableSubtype != null) {
            Slog.d(TAG, "Applicable InputMethodSubtype was found: " + applicableSubtype.getMode() + "," + applicableSubtype.getLocale());
        }
    }
    return applicableSubtype;
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype)

Example 52 with InputMethodSubtype

use of android.view.inputmethod.InputMethodSubtype in project android_frameworks_base by crdroidandroid.

the class InputMethodUtils method getOverridingImplicitlyEnabledSubtypes.

public static ArrayList<InputMethodSubtype> getOverridingImplicitlyEnabledSubtypes(InputMethodInfo imi, String mode) {
    ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
    final int subtypeCount = imi.getSubtypeCount();
    for (int i = 0; i < subtypeCount; ++i) {
        final InputMethodSubtype subtype = imi.getSubtypeAt(i);
        if (subtype.overridesImplicitlyEnabledSubtype() && subtype.getMode().equals(mode)) {
            subtypes.add(subtype);
        }
    }
    return subtypes;
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) ArrayList(java.util.ArrayList)

Example 53 with InputMethodSubtype

use of android.view.inputmethod.InputMethodSubtype in project android_frameworks_base by crdroidandroid.

the class InputMethodManagerService method getCurrentInputMethodSubtypeLocked.

private InputMethodSubtype getCurrentInputMethodSubtypeLocked() {
    if (mCurMethodId == null) {
        return null;
    }
    final boolean subtypeIsSelected = mSettings.isSubtypeSelected();
    final InputMethodInfo imi = mMethodMap.get(mCurMethodId);
    if (imi == null || imi.getSubtypeCount() == 0) {
        return null;
    }
    if (!subtypeIsSelected || mCurrentSubtype == null || !InputMethodUtils.isValidSubtypeId(imi, mCurrentSubtype.hashCode())) {
        int subtypeId = mSettings.getSelectedInputMethodSubtypeId(mCurMethodId);
        if (subtypeId == NOT_A_SUBTYPE_ID) {
            // If there are no selected subtypes, the framework will try to find
            // the most applicable subtype from explicitly or implicitly enabled
            // subtypes.
            List<InputMethodSubtype> explicitlyOrImplicitlyEnabledSubtypes = mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true);
            // just returns it.
            if (explicitlyOrImplicitlyEnabledSubtypes.size() == 1) {
                mCurrentSubtype = explicitlyOrImplicitlyEnabledSubtypes.get(0);
            } else if (explicitlyOrImplicitlyEnabledSubtypes.size() > 1) {
                mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes, explicitlyOrImplicitlyEnabledSubtypes, InputMethodUtils.SUBTYPE_MODE_KEYBOARD, null, true);
                if (mCurrentSubtype == null) {
                    mCurrentSubtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes, explicitlyOrImplicitlyEnabledSubtypes, null, null, true);
                }
            }
        } else {
            mCurrentSubtype = InputMethodUtils.getSubtypes(imi).get(subtypeId);
        }
    }
    return mCurrentSubtype;
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 54 with InputMethodSubtype

use of android.view.inputmethod.InputMethodSubtype in project android_frameworks_base by crdroidandroid.

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 55 with InputMethodSubtype

use of android.view.inputmethod.InputMethodSubtype in project android_frameworks_base by crdroidandroid.

the class TextServicesManagerService method getCurrentSpellCheckerSubtype.

// TODO: Respect allowImplicitlySelectedSubtype
// TODO: Save SpellCheckerSubtype by supported languages by looking at "locale".
@Override
public SpellCheckerSubtype getCurrentSpellCheckerSubtype(String locale, boolean allowImplicitlySelectedSubtype) {
    // TODO: Make this work even for non-current users?
    if (!calledFromValidUser()) {
        return null;
    }
    final int subtypeHashCode;
    final SpellCheckerInfo sci;
    final Locale systemLocale;
    synchronized (mSpellCheckerMap) {
        subtypeHashCode = mSettings.getSelectedSpellCheckerSubtype(SpellCheckerSubtype.SUBTYPE_ID_NONE);
        if (DBG) {
            Slog.w(TAG, "getCurrentSpellCheckerSubtype: " + subtypeHashCode);
        }
        sci = getCurrentSpellChecker(null);
        systemLocale = mContext.getResources().getConfiguration().locale;
    }
    if (sci == null || sci.getSubtypeCount() == 0) {
        if (DBG) {
            Slog.w(TAG, "Subtype not found.");
        }
        return null;
    }
    if (subtypeHashCode == SpellCheckerSubtype.SUBTYPE_ID_NONE && !allowImplicitlySelectedSubtype) {
        return null;
    }
    String candidateLocale = null;
    if (subtypeHashCode == 0) {
        // Spell checker language settings == "auto"
        final InputMethodManager imm = mContext.getSystemService(InputMethodManager.class);
        if (imm != null) {
            final InputMethodSubtype currentInputMethodSubtype = imm.getCurrentInputMethodSubtype();
            if (currentInputMethodSubtype != null) {
                final String localeString = currentInputMethodSubtype.getLocale();
                if (!TextUtils.isEmpty(localeString)) {
                    // 1. Use keyboard locale if available in the spell checker
                    candidateLocale = localeString;
                }
            }
        }
        if (candidateLocale == null) {
            // 2. Use System locale if available in the spell checker
            candidateLocale = systemLocale.toString();
        }
    }
    SpellCheckerSubtype candidate = null;
    for (int i = 0; i < sci.getSubtypeCount(); ++i) {
        final SpellCheckerSubtype scs = sci.getSubtypeAt(i);
        if (subtypeHashCode == 0) {
            final String scsLocale = scs.getLocale();
            if (candidateLocale.equals(scsLocale)) {
                return scs;
            } else if (candidate == null) {
                if (candidateLocale.length() >= 2 && scsLocale.length() >= 2 && candidateLocale.startsWith(scsLocale)) {
                    // Fall back to the applicable language
                    candidate = scs;
                }
            }
        } else if (scs.hashCode() == subtypeHashCode) {
            if (DBG) {
                Slog.w(TAG, "Return subtype " + scs.hashCode() + ", input= " + locale + ", " + scs.getLocale());
            }
            // 3. Use the user specified spell check language
            return scs;
        }
    }
    // spell check languages
    return candidate;
}
Also used : Locale(java.util.Locale) SpellCheckerSubtype(android.view.textservice.SpellCheckerSubtype) InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) InputMethodManager(android.view.inputmethod.InputMethodManager) SpellCheckerInfo(android.view.textservice.SpellCheckerInfo)

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