Merge "Adds the new API - InputMethodSubtypeBuilder#setSubtypeNameOverride."
This commit is contained in:
@@ -53853,6 +53853,7 @@ package android.view.inputmethod {
|
||||
method @NonNull public String getLanguageTag();
|
||||
method @Deprecated @NonNull public String getLocale();
|
||||
method public String getMode();
|
||||
method @NonNull public CharSequence getNameOverride();
|
||||
method public int getNameResId();
|
||||
method public boolean isAsciiCapable();
|
||||
method public boolean isAuxiliary();
|
||||
@@ -53873,6 +53874,7 @@ package android.view.inputmethod {
|
||||
method public android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder setSubtypeId(int);
|
||||
method public android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder setSubtypeLocale(String);
|
||||
method public android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder setSubtypeMode(String);
|
||||
method @NonNull public android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder setSubtypeNameOverride(@NonNull CharSequence);
|
||||
method public android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder setSubtypeNameResId(int);
|
||||
}
|
||||
|
||||
|
||||
@@ -86,6 +86,7 @@ public final class InputMethodSubtype implements Parcelable {
|
||||
private final int mSubtypeHashCode;
|
||||
private final int mSubtypeIconResId;
|
||||
private final int mSubtypeNameResId;
|
||||
private final CharSequence mSubtypeNameOverride;
|
||||
private final int mSubtypeId;
|
||||
private final String mSubtypeLocale;
|
||||
private final String mSubtypeLanguageTag;
|
||||
@@ -173,6 +174,21 @@ public final class InputMethodSubtype implements Parcelable {
|
||||
}
|
||||
private int mSubtypeNameResId = 0;
|
||||
|
||||
/**
|
||||
* Sets the untranslatable name of the subtype.
|
||||
*
|
||||
* This string is used as the subtype's display name if subtype's name res Id is 0.
|
||||
*
|
||||
* @param nameOverride is the name to set.
|
||||
*/
|
||||
@NonNull
|
||||
public InputMethodSubtypeBuilder setSubtypeNameOverride(
|
||||
@NonNull CharSequence nameOverride) {
|
||||
mSubtypeNameOverride = nameOverride;
|
||||
return this;
|
||||
}
|
||||
private CharSequence mSubtypeNameOverride = "";
|
||||
|
||||
/**
|
||||
* @param subtypeId is the unique ID for this subtype. The input method framework keeps
|
||||
* track of enabled subtypes by ID. When the IME package gets upgraded, enabled IDs will
|
||||
@@ -229,23 +245,23 @@ public final class InputMethodSubtype implements Parcelable {
|
||||
public InputMethodSubtype build() {
|
||||
return new InputMethodSubtype(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static InputMethodSubtypeBuilder getBuilder(int nameId, int iconId, String locale,
|
||||
String mode, 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;
|
||||
}
|
||||
private static InputMethodSubtypeBuilder getBuilder(int nameId, int iconId,
|
||||
String locale, String mode, 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with no subtype ID specified.
|
||||
@@ -305,6 +321,7 @@ public final class InputMethodSubtype implements Parcelable {
|
||||
*/
|
||||
private InputMethodSubtype(InputMethodSubtypeBuilder builder) {
|
||||
mSubtypeNameResId = builder.mSubtypeNameResId;
|
||||
mSubtypeNameOverride = builder.mSubtypeNameOverride;
|
||||
mSubtypeIconResId = builder.mSubtypeIconResId;
|
||||
mSubtypeLocale = builder.mSubtypeLocale;
|
||||
mSubtypeLanguageTag = builder.mSubtypeLanguageTag;
|
||||
@@ -327,6 +344,8 @@ public final class InputMethodSubtype implements Parcelable {
|
||||
InputMethodSubtype(Parcel source) {
|
||||
String s;
|
||||
mSubtypeNameResId = source.readInt();
|
||||
CharSequence cs = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
|
||||
mSubtypeNameOverride = cs != null ? cs : "";
|
||||
mSubtypeIconResId = source.readInt();
|
||||
s = source.readString();
|
||||
mSubtypeLocale = s != null ? s : "";
|
||||
@@ -350,6 +369,14 @@ public final class InputMethodSubtype implements Parcelable {
|
||||
return mSubtypeNameResId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The subtype's untranslatable name string.
|
||||
*/
|
||||
@NonNull
|
||||
public CharSequence getNameOverride() {
|
||||
return mSubtypeNameOverride;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Resource ID of the subtype icon drawable.
|
||||
*/
|
||||
@@ -532,8 +559,11 @@ public final class InputMethodSubtype implements Parcelable {
|
||||
public CharSequence getDisplayName(
|
||||
Context context, String packageName, ApplicationInfo appInfo) {
|
||||
if (mSubtypeNameResId == 0) {
|
||||
return getLocaleDisplayName(getLocaleFromContext(context), getLocaleObject(),
|
||||
DisplayContext.CAPITALIZATION_FOR_UI_LIST_OR_MENU);
|
||||
return TextUtils.isEmpty(mSubtypeNameOverride)
|
||||
? getLocaleDisplayName(
|
||||
getLocaleFromContext(context), getLocaleObject(),
|
||||
DisplayContext.CAPITALIZATION_FOR_UI_LIST_OR_MENU)
|
||||
: mSubtypeNameOverride;
|
||||
}
|
||||
|
||||
final CharSequence subtypeName = context.getPackageManager().getText(
|
||||
@@ -698,6 +728,7 @@ public final class InputMethodSubtype implements Parcelable {
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int parcelableFlags) {
|
||||
dest.writeInt(mSubtypeNameResId);
|
||||
TextUtils.writeToParcel(mSubtypeNameOverride, dest, parcelableFlags);
|
||||
dest.writeInt(mSubtypeIconResId);
|
||||
dest.writeString(mSubtypeLocale);
|
||||
dest.writeString(mSubtypeLanguageTag);
|
||||
@@ -765,4 +796,4 @@ public final class InputMethodSubtype implements Parcelable {
|
||||
}
|
||||
return sortedList;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ final class AdditionalSubtypeUtils {
|
||||
private static final String NODE_IMI = "imi";
|
||||
private static final String ATTR_ID = "id";
|
||||
private static final String ATTR_LABEL = "label";
|
||||
private static final String ATTR_NAME_OVERRIDE = "nameOverride";
|
||||
private static final String ATTR_ICON = "icon";
|
||||
private static final String ATTR_IME_SUBTYPE_ID = "subtypeId";
|
||||
private static final String ATTR_IME_SUBTYPE_LOCALE = "imeSubtypeLocale";
|
||||
@@ -161,6 +162,7 @@ final class AdditionalSubtypeUtils {
|
||||
}
|
||||
out.attributeInt(null, ATTR_ICON, subtype.getIconResId());
|
||||
out.attributeInt(null, ATTR_LABEL, subtype.getNameResId());
|
||||
out.attribute(null, ATTR_NAME_OVERRIDE, subtype.getNameOverride().toString());
|
||||
out.attribute(null, ATTR_IME_SUBTYPE_LOCALE, subtype.getLocale());
|
||||
out.attribute(null, ATTR_IME_SUBTYPE_LANGUAGE_TAG,
|
||||
subtype.getLanguageTag());
|
||||
@@ -243,6 +245,8 @@ final class AdditionalSubtypeUtils {
|
||||
}
|
||||
final int icon = parser.getAttributeInt(null, ATTR_ICON);
|
||||
final int label = parser.getAttributeInt(null, ATTR_LABEL);
|
||||
final String untranslatableName = parser.getAttributeValue(null,
|
||||
ATTR_NAME_OVERRIDE);
|
||||
final String imeSubtypeLocale =
|
||||
parser.getAttributeValue(null, ATTR_IME_SUBTYPE_LOCALE);
|
||||
final String languageTag =
|
||||
@@ -258,6 +262,7 @@ final class AdditionalSubtypeUtils {
|
||||
final InputMethodSubtype.InputMethodSubtypeBuilder
|
||||
builder = new InputMethodSubtype.InputMethodSubtypeBuilder()
|
||||
.setSubtypeNameResId(label)
|
||||
.setSubtypeNameOverride(untranslatableName)
|
||||
.setSubtypeIconResId(icon)
|
||||
.setSubtypeLocale(imeSubtypeLocale)
|
||||
.setLanguageTag(languageTag)
|
||||
|
||||
Reference in New Issue
Block a user