Merge "Ignore unknown keyboard layout safely"
This commit is contained in:
commit
d454fcc2cf
3 changed files with 19 additions and 11 deletions
|
@ -22,6 +22,7 @@ import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.KEYBOAR
|
||||||
|
|
||||||
import android.view.inputmethod.InputMethodSubtype;
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class AdditionalSubtype {
|
public class AdditionalSubtype {
|
||||||
|
|
||||||
|
@ -41,9 +42,8 @@ public class AdditionalSubtype {
|
||||||
final String layoutExtraValue = KEYBOARD_LAYOUT_SET + "=" + keyboardLayoutSetName;
|
final String layoutExtraValue = KEYBOARD_LAYOUT_SET + "=" + keyboardLayoutSetName;
|
||||||
final String filteredExtraValue = StringUtils.appendToCsvIfNotExists(
|
final String filteredExtraValue = StringUtils.appendToCsvIfNotExists(
|
||||||
IS_ADDITIONAL_SUBTYPE, extraValue);
|
IS_ADDITIONAL_SUBTYPE, extraValue);
|
||||||
Integer nameId = SubtypeLocale.getSubtypeNameIdFromKeyboardLayoutName(
|
final int nameId = SubtypeLocale.getSubtypeNameIdFromKeyboardLayoutName(
|
||||||
keyboardLayoutSetName);
|
keyboardLayoutSetName);
|
||||||
if (nameId == null) nameId = R.string.subtype_generic;
|
|
||||||
return new InputMethodSubtype(nameId, R.drawable.ic_subtype_keyboard,
|
return new InputMethodSubtype(nameId, R.drawable.ic_subtype_keyboard,
|
||||||
localeString, KEYBOARD_MODE,
|
localeString, KEYBOARD_MODE,
|
||||||
layoutExtraValue + "," + filteredExtraValue, false, false);
|
layoutExtraValue + "," + filteredExtraValue, false, false);
|
||||||
|
@ -74,10 +74,17 @@ public class AdditionalSubtype {
|
||||||
|
|
||||||
public static InputMethodSubtype[] createAdditionalSubtypesArray(String prefSubtypes) {
|
public static InputMethodSubtype[] createAdditionalSubtypesArray(String prefSubtypes) {
|
||||||
final String[] prefSubtypeArray = prefSubtypes.split(PREF_SUBTYPE_SEPARATOR);
|
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++) {
|
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) {
|
private void setPrefSubtypes(String prefSubtypes, Context context) {
|
||||||
final PreferenceGroup group = mSubtypePrefGroup;
|
final PreferenceGroup group = mSubtypePrefGroup;
|
||||||
group.removeAll();
|
group.removeAll();
|
||||||
final String[] prefSubtypeArray = prefSubtypes.split(
|
final InputMethodSubtype[] subtypesArray =
|
||||||
AdditionalSubtype.PREF_SUBTYPE_SEPARATOR);
|
AdditionalSubtype.createAdditionalSubtypesArray(prefSubtypes);
|
||||||
for (final String prefSubtype : prefSubtypeArray) {
|
for (final InputMethodSubtype subtype : subtypesArray) {
|
||||||
final InputMethodSubtype subtype =
|
|
||||||
AdditionalSubtype.createAdditionalSubtype(prefSubtype);
|
|
||||||
final SubtypePreference pref = new SubtypePreference(
|
final SubtypePreference pref = new SubtypePreference(
|
||||||
context, subtype, mSubtypeProxy);
|
context, subtype, mSubtypeProxy);
|
||||||
group.addPreference(pref);
|
group.addPreference(pref);
|
||||||
|
|
|
@ -36,6 +36,8 @@ public class SubtypeLocale {
|
||||||
|
|
||||||
public static final String QWERTY = "qwerty";
|
public static final String QWERTY = "qwerty";
|
||||||
|
|
||||||
|
public static final int UNKNOWN_KEYBOARD_LAYOUT = R.string.subtype_generic;
|
||||||
|
|
||||||
private static String[] sPredefinedKeyboardLayoutSet;
|
private static String[] sPredefinedKeyboardLayoutSet;
|
||||||
// Keyboard layout to its display name map.
|
// Keyboard layout to its display name map.
|
||||||
private static final HashMap<String, String> sKeyboardKayoutToDisplayNameMap =
|
private static final HashMap<String, String> sKeyboardKayoutToDisplayNameMap =
|
||||||
|
@ -81,7 +83,8 @@ public class SubtypeLocale {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getSubtypeNameIdFromKeyboardLayoutName(String keyboardLayoutName) {
|
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.
|
// Get InputMethodSubtype's display name in its locale.
|
||||||
|
|
Loading…
Reference in a new issue