Merge "Ignore unknown keyboard layout safely"
commit
d454fcc2cf
|
@ -22,6 +22,7 @@ import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.KEYBOAR
|
|||
|
||||
import android.view.inputmethod.InputMethodSubtype;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class AdditionalSubtype {
|
||||
|
||||
|
@ -41,9 +42,8 @@ public class AdditionalSubtype {
|
|||
final String layoutExtraValue = KEYBOARD_LAYOUT_SET + "=" + keyboardLayoutSetName;
|
||||
final String filteredExtraValue = StringUtils.appendToCsvIfNotExists(
|
||||
IS_ADDITIONAL_SUBTYPE, extraValue);
|
||||
Integer nameId = SubtypeLocale.getSubtypeNameIdFromKeyboardLayoutName(
|
||||
final int nameId = SubtypeLocale.getSubtypeNameIdFromKeyboardLayoutName(
|
||||
keyboardLayoutSetName);
|
||||
if (nameId == null) nameId = R.string.subtype_generic;
|
||||
return new InputMethodSubtype(nameId, R.drawable.ic_subtype_keyboard,
|
||||
localeString, KEYBOARD_MODE,
|
||||
layoutExtraValue + "," + filteredExtraValue, false, false);
|
||||
|
@ -74,10 +74,17 @@ public class AdditionalSubtype {
|
|||
|
||||
public static InputMethodSubtype[] createAdditionalSubtypesArray(String prefSubtypes) {
|
||||
final String[] prefSubtypeArray = prefSubtypes.split(PREF_SUBTYPE_SEPARATOR);
|
||||
final InputMethodSubtype[] subtypesArray = new InputMethodSubtype[prefSubtypeArray.length];
|
||||
final ArrayList<InputMethodSubtype> subtypesList =
|
||||
new ArrayList<InputMethodSubtype>(prefSubtypeArray.length);
|
||||
for (int i = 0; i < prefSubtypeArray.length; i++) {
|
||||
subtypesArray[i] = createAdditionalSubtype(prefSubtypeArray[i]);
|
||||
final InputMethodSubtype subtype = createAdditionalSubtype(prefSubtypeArray[i]);
|
||||
if (subtype.getNameResId() == SubtypeLocale.UNKNOWN_KEYBOARD_LAYOUT) {
|
||||
// Skip unknown keyboard layout subtype. This may happen when predefined keyboard
|
||||
// layout has been removed.
|
||||
continue;
|
||||
}
|
||||
return subtypesArray;
|
||||
subtypesList.add(subtype);
|
||||
}
|
||||
return subtypesList.toArray(new InputMethodSubtype[subtypesList.size()]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -348,11 +348,9 @@ public class AdditionalSubtypeSettings extends PreferenceFragment {
|
|||
private void setPrefSubtypes(String prefSubtypes, Context context) {
|
||||
final PreferenceGroup group = mSubtypePrefGroup;
|
||||
group.removeAll();
|
||||
final String[] prefSubtypeArray = prefSubtypes.split(
|
||||
AdditionalSubtype.PREF_SUBTYPE_SEPARATOR);
|
||||
for (final String prefSubtype : prefSubtypeArray) {
|
||||
final InputMethodSubtype subtype =
|
||||
AdditionalSubtype.createAdditionalSubtype(prefSubtype);
|
||||
final InputMethodSubtype[] subtypesArray =
|
||||
AdditionalSubtype.createAdditionalSubtypesArray(prefSubtypes);
|
||||
for (final InputMethodSubtype subtype : subtypesArray) {
|
||||
final SubtypePreference pref = new SubtypePreference(
|
||||
context, subtype, mSubtypeProxy);
|
||||
group.addPreference(pref);
|
||||
|
|
|
@ -36,6 +36,8 @@ public class SubtypeLocale {
|
|||
|
||||
public static final String QWERTY = "qwerty";
|
||||
|
||||
public static final int UNKNOWN_KEYBOARD_LAYOUT = R.string.subtype_generic;
|
||||
|
||||
private static String[] sPredefinedKeyboardLayoutSet;
|
||||
// Keyboard layout to its display name map.
|
||||
private static final HashMap<String, String> sKeyboardKayoutToDisplayNameMap =
|
||||
|
@ -81,7 +83,8 @@ public class SubtypeLocale {
|
|||
}
|
||||
|
||||
public static int getSubtypeNameIdFromKeyboardLayoutName(String keyboardLayoutName) {
|
||||
return sKeyboardLayoutToNameIdsMap.get(keyboardLayoutName);
|
||||
final Integer nameId = sKeyboardLayoutToNameIdsMap.get(keyboardLayoutName);
|
||||
return nameId == null ? UNKNOWN_KEYBOARD_LAYOUT : nameId;
|
||||
}
|
||||
|
||||
// Get InputMethodSubtype's display name in its locale.
|
||||
|
|
Loading…
Reference in New Issue