Add InputMethodSubtypeCompatUtils.isAsciiCapable()

Change-Id: I8145f090486f6fe30ef1e992db374cfba0c31012
main
Tadashi G. Takaoka 2014-02-17 16:06:43 +09:00
parent 4f4fb5ef34
commit 20ddd4cff5
3 changed files with 20 additions and 6 deletions

View File

@ -19,7 +19,10 @@ package com.android.inputmethod.compat;
import android.os.Build;
import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.latin.Constants;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
public final class InputMethodSubtypeCompatUtils {
private static final String TAG = InputMethodSubtypeCompatUtils.class.getSimpleName();
@ -37,6 +40,12 @@ public final class InputMethodSubtypeCompatUtils {
}
}
}
// Note that {@link InputMethodSubtype#isAsciiCapable()} has been introduced in API level 19
// (Build.VERSION_CODE.KITKAT).
private static final Method METHOD_isAsciiCapable = CompatUtils.getMethod(
InputMethodSubtype.class, "isAsciiCapable");
private InputMethodSubtypeCompatUtils() {
// This utility class is not publicly instantiable.
}
@ -53,4 +62,9 @@ public final class InputMethodSubtypeCompatUtils {
nameId, iconId, locale, mode, extraValue, isAuxiliary,
overridesImplicitlyEnabledSubtype, id);
}
public static boolean isAsciiCapable(final InputMethodSubtype subtype) {
return (Boolean)CompatUtils.invoke(subtype, false, METHOD_isAsciiCapable)
|| subtype.containsExtraValueKey(Constants.Subtype.ExtraValue.ASCII_CAPABLE);
}
}

View File

@ -20,7 +20,6 @@ import static com.android.inputmethod.latin.Constants.ImeOption.FORCE_ASCII;
import static com.android.inputmethod.latin.Constants.ImeOption.NO_MICROPHONE;
import static com.android.inputmethod.latin.Constants.ImeOption.NO_MICROPHONE_COMPAT;
import static com.android.inputmethod.latin.Constants.ImeOption.NO_SETTINGS_KEY;
import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.ASCII_CAPABLE;
import android.content.Context;
import android.content.res.Resources;
@ -34,6 +33,7 @@ import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.compat.EditorInfoCompatUtils;
import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils;
import com.android.inputmethod.keyboard.internal.KeyboardBuilder;
import com.android.inputmethod.keyboard.internal.KeyboardParams;
import com.android.inputmethod.keyboard.internal.KeysCache;
@ -248,7 +248,7 @@ public final class KeyboardLayoutSet {
}
public Builder setSubtype(final InputMethodSubtype subtype) {
final boolean asciiCapable = subtype.containsExtraValueKey(ASCII_CAPABLE);
final boolean asciiCapable = InputMethodSubtypeCompatUtils.isAsciiCapable(subtype);
@SuppressWarnings("deprecation")
final boolean deprecatedForceAscii = InputAttributes.inPrivateImeOptions(
mPackageName, FORCE_ASCII, mParams.mEditorInfo);

View File

@ -16,8 +16,6 @@
package com.android.inputmethod.latin.settings;
import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.ASCII_CAPABLE;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
@ -44,6 +42,8 @@ import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import android.widget.Toast;
import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.RichInputMethodManager;
import com.android.inputmethod.latin.utils.AdditionalSubtypeUtils;
@ -111,7 +111,7 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment {
subtype.getLocale(), subtype.hashCode(), subtype.hashCode(),
SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(subtype)));
}
if (subtype.containsExtraValueKey(ASCII_CAPABLE)) {
if (InputMethodSubtypeCompatUtils.isAsciiCapable(subtype)) {
items.add(createItem(context, subtype.getLocale()));
}
}
@ -287,7 +287,7 @@ public final class AdditionalSubtypeSettings extends PreferenceFragment {
final KeyboardLayoutSetItem layout =
(KeyboardLayoutSetItem) mKeyboardLayoutSetSpinner.getSelectedItem();
final InputMethodSubtype subtype = AdditionalSubtypeUtils.createAdditionalSubtype(
locale.first, layout.first, ASCII_CAPABLE);
locale.first, layout.first, Constants.Subtype.ExtraValue.ASCII_CAPABLE);
setSubtype(subtype);
notifyChanged();
if (isEditing) {