Search in sources :

Example 71 with InputMethodSubtype

use of android.view.inputmethod.InputMethodSubtype in project platform_packages_apps_Settings by BlissRoms.

the class UserDictionaryList method getUserDictionaryLocalesSet.

@NonNull
public static TreeSet<String> getUserDictionaryLocalesSet(Context context) {
    final Cursor cursor = context.getContentResolver().query(UserDictionary.Words.CONTENT_URI, new String[] { UserDictionary.Words.LOCALE }, null, null, null);
    final TreeSet<String> localeSet = new TreeSet<>();
    if (cursor == null) {
        // The user dictionary service is not present or disabled. Return empty set.
        return localeSet;
    }
    try {
        if (cursor.moveToFirst()) {
            final int columnIndex = cursor.getColumnIndex(UserDictionary.Words.LOCALE);
            do {
                final String locale = cursor.getString(columnIndex);
                localeSet.add(null != locale ? locale : "");
            } while (cursor.moveToNext());
        }
    } finally {
        cursor.close();
    }
    // CAVEAT: Keep this for consistency of the implementation between Keyboard and Settings
    // if (!UserDictionarySettings.IS_SHORTCUT_API_SUPPORTED) {
    // // For ICS, we need to show "For all languages" in case that the keyboard locale
    // // is different from the system locale
    // localeSet.add("");
    // }
    final InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    final List<InputMethodInfo> imis = imm.getEnabledInputMethodList();
    for (final InputMethodInfo imi : imis) {
        final List<InputMethodSubtype> subtypes = imm.getEnabledInputMethodSubtypeList(imi, true);
        for (InputMethodSubtype subtype : subtypes) {
            final String locale = subtype.getLocale();
            if (!TextUtils.isEmpty(locale)) {
                localeSet.add(locale);
            }
        }
    }
    // correct to add it.
    if (!localeSet.contains(Locale.getDefault().getLanguage().toString())) {
        localeSet.add(Locale.getDefault().toString());
    }
    return localeSet;
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) TreeSet(java.util.TreeSet) InputMethodManager(android.view.inputmethod.InputMethodManager) Cursor(android.database.Cursor) InputMethodInfo(android.view.inputmethod.InputMethodInfo) NonNull(android.support.annotation.NonNull)

Example 72 with InputMethodSubtype

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

the class KeyboardLayoutSetTestsBase method getSubtype.

protected final InputMethodSubtype getSubtype(final Locale locale, final String keyboardLayout) {
    for (final InputMethodSubtype subtype : mAllSubtypesList) {
        final Locale subtypeLocale = SubtypeLocaleUtils.getSubtypeLocale(subtype);
        final String subtypeLayout = SubtypeLocaleUtils.getKeyboardLayoutSetName(subtype);
        if (locale.equals(subtypeLocale) && keyboardLayout.equals(subtypeLayout)) {
            // Found subtype that matches locale and keyboard layout.
            return subtype;
        }
    }
    for (final InputMethodSubtype subtype : getSubtypesFilteredBy(FILTER_IS_ASCII_CAPABLE)) {
        final Locale subtypeLocale = SubtypeLocaleUtils.getSubtypeLocale(subtype);
        if (locale.equals(subtypeLocale)) {
            // Create additional subtype.
            return AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(locale.toString(), keyboardLayout);
        }
    }
    throw new RuntimeException("Unknown subtype: locale=" + locale + " keyboardLayout=" + keyboardLayout);
}
Also used : Locale(java.util.Locale) RichInputMethodSubtype(com.android.inputmethod.latin.RichInputMethodSubtype) InputMethodSubtype(android.view.inputmethod.InputMethodSubtype)

Example 73 with InputMethodSubtype

use of android.view.inputmethod.InputMethodSubtype 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 74 with InputMethodSubtype

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

the class KlpActionLabelTests method testSerbianLatinActionLabel.

public void testSerbianLatinActionLabel() {
    final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
    final Locale sr_ZZ = new Locale("sr", "ZZ");
    final InputMethodSubtype srLatn = richImm.findSubtypeByLocaleAndKeyboardLayoutSet(sr_ZZ.toString(), "serbian_qwertz");
    // This is a preliminary subtype and may not exist.
    if (srLatn == null) {
        return;
    }
    // An action label should be displayed in subtype's locale regardless of the system locale.
    doTestActionKeysInLocaleWithKeyboardTextsSet(srLatn, sr_ZZ, new Locale("sr"));
    doTestActionKeysInLocaleWithKeyboardTextsSet(srLatn, sr_ZZ, Locale.US);
    doTestActionKeysInLocaleWithKeyboardTextsSet(srLatn, sr_ZZ, Locale.FRENCH);
    doTestActionKeysInLocaleWithKeyboardTextsSet(srLatn, sr_ZZ, Locale.ITALIAN);
    doTestActionKeysInLocaleWithKeyboardTextsSet(srLatn, sr_ZZ, Locale.JAPANESE);
}
Also used : Locale(java.util.Locale) RunInLocale(com.android.inputmethod.latin.utils.RunInLocale) InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) RichInputMethodManager(com.android.inputmethod.latin.RichInputMethodManager)

Example 75 with InputMethodSubtype

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

the class KlpActionLabelTests method testActionLabelInOtherLocale.

public void testActionLabelInOtherLocale() {
    final RichInputMethodManager richImm = RichInputMethodManager.getInstance();
    final InputMethodSubtype italian = richImm.findSubtypeByLocaleAndKeyboardLayoutSet(Locale.ITALIAN.toString(), SubtypeLocaleUtils.QWERTY);
    // An action label should be displayed in subtype's locale regardless of the system locale.
    doTestActionKeysInLocaleWithStringResources(italian, Locale.ITALIAN, Locale.US);
    doTestActionKeysInLocaleWithStringResources(italian, Locale.ITALIAN, Locale.FRENCH);
    doTestActionKeysInLocaleWithStringResources(italian, Locale.ITALIAN, Locale.ITALIAN);
    doTestActionKeysInLocaleWithStringResources(italian, Locale.ITALIAN, Locale.JAPANESE);
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) RichInputMethodManager(com.android.inputmethod.latin.RichInputMethodManager)

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