Search in sources :

Example 91 with InputMethodSubtype

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

the class AdditionalSubtypeUtilsTests method testRestorable.

public void testRestorable() {
    final InputMethodSubtype EN_US_DVORAK = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(Locale.US.toString(), "dvorak");
    final InputMethodSubtype ZZ_AZERTY = AdditionalSubtypeUtils.createAsciiEmojiCapableAdditionalSubtype(SubtypeLocaleUtils.NO_LANGUAGE, "azerty");
    assertEnUsDvorak(EN_US_DVORAK);
    assertAzerty(ZZ_AZERTY);
    // Make sure the subtype can be stored and restored in a deterministic manner.
    final InputMethodSubtype[] subtypes = { EN_US_DVORAK, ZZ_AZERTY };
    final String prefSubtype = AdditionalSubtypeUtils.createPrefSubtypes(subtypes);
    final InputMethodSubtype[] restoredSubtypes = AdditionalSubtypeUtils.createAdditionalSubtypesArray(prefSubtype);
    assertEquals(2, restoredSubtypes.length);
    final InputMethodSubtype restored_EN_US_DVORAK = restoredSubtypes[0];
    final InputMethodSubtype restored_ZZ_AZERTY = restoredSubtypes[1];
    assertEnUsDvorak(restored_EN_US_DVORAK);
    assertAzerty(restored_ZZ_AZERTY);
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype)

Example 92 with InputMethodSubtype

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

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

the class AdditionalSubtypeUtils method createAdditionalSubtypesArray.

public static InputMethodSubtype[] createAdditionalSubtypesArray(final String prefSubtypes) {
    if (TextUtils.isEmpty(prefSubtypes)) {
        return EMPTY_SUBTYPE_ARRAY;
    }
    final String[] prefSubtypeArray = prefSubtypes.split(PREF_SUBTYPE_SEPARATOR);
    final ArrayList<InputMethodSubtype> subtypesList = new ArrayList<>(prefSubtypeArray.length);
    for (final String prefSubtype : prefSubtypeArray) {
        final String[] elems = prefSubtype.split(LOCALE_AND_LAYOUT_SEPARATOR);
        if (elems.length != LENGTH_WITHOUT_EXTRA_VALUE && elems.length != LENGTH_WITH_EXTRA_VALUE) {
            Log.w(TAG, "Unknown additional subtype specified: " + prefSubtype + " in " + prefSubtypes);
            continue;
        }
        final String localeString = elems[INDEX_OF_LOCALE];
        final String keyboardLayoutSetName = elems[INDEX_OF_KEYBOARD_LAYOUT];
        // Here we assume that all the additional subtypes have AsciiCapable and EmojiCapable.
        // This is actually what the setting dialog for additional subtype is doing.
        final InputMethodSubtype subtype = createAsciiEmojiCapableAdditionalSubtype(localeString, keyboardLayoutSetName);
        if (subtype.getNameResId() == SubtypeLocaleUtils.UNKNOWN_KEYBOARD_LAYOUT) {
            // layout has been removed.
            continue;
        }
        subtypesList.add(subtype);
    }
    return subtypesList.toArray(new InputMethodSubtype[subtypesList.size()]);
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) ArrayList(java.util.ArrayList)

Example 94 with InputMethodSubtype

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

the class CustomInputStyleSettingsFragment method onSaveCustomInputStyle.

@Override
public void onSaveCustomInputStyle(final CustomInputStylePreference stylePref) {
    final InputMethodSubtype subtype = stylePref.getSubtype();
    if (!stylePref.hasBeenModified()) {
        return;
    }
    if (findDuplicatedSubtype(subtype) == null) {
        mRichImm.setAdditionalInputMethodSubtypes(getSubtypes());
        return;
    }
    // Saved subtype is duplicated.
    final PreferenceGroup group = getPreferenceScreen();
    group.removePreference(stylePref);
    stylePref.revert();
    group.addPreference(stylePref);
    showSubtypeAlreadyExistsToast(subtype);
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) PreferenceGroup(android.preference.PreferenceGroup)

Example 95 with InputMethodSubtype

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

the class CustomInputStyleSettingsFragment method updateCustomInputStylesSummary.

static void updateCustomInputStylesSummary(final Preference pref) {
    // When we are called from the Settings application but we are not already running, some
    // singleton and utility classes may not have been initialized.  We have to call
    // initialization method of these classes here. See {@link LatinIME#onCreate()}.
    SubtypeLocaleUtils.init(pref.getContext());
    final Resources res = pref.getContext().getResources();
    final SharedPreferences prefs = pref.getSharedPreferences();
    final String prefSubtype = Settings.readPrefAdditionalSubtypes(prefs, res);
    final InputMethodSubtype[] subtypes = AdditionalSubtypeUtils.createAdditionalSubtypesArray(prefSubtype);
    final ArrayList<String> subtypeNames = new ArrayList<>();
    for (final InputMethodSubtype subtype : subtypes) {
        subtypeNames.add(SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(subtype));
    }
    // TODO: A delimiter of custom input styles should be localized.
    pref.setSummary(TextUtils.join(", ", subtypeNames));
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) SharedPreferences(android.content.SharedPreferences) ArrayList(java.util.ArrayList) Resources(android.content.res.Resources)

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