Search in sources :

Example 36 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)

Example 37 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 38 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 39 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 40 with InputMethodSubtype

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

the class RichInputMethodManager method switchToNextInputSubtypeInThisIme.

private boolean switchToNextInputSubtypeInThisIme(final IBinder token, final boolean onlyCurrentIme) {
    final InputMethodManager imm = mImmWrapper.mImm;
    final InputMethodSubtype currentSubtype = imm.getCurrentInputMethodSubtype();
    final List<InputMethodSubtype> enabledSubtypes = getMyEnabledInputMethodSubtypeList(true);
    final int currentIndex = getSubtypeIndexInList(currentSubtype, enabledSubtypes);
    if (currentIndex == INDEX_NOT_FOUND) {
        Log.w(TAG, "Can't find current subtype in enabled subtypes: subtype=" + SubtypeLocaleUtils.getSubtypeNameForLogging(currentSubtype));
        return false;
    }
    final int nextIndex = (currentIndex + 1) % enabledSubtypes.size();
    if (nextIndex <= currentIndex && !onlyCurrentIme) {
        // next IME.
        return false;
    }
    final InputMethodSubtype nextSubtype = enabledSubtypes.get(nextIndex);
    setInputMethodAndSubtype(token, nextSubtype);
    return true;
}
Also used : InputMethodSubtype(android.view.inputmethod.InputMethodSubtype) InputMethodManager(android.view.inputmethod.InputMethodManager)

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