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