InputMethodSubtypepublic final class InputMethodSubtype extends Object implements android.os.ParcelableThis class is used to specify meta information of a subtype contained in an input method editor
(IME). Subtype can describe locale (e.g. en_US, fr_FR...) and mode (e.g. voice, keyboard...),
and is used for IME switch and settings. The input method subtype allows the system to bring up
the specified subtype of the designated IME directly.
It should be defined in an XML resource file of the input method with the
<subtype> element, which resides within an {@code <input-method>} element.
For more information, see the guide to
Creating an Input Method. |
Fields Summary |
---|
private static final String | TAG | private static final String | EXTRA_VALUE_PAIR_SEPARATOR | private static final String | EXTRA_VALUE_KEY_VALUE_SEPARATOR | private static final String | EXTRA_KEY_UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME | private final boolean | mIsAuxiliary | private final boolean | mOverridesImplicitlyEnabledSubtype | private final boolean | mIsAsciiCapable | private final int | mSubtypeHashCode | private final int | mSubtypeIconResId | private final int | mSubtypeNameResId | private final int | mSubtypeId | private final String | mSubtypeLocale | private final String | mSubtypeMode | private final String | mSubtypeExtraValue | private volatile HashMap | mExtraValueHashMapCache | public static final Parcelable.Creator | CREATOR |
Constructors Summary |
---|
public InputMethodSubtype(int nameId, int iconId, String locale, String mode, String extraValue, boolean isAuxiliary, boolean overridesImplicitlyEnabledSubtype)Constructor with no subtype ID specified.
this(nameId, iconId, locale, mode, extraValue, isAuxiliary,
overridesImplicitlyEnabledSubtype, 0);
| public InputMethodSubtype(int nameId, int iconId, String locale, String mode, String extraValue, boolean isAuxiliary, boolean overridesImplicitlyEnabledSubtype, int id)Constructor.
this(getBuilder(nameId, iconId, locale, mode, extraValue, isAuxiliary,
overridesImplicitlyEnabledSubtype, id, false));
| private InputMethodSubtype(InputMethodSubtypeBuilder builder)Constructor.
mSubtypeNameResId = builder.mSubtypeNameResId;
mSubtypeIconResId = builder.mSubtypeIconResId;
mSubtypeLocale = builder.mSubtypeLocale;
mSubtypeMode = builder.mSubtypeMode;
mSubtypeExtraValue = builder.mSubtypeExtraValue;
mIsAuxiliary = builder.mIsAuxiliary;
mOverridesImplicitlyEnabledSubtype = builder.mOverridesImplicitlyEnabledSubtype;
mSubtypeId = builder.mSubtypeId;
mIsAsciiCapable = builder.mIsAsciiCapable;
// If hashCode() of this subtype is 0 and you want to specify it as an id of this subtype,
// just specify 0 as this subtype's id. Then, this subtype's id is treated as 0.
mSubtypeHashCode = mSubtypeId != 0 ? mSubtypeId : hashCodeInternal(mSubtypeLocale,
mSubtypeMode, mSubtypeExtraValue, mIsAuxiliary, mOverridesImplicitlyEnabledSubtype,
mIsAsciiCapable);
| InputMethodSubtype(android.os.Parcel source)
String s;
mSubtypeNameResId = source.readInt();
mSubtypeIconResId = source.readInt();
s = source.readString();
mSubtypeLocale = s != null ? s : "";
s = source.readString();
mSubtypeMode = s != null ? s : "";
s = source.readString();
mSubtypeExtraValue = s != null ? s : "";
mIsAuxiliary = (source.readInt() == 1);
mOverridesImplicitlyEnabledSubtype = (source.readInt() == 1);
mSubtypeHashCode = source.readInt();
mSubtypeId = source.readInt();
mIsAsciiCapable = (source.readInt() == 1);
|
Methods Summary |
---|
private static java.util.Locale | constructLocaleFromString(java.lang.String localeStr)
if (TextUtils.isEmpty(localeStr))
return null;
String[] localeParams = localeStr.split("_", 3);
// The length of localeStr is guaranteed to always return a 1 <= value <= 3
// because localeStr is not empty.
if (localeParams.length == 1) {
return new Locale(localeParams[0]);
} else if (localeParams.length == 2) {
return new Locale(localeParams[0], localeParams[1]);
} else if (localeParams.length == 3) {
return new Locale(localeParams[0], localeParams[1], localeParams[2]);
}
return null;
| public boolean | containsExtraValueKey(java.lang.String key)The string of ExtraValue in subtype should be defined as follows:
example: key0,key1=value1,key2,key3,key4=value4
return getExtraValueHashMap().containsKey(key);
| public int | describeContents()
return 0;
| public boolean | equals(java.lang.Object o)
if (o instanceof InputMethodSubtype) {
InputMethodSubtype subtype = (InputMethodSubtype) o;
if (subtype.mSubtypeId != 0 || mSubtypeId != 0) {
return (subtype.hashCode() == hashCode());
}
return (subtype.hashCode() == hashCode())
&& (subtype.getLocale().equals(getLocale()))
&& (subtype.getMode().equals(getMode()))
&& (subtype.getExtraValue().equals(getExtraValue()))
&& (subtype.isAuxiliary() == isAuxiliary())
&& (subtype.overridesImplicitlyEnabledSubtype()
== overridesImplicitlyEnabledSubtype())
&& (subtype.isAsciiCapable() == isAsciiCapable());
}
return false;
| private static android.view.inputmethod.InputMethodSubtype$InputMethodSubtypeBuilder | getBuilder(int nameId, int iconId, java.lang.String locale, java.lang.String mode, java.lang.String extraValue, boolean isAuxiliary, boolean overridesImplicitlyEnabledSubtype, int id, boolean isAsciiCapable)
final InputMethodSubtypeBuilder builder = new InputMethodSubtypeBuilder();
builder.mSubtypeNameResId = nameId;
builder.mSubtypeIconResId = iconId;
builder.mSubtypeLocale = locale;
builder.mSubtypeMode = mode;
builder.mSubtypeExtraValue = extraValue;
builder.mIsAuxiliary = isAuxiliary;
builder.mOverridesImplicitlyEnabledSubtype = overridesImplicitlyEnabledSubtype;
builder.mSubtypeId = id;
builder.mIsAsciiCapable = isAsciiCapable;
return builder;
| public java.lang.CharSequence | getDisplayName(android.content.Context context, java.lang.String packageName, android.content.pm.ApplicationInfo appInfo)
final Locale locale = constructLocaleFromString(mSubtypeLocale);
final String localeStr = locale != null ? locale.getDisplayName() : mSubtypeLocale;
if (mSubtypeNameResId == 0) {
return localeStr;
}
final CharSequence subtypeName = context.getPackageManager().getText(
packageName, mSubtypeNameResId, appInfo);
if (!TextUtils.isEmpty(subtypeName)) {
final String replacementString =
containsExtraValueKey(EXTRA_KEY_UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME)
? getExtraValueOf(EXTRA_KEY_UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME)
: localeStr;
try {
return String.format(
subtypeName.toString(), replacementString != null ? replacementString : "");
} catch (IllegalFormatException e) {
Slog.w(TAG, "Found illegal format in subtype name("+ subtypeName + "): " + e);
return "";
}
} else {
return localeStr;
}
| public java.lang.String | getExtraValue()
return mSubtypeExtraValue;
| private java.util.HashMap | getExtraValueHashMap()
if (mExtraValueHashMapCache == null) {
synchronized(this) {
if (mExtraValueHashMapCache == null) {
mExtraValueHashMapCache = new HashMap<String, String>();
final String[] pairs = mSubtypeExtraValue.split(EXTRA_VALUE_PAIR_SEPARATOR);
final int N = pairs.length;
for (int i = 0; i < N; ++i) {
final String[] pair = pairs[i].split(EXTRA_VALUE_KEY_VALUE_SEPARATOR);
if (pair.length == 1) {
mExtraValueHashMapCache.put(pair[0], null);
} else if (pair.length > 1) {
if (pair.length > 2) {
Slog.w(TAG, "ExtraValue has two or more '='s");
}
mExtraValueHashMapCache.put(pair[0], pair[1]);
}
}
}
}
}
return mExtraValueHashMapCache;
| public java.lang.String | getExtraValueOf(java.lang.String key)The string of ExtraValue in subtype should be defined as follows:
example: key0,key1=value1,key2,key3,key4=value4
return getExtraValueHashMap().get(key);
| public int | getIconResId()
return mSubtypeIconResId;
| public java.lang.String | getLocale()
return mSubtypeLocale;
| public java.lang.String | getMode()
return mSubtypeMode;
| public int | getNameResId()
return mSubtypeNameResId;
| public int | hashCode()
return mSubtypeHashCode;
| private static int | hashCodeInternal(java.lang.String locale, java.lang.String mode, java.lang.String extraValue, boolean isAuxiliary, boolean overridesImplicitlyEnabledSubtype, boolean isAsciiCapable)
// CAVEAT: Must revisit how to compute needsToCalculateCompatibleHashCode when a new
// attribute is added in order to avoid enabled subtypes being unexpectedly disabled.
final boolean needsToCalculateCompatibleHashCode = !isAsciiCapable;
if (needsToCalculateCompatibleHashCode) {
return Arrays.hashCode(new Object[] {locale, mode, extraValue, isAuxiliary,
overridesImplicitlyEnabledSubtype});
}
return Arrays.hashCode(new Object[] {locale, mode, extraValue, isAuxiliary,
overridesImplicitlyEnabledSubtype, isAsciiCapable});
| public boolean | isAsciiCapable()
return mIsAsciiCapable;
| public boolean | isAuxiliary()
return mIsAuxiliary;
| public boolean | overridesImplicitlyEnabledSubtype()
return mOverridesImplicitlyEnabledSubtype;
| public static java.util.List | sort(android.content.Context context, int flags, InputMethodInfo imi, java.util.List subtypeList)Sort the list of InputMethodSubtype
if (imi == null) return subtypeList;
final HashSet<InputMethodSubtype> inputSubtypesSet = new HashSet<InputMethodSubtype>(
subtypeList);
final ArrayList<InputMethodSubtype> sortedList = new ArrayList<InputMethodSubtype>();
int N = imi.getSubtypeCount();
for (int i = 0; i < N; ++i) {
InputMethodSubtype subtype = imi.getSubtypeAt(i);
if (inputSubtypesSet.contains(subtype)) {
sortedList.add(subtype);
inputSubtypesSet.remove(subtype);
}
}
// If subtypes in inputSubtypesSet remain, that means these subtypes are not
// contained in imi, so the remaining subtypes will be appended.
for (InputMethodSubtype subtype: inputSubtypesSet) {
sortedList.add(subtype);
}
return sortedList;
| public void | writeToParcel(android.os.Parcel dest, int parcelableFlags)
dest.writeInt(mSubtypeNameResId);
dest.writeInt(mSubtypeIconResId);
dest.writeString(mSubtypeLocale);
dest.writeString(mSubtypeMode);
dest.writeString(mSubtypeExtraValue);
dest.writeInt(mIsAuxiliary ? 1 : 0);
dest.writeInt(mOverridesImplicitlyEnabledSubtype ? 1 : 0);
dest.writeInt(mSubtypeHashCode);
dest.writeInt(mSubtypeId);
dest.writeInt(mIsAsciiCapable ? 1 : 0);
|
|