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));
}
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);
}
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()]);
}
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;
}
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;
}
Aggregations