Search in sources :

Example 1 with RichInputMethodSubtype

use of com.android.inputmethod.latin.RichInputMethodSubtype in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class LanguageOnSpacebarUtils method getLanguageOnSpacebarFormatType.

public static int getLanguageOnSpacebarFormatType(@Nonnull final RichInputMethodSubtype subtype) {
    if (subtype.isNoLanguage()) {
        return FORMAT_TYPE_FULL_LOCALE;
    }
    // Only this subtype is enabled and equals to the system locale.
    if (sEnabledSubtypes.size() < 2 && sIsSystemLanguageSameAsInputLanguage) {
        return FORMAT_TYPE_NONE;
    }
    final Locale locale = subtype.getLocale();
    if (locale == null) {
        return FORMAT_TYPE_NONE;
    }
    final String keyboardLanguage = locale.getLanguage();
    final String keyboardLayout = subtype.getKeyboardLayoutSetName();
    int sameLanguageAndLayoutCount = 0;
    for (final InputMethodSubtype ims : sEnabledSubtypes) {
        final String language = SubtypeLocaleUtils.getSubtypeLocale(ims).getLanguage();
        if (keyboardLanguage.equals(language) && keyboardLayout.equals(SubtypeLocaleUtils.getKeyboardLayoutSetName(ims))) {
            sameLanguageAndLayoutCount++;
        }
    }
    // locale and keyboard layout. Otherwise displaying language name is enough.
    return sameLanguageAndLayoutCount > 1 ? FORMAT_TYPE_FULL_LOCALE : FORMAT_TYPE_LANGUAGE_ONLY;
}
Also used : Locale(java.util.Locale) InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) RichInputMethodSubtype(com.android.inputmethod.latin.RichInputMethodSubtype)

Example 2 with RichInputMethodSubtype

use of com.android.inputmethod.latin.RichInputMethodSubtype in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class RichInputMethodSubtypeTests method testAllMiddleDisplayNameForSpacebar.

public void testAllMiddleDisplayNameForSpacebar() {
    for (final RichInputMethodSubtype subtype : mSubtypesList) {
        final String subtypeName = SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(subtype.getRawSubtype());
        final Locale locale = subtype.getLocale();
        final Locale displayLocale = SubtypeLocaleUtils.getDisplayLocaleOfSubtypeLocale(locale.toString());
        if (Locale.ROOT.equals(displayLocale)) {
            // the locale to be displayed on the spacebar (for example Hinglish).
            continue;
        }
        final String spacebarText = subtype.getMiddleDisplayName();
        if (subtype.isNoLanguage()) {
            assertEquals(subtypeName, SubtypeLocaleUtils.getKeyboardLayoutSetDisplayName(subtype.getRawSubtype()), spacebarText);
        } else {
            assertEquals(subtypeName, SubtypeLocaleUtils.getSubtypeLanguageDisplayName(locale.toString()), spacebarText);
        }
    }
}
Also used : Locale(java.util.Locale) RunInLocale(com.android.inputmethod.latin.utils.RunInLocale) RichInputMethodSubtype(com.android.inputmethod.latin.RichInputMethodSubtype)

Example 3 with RichInputMethodSubtype

use of com.android.inputmethod.latin.RichInputMethodSubtype in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class SubtypeLocaleUtilsTests method testAllFullDisplayName.

public void testAllFullDisplayName() {
    for (final RichInputMethodSubtype subtype : mSubtypesList) {
        final String subtypeName = SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(subtype.getRawSubtype());
        if (subtype.isNoLanguage()) {
            final String layoutName = SubtypeLocaleUtils.getKeyboardLayoutSetDisplayName(subtype.getRawSubtype());
            assertTrue(subtypeName, subtypeName.contains(layoutName));
        } else {
            final String languageName = SubtypeLocaleUtils.getSubtypeLocaleDisplayNameInSystemLocale(subtype.getLocale().toString());
            assertTrue(subtypeName, subtypeName.contains(languageName));
        }
    }
}
Also used : RichInputMethodSubtype(com.android.inputmethod.latin.RichInputMethodSubtype)

Example 4 with RichInputMethodSubtype

use of com.android.inputmethod.latin.RichInputMethodSubtype in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class SubtypeLocaleUtilsTests method testIsRtlLanguage.

public void testIsRtlLanguage() {
    // Known Right-to-Left language subtypes.
    final InputMethodSubtype ARABIC = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet("ar", "arabic");
    assertNotNull("Arabic", ARABIC);
    final InputMethodSubtype FARSI = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet("fa", "farsi");
    assertNotNull("Farsi", FARSI);
    final InputMethodSubtype HEBREW = mRichImm.findSubtypeByLocaleAndKeyboardLayoutSet("iw", "hebrew");
    assertNotNull("Hebrew", HEBREW);
    for (final RichInputMethodSubtype subtype : mSubtypesList) {
        final InputMethodSubtype rawSubtype = subtype.getRawSubtype();
        final String subtypeName = SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(rawSubtype);
        if (rawSubtype.equals(ARABIC) || rawSubtype.equals(FARSI) || rawSubtype.equals(HEBREW)) {
            assertTrue(subtypeName, subtype.isRtlSubtype());
        } else {
            assertFalse(subtypeName, subtype.isRtlSubtype());
        }
    }
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) RichInputMethodSubtype(com.android.inputmethod.latin.RichInputMethodSubtype) RichInputMethodSubtype(com.android.inputmethod.latin.RichInputMethodSubtype)

Example 5 with RichInputMethodSubtype

use of com.android.inputmethod.latin.RichInputMethodSubtype in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class RichInputMethodSubtypeTests method testRichInputMethodSubtypeForNullInputMethodSubtype.

public void testRichInputMethodSubtypeForNullInputMethodSubtype() {
    RichInputMethodSubtype subtype = RichInputMethodSubtype.getRichInputMethodSubtype(null);
    assertNotNull(subtype);
    assertEquals("zz", subtype.getRawSubtype().getLocale());
    assertEquals("keyboard", subtype.getRawSubtype().getMode());
}
Also used : RichInputMethodSubtype(com.android.inputmethod.latin.RichInputMethodSubtype)

Aggregations

RichInputMethodSubtype (com.android.inputmethod.latin.RichInputMethodSubtype)10 InputMethodSubtype (android.view.inputmethod.InputMethodSubtype)5 Context (android.content.Context)3 InputMethodInfo (android.view.inputmethod.InputMethodInfo)2 Locale (java.util.Locale)2 RunInLocale (com.android.inputmethod.latin.utils.RunInLocale)1 ArrayList (java.util.ArrayList)1