use of android.view.inputmethod.InputMethodSubtype in project android_frameworks_base by DirtyUnicorns.
the class InputMethodUtils method findLastResortApplicableSubtypeLocked.
/**
* If there are no selected subtypes, tries finding the most applicable one according to the
* given locale.
* @param subtypes this function will search the most applicable subtype in subtypes
* @param mode subtypes will be filtered by mode
* @param locale subtypes will be filtered by locale
* @param canIgnoreLocaleAsLastResort if this function can't find the most applicable subtype,
* it will return the first subtype matched with mode
* @return the most applicable subtypeId
*/
public static InputMethodSubtype findLastResortApplicableSubtypeLocked(Resources res, List<InputMethodSubtype> subtypes, String mode, String locale, boolean canIgnoreLocaleAsLastResort) {
if (subtypes == null || subtypes.size() == 0) {
return null;
}
if (TextUtils.isEmpty(locale)) {
locale = res.getConfiguration().locale.toString();
}
final String language = getLanguageFromLocaleString(locale);
boolean partialMatchFound = false;
InputMethodSubtype applicableSubtype = null;
InputMethodSubtype firstMatchedModeSubtype = null;
final int N = subtypes.size();
for (int i = 0; i < N; ++i) {
InputMethodSubtype subtype = subtypes.get(i);
final String subtypeLocale = subtype.getLocale();
final String subtypeLanguage = getLanguageFromLocaleString(subtypeLocale);
// and all subtypes with all modes can be candidates.
if (mode == null || subtypes.get(i).getMode().equalsIgnoreCase(mode)) {
if (firstMatchedModeSubtype == null) {
firstMatchedModeSubtype = subtype;
}
if (locale.equals(subtypeLocale)) {
// Exact match (e.g. system locale is "en_US" and subtype locale is "en_US")
applicableSubtype = subtype;
break;
} else if (!partialMatchFound && language.equals(subtypeLanguage)) {
// Partial match (e.g. system locale is "en_US" and subtype locale is "en")
applicableSubtype = subtype;
partialMatchFound = true;
}
}
}
if (applicableSubtype == null && canIgnoreLocaleAsLastResort) {
return firstMatchedModeSubtype;
}
// subtype.
if (DEBUG) {
if (applicableSubtype != null) {
Slog.d(TAG, "Applicable InputMethodSubtype was found: " + applicableSubtype.getMode() + "," + applicableSubtype.getLocale());
}
}
return applicableSubtype;
}
use of android.view.inputmethod.InputMethodSubtype in project android_frameworks_base by DirtyUnicorns.
the class InputMethodManagerService method findLastResortApplicableShortcutInputMethodAndSubtypeLocked.
// If there are no selected shortcuts, tries finding the most applicable ones.
private Pair<InputMethodInfo, InputMethodSubtype> findLastResortApplicableShortcutInputMethodAndSubtypeLocked(String mode) {
List<InputMethodInfo> imis = mSettings.getEnabledInputMethodListLocked();
InputMethodInfo mostApplicableIMI = null;
InputMethodSubtype mostApplicableSubtype = null;
boolean foundInSystemIME = false;
// Search applicable subtype for each InputMethodInfo
for (InputMethodInfo imi : imis) {
final String imiId = imi.getId();
if (foundInSystemIME && !imiId.equals(mCurMethodId)) {
continue;
}
InputMethodSubtype subtype = null;
final List<InputMethodSubtype> enabledSubtypes = mSettings.getEnabledInputMethodSubtypeListLocked(mContext, imi, true);
// 1. Search by the current subtype's locale from enabledSubtypes.
if (mCurrentSubtype != null) {
subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes, enabledSubtypes, mode, mCurrentSubtype.getLocale(), false);
}
// 3. Search the first enabled subtype matched with mode from enabledSubtypes.
if (subtype == null) {
subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes, enabledSubtypes, mode, null, true);
}
final ArrayList<InputMethodSubtype> overridingImplicitlyEnabledSubtypes = InputMethodUtils.getOverridingImplicitlyEnabledSubtypes(imi, mode);
final ArrayList<InputMethodSubtype> subtypesForSearch = overridingImplicitlyEnabledSubtypes.isEmpty() ? InputMethodUtils.getSubtypes(imi) : overridingImplicitlyEnabledSubtypes;
// 4. Search by the current subtype's locale from all subtypes.
if (subtype == null && mCurrentSubtype != null) {
subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes, subtypesForSearch, mode, mCurrentSubtype.getLocale(), false);
}
// 6. Search the first enabled subtype matched with mode from all subtypes.
if (subtype == null) {
subtype = InputMethodUtils.findLastResortApplicableSubtypeLocked(mRes, subtypesForSearch, mode, null, true);
}
if (subtype != null) {
if (imiId.equals(mCurMethodId)) {
// The current input method is the most applicable IME.
mostApplicableIMI = imi;
mostApplicableSubtype = subtype;
break;
} else if (!foundInSystemIME) {
// The system input method is 2nd applicable IME.
mostApplicableIMI = imi;
mostApplicableSubtype = subtype;
if ((imi.getServiceInfo().applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
foundInSystemIME = true;
}
}
}
}
if (DEBUG) {
if (mostApplicableIMI != null) {
Slog.w(TAG, "Most applicable shortcut input method was:" + mostApplicableIMI.getId());
if (mostApplicableSubtype != null) {
Slog.w(TAG, "Most applicable shortcut input method subtype was:" + "," + mostApplicableSubtype.getMode() + "," + mostApplicableSubtype.getLocale());
}
}
}
if (mostApplicableIMI != null) {
return new Pair<>(mostApplicableIMI, mostApplicableSubtype);
} else {
return null;
}
}
use of android.view.inputmethod.InputMethodSubtype in project android_frameworks_base by AOSPA.
the class InputMethodUtils method getImplicitlyApplicableSubtypesLockedImpl.
private static ArrayList<InputMethodSubtype> getImplicitlyApplicableSubtypesLockedImpl(Resources res, InputMethodInfo imi) {
final List<InputMethodSubtype> subtypes = InputMethodUtils.getSubtypes(imi);
final LocaleList systemLocales = res.getConfiguration().getLocales();
final String systemLocale = systemLocales.get(0).toString();
if (TextUtils.isEmpty(systemLocale))
return new ArrayList<>();
final int numSubtypes = subtypes.size();
// Handle overridesImplicitlyEnabledSubtype mechanism.
final HashMap<String, InputMethodSubtype> applicableModeAndSubtypesMap = new HashMap<>();
for (int i = 0; i < numSubtypes; ++i) {
// scan overriding implicitly enabled subtypes.
final InputMethodSubtype subtype = subtypes.get(i);
if (subtype.overridesImplicitlyEnabledSubtype()) {
final String mode = subtype.getMode();
if (!applicableModeAndSubtypesMap.containsKey(mode)) {
applicableModeAndSubtypesMap.put(mode, subtype);
}
}
}
if (applicableModeAndSubtypesMap.size() > 0) {
return new ArrayList<>(applicableModeAndSubtypesMap.values());
}
final HashMap<String, ArrayList<InputMethodSubtype>> nonKeyboardSubtypesMap = new HashMap<>();
final ArrayList<InputMethodSubtype> keyboardSubtypes = new ArrayList<>();
for (int i = 0; i < numSubtypes; ++i) {
final InputMethodSubtype subtype = subtypes.get(i);
final String mode = subtype.getMode();
if (SUBTYPE_MODE_KEYBOARD.equals(mode)) {
keyboardSubtypes.add(subtype);
} else {
if (!nonKeyboardSubtypesMap.containsKey(mode)) {
nonKeyboardSubtypesMap.put(mode, new ArrayList<>());
}
nonKeyboardSubtypesMap.get(mode).add(subtype);
}
}
final ArrayList<InputMethodSubtype> applicableSubtypes = new ArrayList<>();
LocaleUtils.filterByLanguage(keyboardSubtypes, sSubtypeToLocale, systemLocales, applicableSubtypes);
if (!applicableSubtypes.isEmpty()) {
boolean hasAsciiCapableKeyboard = false;
final int numApplicationSubtypes = applicableSubtypes.size();
for (int i = 0; i < numApplicationSubtypes; ++i) {
final InputMethodSubtype subtype = applicableSubtypes.get(i);
if (subtype.containsExtraValueKey(TAG_ASCII_CAPABLE)) {
hasAsciiCapableKeyboard = true;
break;
}
}
if (!hasAsciiCapableKeyboard) {
final int numKeyboardSubtypes = keyboardSubtypes.size();
for (int i = 0; i < numKeyboardSubtypes; ++i) {
final InputMethodSubtype subtype = keyboardSubtypes.get(i);
final String mode = subtype.getMode();
if (SUBTYPE_MODE_KEYBOARD.equals(mode) && subtype.containsExtraValueKey(TAG_ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE)) {
applicableSubtypes.add(subtype);
}
}
}
}
if (applicableSubtypes.isEmpty()) {
InputMethodSubtype lastResortKeyboardSubtype = findLastResortApplicableSubtypeLocked(res, subtypes, SUBTYPE_MODE_KEYBOARD, systemLocale, true);
if (lastResortKeyboardSubtype != null) {
applicableSubtypes.add(lastResortKeyboardSubtype);
}
}
// For each non-keyboard mode, extract subtypes with system locales.
for (final ArrayList<InputMethodSubtype> subtypeList : nonKeyboardSubtypesMap.values()) {
LocaleUtils.filterByLanguage(subtypeList, sSubtypeToLocale, systemLocales, applicableSubtypes);
}
return applicableSubtypes;
}
use of android.view.inputmethod.InputMethodSubtype in project android_frameworks_base by AOSPA.
the class InputMethodUtils method getOverridingImplicitlyEnabledSubtypes.
public static ArrayList<InputMethodSubtype> getOverridingImplicitlyEnabledSubtypes(InputMethodInfo imi, String mode) {
ArrayList<InputMethodSubtype> subtypes = new ArrayList<>();
final int subtypeCount = imi.getSubtypeCount();
for (int i = 0; i < subtypeCount; ++i) {
final InputMethodSubtype subtype = imi.getSubtypeAt(i);
if (subtype.overridesImplicitlyEnabledSubtype() && subtype.getMode().equals(mode)) {
subtypes.add(subtype);
}
}
return subtypes;
}
use of android.view.inputmethod.InputMethodSubtype in project android_frameworks_base by AOSPA.
the class InputMethodUtils method findLastResortApplicableSubtypeLocked.
/**
* If there are no selected subtypes, tries finding the most applicable one according to the
* given locale.
* @param subtypes this function will search the most applicable subtype in subtypes
* @param mode subtypes will be filtered by mode
* @param locale subtypes will be filtered by locale
* @param canIgnoreLocaleAsLastResort if this function can't find the most applicable subtype,
* it will return the first subtype matched with mode
* @return the most applicable subtypeId
*/
public static InputMethodSubtype findLastResortApplicableSubtypeLocked(Resources res, List<InputMethodSubtype> subtypes, String mode, String locale, boolean canIgnoreLocaleAsLastResort) {
if (subtypes == null || subtypes.size() == 0) {
return null;
}
if (TextUtils.isEmpty(locale)) {
locale = res.getConfiguration().locale.toString();
}
final String language = getLanguageFromLocaleString(locale);
boolean partialMatchFound = false;
InputMethodSubtype applicableSubtype = null;
InputMethodSubtype firstMatchedModeSubtype = null;
final int N = subtypes.size();
for (int i = 0; i < N; ++i) {
InputMethodSubtype subtype = subtypes.get(i);
final String subtypeLocale = subtype.getLocale();
final String subtypeLanguage = getLanguageFromLocaleString(subtypeLocale);
// and all subtypes with all modes can be candidates.
if (mode == null || subtypes.get(i).getMode().equalsIgnoreCase(mode)) {
if (firstMatchedModeSubtype == null) {
firstMatchedModeSubtype = subtype;
}
if (locale.equals(subtypeLocale)) {
// Exact match (e.g. system locale is "en_US" and subtype locale is "en_US")
applicableSubtype = subtype;
break;
} else if (!partialMatchFound && language.equals(subtypeLanguage)) {
// Partial match (e.g. system locale is "en_US" and subtype locale is "en")
applicableSubtype = subtype;
partialMatchFound = true;
}
}
}
if (applicableSubtype == null && canIgnoreLocaleAsLastResort) {
return firstMatchedModeSubtype;
}
// subtype.
if (DEBUG) {
if (applicableSubtype != null) {
Slog.d(TAG, "Applicable InputMethodSubtype was found: " + applicableSubtype.getMode() + "," + applicableSubtype.getLocale());
}
}
return applicableSubtype;
}
Aggregations