Search in sources :

Example 46 with InputMethodSubtype

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

the class InputMethodSubtypeSwitchingControllerTest method assertNextInputMethod.

private void assertNextInputMethod(final ControllerImpl controller, final boolean onlyCurrentIme, final ImeSubtypeListItem currentItem, final ImeSubtypeListItem nextItem, final ImeSubtypeListItem prevItem) {
    InputMethodSubtype subtype = null;
    if (currentItem.mSubtypeName != null) {
        subtype = createDummySubtype(currentItem.mSubtypeName.toString());
    }
    final ImeSubtypeListItem nextIme = controller.getNextInputMethod(onlyCurrentIme, currentItem.mImi, subtype, true);
    assertEquals(nextItem, nextIme);
    final ImeSubtypeListItem prevIme = controller.getNextInputMethod(onlyCurrentIme, currentItem.mImi, subtype, false);
    assertEquals(prevItem, prevIme);
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) ImeSubtypeListItem(com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem)

Example 47 with InputMethodSubtype

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

the class InputMethodSubtypeSwitchingControllerTest method addDummyImeSubtypeListItems.

private static void addDummyImeSubtypeListItems(List<ImeSubtypeListItem> items, String imeName, String imeLabel, List<String> subtypeLocales, boolean supportsSwitchingToNextInputMethod) {
    final ResolveInfo ri = new ResolveInfo();
    final ServiceInfo si = new ServiceInfo();
    final ApplicationInfo ai = new ApplicationInfo();
    ai.packageName = DUMMY_PACKAGE_NAME;
    ai.enabled = true;
    si.applicationInfo = ai;
    si.enabled = true;
    si.packageName = DUMMY_PACKAGE_NAME;
    si.name = imeName;
    si.exported = true;
    si.nonLocalizedLabel = imeLabel;
    ri.serviceInfo = si;
    List<InputMethodSubtype> subtypes = null;
    if (subtypeLocales != null) {
        subtypes = new ArrayList<>();
        for (String subtypeLocale : subtypeLocales) {
            subtypes.add(createDummySubtype(subtypeLocale));
        }
    }
    final InputMethodInfo imi = new InputMethodInfo(ri, DUMMY_IS_AUX_IME, DUMMY_SETTING_ACTIVITY_NAME, subtypes, DUMMY_IS_DEFAULT_RES_ID, DUMMY_FORCE_DEFAULT, supportsSwitchingToNextInputMethod);
    if (subtypes == null) {
        items.add(new ImeSubtypeListItem(imeName, null, /* variableName */
        imi, NOT_A_SUBTYPE_ID, null, SYSTEM_LOCALE));
    } else {
        for (int i = 0; i < subtypes.size(); ++i) {
            final String subtypeLocale = subtypeLocales.get(i);
            items.add(new ImeSubtypeListItem(imeName, subtypeLocale, imi, i, subtypeLocale, SYSTEM_LOCALE));
        }
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ServiceInfo(android.content.pm.ServiceInfo) InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) ApplicationInfo(android.content.pm.ApplicationInfo) InputMethodInfo(android.view.inputmethod.InputMethodInfo) ImeSubtypeListItem(com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem)

Example 48 with InputMethodSubtype

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

the class InputMethodSubtypeSwitchingControllerTest method assertNextInputMethod.

private void assertNextInputMethod(final ControllerImpl controller, final boolean onlyCurrentIme, final ImeSubtypeListItem currentItem, final ImeSubtypeListItem nextItem, final ImeSubtypeListItem prevItem) {
    InputMethodSubtype subtype = null;
    if (currentItem.mSubtypeName != null) {
        subtype = createDummySubtype(currentItem.mSubtypeName.toString());
    }
    final ImeSubtypeListItem nextIme = controller.getNextInputMethod(onlyCurrentIme, currentItem.mImi, subtype, true);
    assertEquals(nextItem, nextIme);
    final ImeSubtypeListItem prevIme = controller.getNextInputMethod(onlyCurrentIme, currentItem.mImi, subtype, false);
    assertEquals(prevItem, prevIme);
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) ImeSubtypeListItem(com.android.internal.inputmethod.InputMethodSubtypeSwitchingController.ImeSubtypeListItem)

Example 49 with InputMethodSubtype

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

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

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

the class InputMethodUtils method getImplicitlyApplicableSubtypesLockedImpl.

private static ArrayList<InputMethodSubtype> getImplicitlyApplicableSubtypesLockedImpl(Resources res, InputMethodInfo imi) {
    final List<InputMethodSubtype> subtypes = InputMethodUtils.getSubtypes(imi);
    final LocaleList systemLocales = res.getConfiguration().getLocales();
    final String systemLocale = systemLocales.get(0).toString();
    if (TextUtils.isEmpty(systemLocale))
        return new ArrayList<>();
    final int numSubtypes = subtypes.size();
    // Handle overridesImplicitlyEnabledSubtype mechanism.
    final HashMap<String, InputMethodSubtype> applicableModeAndSubtypesMap = new HashMap<>();
    for (int i = 0; i < numSubtypes; ++i) {
        // scan overriding implicitly enabled subtypes.
        final InputMethodSubtype subtype = subtypes.get(i);
        if (subtype.overridesImplicitlyEnabledSubtype()) {
            final String mode = subtype.getMode();
            if (!applicableModeAndSubtypesMap.containsKey(mode)) {
                applicableModeAndSubtypesMap.put(mode, subtype);
            }
        }
    }
    if (applicableModeAndSubtypesMap.size() > 0) {
        return new ArrayList<>(applicableModeAndSubtypesMap.values());
    }
    final HashMap<String, ArrayList<InputMethodSubtype>> nonKeyboardSubtypesMap = new HashMap<>();
    final ArrayList<InputMethodSubtype> keyboardSubtypes = new ArrayList<>();
    for (int i = 0; i < numSubtypes; ++i) {
        final InputMethodSubtype subtype = subtypes.get(i);
        final String mode = subtype.getMode();
        if (SUBTYPE_MODE_KEYBOARD.equals(mode)) {
            keyboardSubtypes.add(subtype);
        } else {
            if (!nonKeyboardSubtypesMap.containsKey(mode)) {
                nonKeyboardSubtypesMap.put(mode, new ArrayList<>());
            }
            nonKeyboardSubtypesMap.get(mode).add(subtype);
        }
    }
    final ArrayList<InputMethodSubtype> applicableSubtypes = new ArrayList<>();
    LocaleUtils.filterByLanguage(keyboardSubtypes, sSubtypeToLocale, systemLocales, applicableSubtypes);
    if (!applicableSubtypes.isEmpty()) {
        boolean hasAsciiCapableKeyboard = false;
        final int numApplicationSubtypes = applicableSubtypes.size();
        for (int i = 0; i < numApplicationSubtypes; ++i) {
            final InputMethodSubtype subtype = applicableSubtypes.get(i);
            if (subtype.containsExtraValueKey(TAG_ASCII_CAPABLE)) {
                hasAsciiCapableKeyboard = true;
                break;
            }
        }
        if (!hasAsciiCapableKeyboard) {
            final int numKeyboardSubtypes = keyboardSubtypes.size();
            for (int i = 0; i < numKeyboardSubtypes; ++i) {
                final InputMethodSubtype subtype = keyboardSubtypes.get(i);
                final String mode = subtype.getMode();
                if (SUBTYPE_MODE_KEYBOARD.equals(mode) && subtype.containsExtraValueKey(TAG_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE)) {
                    applicableSubtypes.add(subtype);
                }
            }
        }
    }
    if (applicableSubtypes.isEmpty()) {
        InputMethodSubtype lastResortKeyboardSubtype = findLastResortApplicableSubtypeLocked(res, subtypes, SUBTYPE_MODE_KEYBOARD, systemLocale, true);
        if (lastResortKeyboardSubtype != null) {
            applicableSubtypes.add(lastResortKeyboardSubtype);
        }
    }
    // For each non-keyboard mode, extract subtypes with system locales.
    for (final ArrayList<InputMethodSubtype> subtypeList : nonKeyboardSubtypesMap.values()) {
        LocaleUtils.filterByLanguage(subtypeList, sSubtypeToLocale, systemLocales, applicableSubtypes);
    }
    return applicableSubtypes;
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) LocaleList(android.os.LocaleList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

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