Search in sources :

Example 16 with InputMethodSubtype

use of android.view.inputmethod.InputMethodSubtype in project platform_frameworks_base by android.

the class InputMethodManagerService method findLastResortApplicableShortcutInputMethodAndSubtypeLocked.

// If there are no selected shortcuts, tries finding the most applicable ones.
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);
        }
        // 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);
        }
        // 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<>(mostApplicableIMI, mostApplicableSubtype);
    } else {
        return null;
    }
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) InputMethodInfo(android.view.inputmethod.InputMethodInfo) Pair(android.util.Pair)

Example 17 with InputMethodSubtype

use of android.view.inputmethod.InputMethodSubtype in project platform_frameworks_base by android.

the class InputMethodManagerService method getShortcutInputMethodsAndSubtypes.

// TODO: We should change the return type from List to List<Parcelable>
@SuppressWarnings("rawtypes")
@Override
public List getShortcutInputMethodsAndSubtypes() {
    synchronized (mMethodMap) {
        ArrayList<Object> ret = new ArrayList<>();
        if (mShortcutInputMethodsAndSubtypes.size() == 0) {
            // If there are no selected shortcut subtypes, the framework will try to find
            // the most applicable subtype from all subtypes whose mode is
            // SUBTYPE_MODE_VOICE. This is an exceptional case, so we will hardcode the mode.
            Pair<InputMethodInfo, InputMethodSubtype> info = findLastResortApplicableShortcutInputMethodAndSubtypeLocked(InputMethodUtils.SUBTYPE_MODE_VOICE);
            if (info != null) {
                ret.add(info.first);
                ret.add(info.second);
            }
            return ret;
        }
        for (InputMethodInfo imi : mShortcutInputMethodsAndSubtypes.keySet()) {
            ret.add(imi);
            for (InputMethodSubtype subtype : mShortcutInputMethodsAndSubtypes.get(imi)) {
                ret.add(subtype);
            }
        }
        return ret;
    }
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) ArrayList(java.util.ArrayList) InputMethodInfo(android.view.inputmethod.InputMethodInfo)

Example 18 with InputMethodSubtype

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

the class InputMethodUtilsTest method verifyEquality.

private static void verifyEquality(InputMethodInfo expected, InputMethodInfo actual) {
    assertEquals(expected, actual);
    assertEquals(expected.getSubtypeCount(), actual.getSubtypeCount());
    for (int subtypeIndex = 0; subtypeIndex < expected.getSubtypeCount(); ++subtypeIndex) {
        final InputMethodSubtype expectedSubtype = expected.getSubtypeAt(subtypeIndex);
        final InputMethodSubtype actualSubtype = actual.getSubtypeAt(subtypeIndex);
        verifyEquality(expectedSubtype, actualSubtype);
    }
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype)

Example 19 with InputMethodSubtype

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

the class InputMethodUtilsTest method testGetImplicitlyApplicableSubtypesLocked.

@SmallTest
public void testGetImplicitlyApplicableSubtypesLocked() throws Exception {
    final InputMethodSubtype nonAutoEnUS = createDummyInputMethodSubtype("en_US", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
    final InputMethodSubtype nonAutoEnGB = createDummyInputMethodSubtype("en_GB", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, IS_ASCII_CAPABLE, IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
    final InputMethodSubtype nonAutoEnIN = createDummyInputMethodSubtype("en_IN", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, IS_ASCII_CAPABLE, IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
    final InputMethodSubtype nonAutoFrCA = createDummyInputMethodSubtype("fr_CA", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, IS_ASCII_CAPABLE, IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
    final InputMethodSubtype nonAutoFr = createDummyInputMethodSubtype("fr_CA", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, IS_ASCII_CAPABLE, IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
    final InputMethodSubtype nonAutoFil = createDummyInputMethodSubtype("fil", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
    final InputMethodSubtype nonAutoIn = createDummyInputMethodSubtype("in", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, IS_ASCII_CAPABLE, IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
    final InputMethodSubtype nonAutoId = createDummyInputMethodSubtype("id", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, IS_ASCII_CAPABLE, IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
    final InputMethodSubtype autoSubtype = createDummyInputMethodSubtype("auto", SUBTYPE_MODE_KEYBOARD, !IS_AUX, IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
    final InputMethodSubtype nonAutoJa = createDummyInputMethodSubtype("ja", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
    final InputMethodSubtype nonAutoHi = createDummyInputMethodSubtype("hi", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
    final InputMethodSubtype nonAutoSrCyrl = createDummyInputMethodSubtype("sr", "sr-Cyrl", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
    final InputMethodSubtype nonAutoSrLatn = createDummyInputMethodSubtype("sr_ZZ", "sr-Latn", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
    final InputMethodSubtype nonAutoHandwritingEn = createDummyInputMethodSubtype("en", SUBTYPE_MODE_HANDWRITING, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
    final InputMethodSubtype nonAutoHandwritingFr = createDummyInputMethodSubtype("fr", SUBTYPE_MODE_HANDWRITING, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
    final InputMethodSubtype nonAutoHandwritingSrCyrl = createDummyInputMethodSubtype("sr", "sr-Cyrl", SUBTYPE_MODE_HANDWRITING, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
    final InputMethodSubtype nonAutoHandwritingSrLatn = createDummyInputMethodSubtype("sr_ZZ", "sr-Latn", SUBTYPE_MODE_HANDWRITING, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, !IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
    final InputMethodSubtype nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype = createDummyInputMethodSubtype("zz", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
    final InputMethodSubtype nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype2 = createDummyInputMethodSubtype("zz", SUBTYPE_MODE_KEYBOARD, !IS_AUX, !IS_OVERRIDES_IMPLICITLY_ENABLED_SUBTYPE, !IS_ASCII_CAPABLE, IS_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE);
    // Make sure that an automatic subtype (overridesImplicitlyEnabledSubtype:true) is
    // selected no matter what locale is specified.
    {
        final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
        subtypes.add(nonAutoEnUS);
        subtypes.add(nonAutoEnGB);
        subtypes.add(nonAutoJa);
        subtypes.add(nonAutoFil);
        // overridesImplicitlyEnabledSubtype == true
        subtypes.add(autoSubtype);
        subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype);
        subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype2);
        subtypes.add(nonAutoHandwritingEn);
        subtypes.add(nonAutoHandwritingFr);
        final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
        final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_EN_US), imi);
        assertEquals(1, result.size());
        verifyEquality(autoSubtype, result.get(0));
    }
    // Make sure that a subtype whose locale is exactly equal to the specified locale is
    // selected as long as there is no no automatic subtype
    // (overridesImplicitlyEnabledSubtype:true) in the given list.
    {
        final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
        // locale == "en_US"
        subtypes.add(nonAutoEnUS);
        subtypes.add(nonAutoEnGB);
        subtypes.add(nonAutoJa);
        subtypes.add(nonAutoFil);
        subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype);
        subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype2);
        subtypes.add(nonAutoHandwritingEn);
        subtypes.add(nonAutoHandwritingFr);
        final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
        final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_EN_US), imi);
        assertEquals(2, result.size());
        verifyEquality(nonAutoEnUS, result.get(0));
        verifyEquality(nonAutoHandwritingEn, result.get(1));
    }
    // Make sure that a subtype whose locale is exactly equal to the specified locale is
    // selected as long as there is no automatic subtype
    // (overridesImplicitlyEnabledSubtype:true) in the given list.
    {
        final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
        subtypes.add(nonAutoEnUS);
        // locale == "en_GB"
        subtypes.add(nonAutoEnGB);
        subtypes.add(nonAutoJa);
        subtypes.add(nonAutoFil);
        subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype);
        subtypes.add(nonAutoHandwritingEn);
        subtypes.add(nonAutoHandwritingFr);
        final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
        final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_EN_GB), imi);
        assertEquals(2, result.size());
        verifyEquality(nonAutoEnGB, result.get(0));
        verifyEquality(nonAutoHandwritingEn, result.get(1));
    }
    // If there is no automatic subtype (overridesImplicitlyEnabledSubtype:true) and
    // any subtype whose locale is exactly equal to the specified locale in the given list,
    // try to find a subtype whose language is equal to the language part of the given locale.
    // Here make sure that a subtype (locale: "fr_CA") can be found with locale: "fr".
    {
        final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
        // locale == "fr_CA"
        subtypes.add(nonAutoFrCA);
        subtypes.add(nonAutoJa);
        subtypes.add(nonAutoFil);
        subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype);
        subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype2);
        subtypes.add(nonAutoHandwritingEn);
        subtypes.add(nonAutoHandwritingFr);
        final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
        final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_FR), imi);
        assertEquals(2, result.size());
        verifyEquality(nonAutoFrCA, result.get(0));
        verifyEquality(nonAutoHandwritingFr, result.get(1));
    }
    // Then make sure that a subtype (locale: "fr") can be found with locale: "fr_CA".
    {
        final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
        // locale == "fr"
        subtypes.add(nonAutoFr);
        subtypes.add(nonAutoJa);
        subtypes.add(nonAutoFil);
        subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype);
        subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype2);
        subtypes.add(nonAutoHandwritingEn);
        subtypes.add(nonAutoHandwritingFr);
        final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
        final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_FR_CA), imi);
        assertEquals(2, result.size());
        verifyEquality(nonAutoFrCA, result.get(0));
        verifyEquality(nonAutoHandwritingFr, result.get(1));
    }
    // Make sure that subtypes which have "EnabledWhenDefaultIsNotAsciiCapable" in its
    // extra value is selected if and only if all other selected IMEs are not AsciiCapable.
    {
        final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
        subtypes.add(nonAutoEnUS);
        // not ASCII capable
        subtypes.add(nonAutoJa);
        subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype);
        subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype2);
        subtypes.add(nonAutoHandwritingEn);
        subtypes.add(nonAutoHandwritingFr);
        final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
        final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_JA_JP), imi);
        assertEquals(3, result.size());
        verifyEquality(nonAutoJa, result.get(0));
        verifyEquality(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype, result.get(1));
        verifyEquality(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype2, result.get(2));
    }
    // Make sure that if there is no subtype that matches the language requested, then we just
    // use the first keyboard subtype.
    {
        final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
        subtypes.add(nonAutoHi);
        subtypes.add(nonAutoEnUS);
        subtypes.add(nonAutoHandwritingEn);
        subtypes.add(nonAutoHandwritingFr);
        subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype);
        final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
        final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_JA_JP), imi);
        assertEquals(1, result.size());
        verifyEquality(nonAutoHi, result.get(0));
    }
    {
        final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
        subtypes.add(nonAutoEnUS);
        subtypes.add(nonAutoHi);
        subtypes.add(nonAutoHandwritingEn);
        subtypes.add(nonAutoHandwritingFr);
        subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype);
        final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
        final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_JA_JP), imi);
        assertEquals(1, result.size());
        verifyEquality(nonAutoEnUS, result.get(0));
    }
    {
        final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
        subtypes.add(nonAutoHandwritingEn);
        subtypes.add(nonAutoHandwritingFr);
        subtypes.add(nonAutoEnUS);
        subtypes.add(nonAutoHi);
        subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype);
        final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
        final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_JA_JP), imi);
        assertEquals(1, result.size());
        verifyEquality(nonAutoEnUS, result.get(0));
    }
    // Make sure that both language and script are taken into account to find the best matching
    // subtype.
    {
        final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
        subtypes.add(nonAutoEnUS);
        subtypes.add(nonAutoSrCyrl);
        subtypes.add(nonAutoSrLatn);
        subtypes.add(nonAutoHandwritingEn);
        subtypes.add(nonAutoHandwritingFr);
        subtypes.add(nonAutoHandwritingSrCyrl);
        subtypes.add(nonAutoHandwritingSrLatn);
        final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
        final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(Locale.forLanguageTag("sr-Latn-RS")), imi);
        assertEquals(2, result.size());
        assertThat(nonAutoSrLatn, isIn(result));
        assertThat(nonAutoHandwritingSrLatn, isIn(result));
    }
    {
        final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
        subtypes.add(nonAutoEnUS);
        subtypes.add(nonAutoSrCyrl);
        subtypes.add(nonAutoSrLatn);
        subtypes.add(nonAutoHandwritingEn);
        subtypes.add(nonAutoHandwritingFr);
        subtypes.add(nonAutoHandwritingSrCyrl);
        subtypes.add(nonAutoHandwritingSrLatn);
        final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
        final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(Locale.forLanguageTag("sr-Cyrl-RS")), imi);
        assertEquals(2, result.size());
        assertThat(nonAutoSrCyrl, isIn(result));
        assertThat(nonAutoHandwritingSrCyrl, isIn(result));
    }
    // Make sure that secondary locales are taken into account to find the best matching
    // subtype.
    {
        final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
        subtypes.add(nonAutoEnUS);
        subtypes.add(nonAutoEnGB);
        subtypes.add(nonAutoSrCyrl);
        subtypes.add(nonAutoSrLatn);
        subtypes.add(nonAutoFr);
        subtypes.add(nonAutoFrCA);
        subtypes.add(nonAutoHandwritingEn);
        subtypes.add(nonAutoHandwritingFr);
        subtypes.add(nonAutoHandwritingSrCyrl);
        subtypes.add(nonAutoHandwritingSrLatn);
        final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
        final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(Locale.forLanguageTag("sr-Latn-RS-x-android"), Locale.forLanguageTag("ja-JP"), Locale.forLanguageTag("fr-FR"), Locale.forLanguageTag("en-GB"), Locale.forLanguageTag("en-US")), imi);
        assertEquals(6, result.size());
        assertThat(nonAutoEnGB, isIn(result));
        assertThat(nonAutoFr, isIn(result));
        assertThat(nonAutoSrLatn, isIn(result));
        assertThat(nonAutoHandwritingEn, isIn(result));
        assertThat(nonAutoHandwritingFr, isIn(result));
        assertThat(nonAutoHandwritingSrLatn, isIn(result));
    }
    // Make sure that 3-letter language code can be handled.
    {
        final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
        subtypes.add(nonAutoEnUS);
        subtypes.add(nonAutoFil);
        final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
        final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_FIL_PH), imi);
        assertEquals(1, result.size());
        verifyEquality(nonAutoFil, result.get(0));
    }
    // Make sure that we never end up matching "fi" (finnish) with "fil" (filipino).
    // Also make sure that the first subtype will be used as the last-resort candidate.
    {
        final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
        subtypes.add(nonAutoJa);
        subtypes.add(nonAutoEnUS);
        subtypes.add(nonAutoFil);
        final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
        final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_FI), imi);
        assertEquals(1, result.size());
        verifyEquality(nonAutoJa, result.get(0));
    }
    // Make sure that "in" and "id" conversion is taken into account.
    {
        final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
        subtypes.add(nonAutoIn);
        subtypes.add(nonAutoEnUS);
        final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
        final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_IN), imi);
        assertEquals(1, result.size());
        verifyEquality(nonAutoIn, result.get(0));
    }
    {
        final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
        subtypes.add(nonAutoIn);
        subtypes.add(nonAutoEnUS);
        final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
        final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_ID), imi);
        assertEquals(1, result.size());
        verifyEquality(nonAutoIn, result.get(0));
    }
    {
        final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
        subtypes.add(nonAutoId);
        subtypes.add(nonAutoEnUS);
        final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
        final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_IN), imi);
        assertEquals(1, result.size());
        verifyEquality(nonAutoId, result.get(0));
    }
    {
        final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
        subtypes.add(nonAutoId);
        subtypes.add(nonAutoEnUS);
        final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
        final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_ID), imi);
        assertEquals(1, result.size());
        verifyEquality(nonAutoId, result.get(0));
    }
    // If there is no automatic subtype (overridesImplicitlyEnabledSubtype:true) and the system
    // provides multiple locales, we try to enable multiple subtypes.
    {
        final ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
        subtypes.add(nonAutoEnUS);
        subtypes.add(nonAutoFrCA);
        subtypes.add(nonAutoIn);
        subtypes.add(nonAutoJa);
        subtypes.add(nonAutoFil);
        subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype);
        subtypes.add(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype2);
        final InputMethodInfo imi = createDummyInputMethodInfo("com.android.apps.inputmethod.latin", "com.android.apps.inputmethod.latin", "DummyLatinIme", !IS_AUX, IS_DEFAULT, subtypes);
        final ArrayList<InputMethodSubtype> result = InputMethodUtils.getImplicitlyApplicableSubtypesLocked(getResourcesForLocales(LOCALE_FR, LOCALE_EN_US, LOCALE_JA_JP), imi);
        assertThat(nonAutoFrCA, isIn(result));
        assertThat(nonAutoEnUS, isIn(result));
        assertThat(nonAutoJa, isIn(result));
        assertThat(nonAutoIn, not(isIn(result)));
        assertThat(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype, not(isIn(result)));
        assertThat(nonAutoEnabledWhenDefaultIsNotAsciiCalableSubtype, not(isIn(result)));
    }
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) ArrayList(java.util.ArrayList) InputMethodInfo(android.view.inputmethod.InputMethodInfo) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 20 with InputMethodSubtype

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

the class InputMethodSubtypeSwitchingControllerTest method onUserAction.

private void onUserAction(final ControllerImpl controller, final ImeSubtypeListItem subtypeListItem) {
    InputMethodSubtype subtype = null;
    if (subtypeListItem.mSubtypeName != null) {
        subtype = createDummySubtype(subtypeListItem.mSubtypeName.toString());
    }
    controller.onUserActionLocked(subtypeListItem.mImi, subtype);
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype)

Aggregations

InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)195 InputMethodInfo (android.view.inputmethod.InputMethodInfo)92 ArrayList (java.util.ArrayList)48 Locale (java.util.Locale)17 LocaleList (android.os.LocaleList)15 ImeSubtypeListItem (com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem)15 InputMethodManager (android.view.inputmethod.InputMethodManager)14 Context (android.content.Context)12 SmallTest (android.test.suitebuilder.annotation.SmallTest)10 View (android.view.View)9 TextView (android.widget.TextView)9 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 PendingIntent (android.app.PendingIntent)6 DialogInterface (android.content.DialogInterface)6 OnCancelListener (android.content.DialogInterface.OnCancelListener)6 TypedArray (android.content.res.TypedArray)6