Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d6d3a16f authored by Shu Chen's avatar Shu Chen Committed by Android (Google) Code Review
Browse files

Merge "Adds the new API - InputMethodSubtypeBuilder#setPhysicalKeyboardHint."

parents 9e7a9aa0 8203a5c4
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -1174,6 +1174,8 @@ package android {
    field public static final int persistentDrawingCache = 16842990; // 0x10100ee
    field public static final int persistentWhenFeatureAvailable = 16844131; // 0x1010563
    field @Deprecated public static final int phoneNumber = 16843111; // 0x1010167
    field public static final int physicalKeyboardHintLanguageTag;
    field public static final int physicalKeyboardHintLayoutType;
    field public static final int pivotX = 16843189; // 0x10101b5
    field public static final int pivotY = 16843190; // 0x10101b6
    field public static final int pointerIcon = 16844041; // 0x1010509
@@ -54438,6 +54440,8 @@ package android.view.inputmethod {
    method public String getMode();
    method @NonNull public CharSequence getNameOverride();
    method public int getNameResId();
    method @Nullable public android.icu.util.ULocale getPhysicalKeyboardHintLanguageTag();
    method @NonNull public String getPhysicalKeyboardHintLayoutType();
    method public boolean isAsciiCapable();
    method public boolean isAuxiliary();
    method public boolean overridesImplicitlyEnabledSubtype();
@@ -54452,6 +54456,7 @@ package android.view.inputmethod {
    method public android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder setIsAuxiliary(boolean);
    method public android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder setLanguageTag(String);
    method public android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder setOverridesImplicitlyEnabledSubtype(boolean);
    method @NonNull public android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder setPhysicalKeyboardHint(@Nullable android.icu.util.ULocale, @NonNull String);
    method public android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder setSubtypeExtraValue(String);
    method public android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder setSubtypeIconResId(int);
    method public android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder setSubtypeId(int);
+8 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.content.res.Resources.NotFoundException;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.graphics.drawable.Drawable;
import android.icu.util.ULocale;
import android.inputmethodservice.InputMethodService;
import android.os.Parcel;
import android.os.Parcelable;
@@ -266,11 +267,18 @@ public final class InputMethodInfo implements Parcelable {
                    }
                    final TypedArray a = res.obtainAttributes(
                            attrs, com.android.internal.R.styleable.InputMethod_Subtype);
                    String pkLanguageTag = a.getString(com.android.internal.R.styleable
                            .InputMethod_Subtype_physicalKeyboardHintLanguageTag);
                    String pkLayoutType = a.getString(com.android.internal.R.styleable
                            .InputMethod_Subtype_physicalKeyboardHintLayoutType);
                    final InputMethodSubtype subtype = new InputMethodSubtypeBuilder()
                            .setSubtypeNameResId(a.getResourceId(com.android.internal.R.styleable
                                    .InputMethod_Subtype_label, 0))
                            .setSubtypeIconResId(a.getResourceId(com.android.internal.R.styleable
                                    .InputMethod_Subtype_icon, 0))
                            .setPhysicalKeyboardHint(
                                    pkLanguageTag == null ? null : new ULocale(pkLanguageTag),
                                    pkLayoutType == null ? "" : pkLayoutType)
                            .setLanguageTag(a.getString(com.android.internal.R.styleable
                                    .InputMethod_Subtype_languageTag))
                            .setSubtypeLocale(a.getString(com.android.internal.R.styleable
+57 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import java.util.HashSet;
import java.util.IllegalFormatException;
import java.util.List;
import java.util.Locale;
import java.util.Objects;

/**
 * This class is used to specify meta information of a subtype contained in an input method editor
@@ -87,6 +88,8 @@ public final class InputMethodSubtype implements Parcelable {
    private final int mSubtypeIconResId;
    private final int mSubtypeNameResId;
    private final CharSequence mSubtypeNameOverride;
    private final String mPkLanguageTag;
    private final String mPkLayoutType;
    private final int mSubtypeId;
    private final String mSubtypeLocale;
    private final String mSubtypeLanguageTag;
@@ -189,6 +192,30 @@ public final class InputMethodSubtype implements Parcelable {
        }
        private CharSequence mSubtypeNameOverride = "";

        /**
         * Sets the physical keyboard hint information, such as language and layout.
         *
         * The system can use the hint information to automatically configure the physical keyboard
         * for the subtype.
         *
         * @param languageTag is the preferred physical keyboard BCP-47 language tag. This is used
         * to match the keyboardLocale attribute in the physical keyboard definition. If it's
         * {@code null}, the subtype's language tag will be used.
         * @param layoutType  is the preferred physical keyboard layout, which is used to match the
         * keyboardLayoutType attribute in the physical keyboard definition. See
         * {@link android.hardware.input.InputManager#ACTION_QUERY_KEYBOARD_LAYOUTS}.
         */
        @NonNull
        public InputMethodSubtypeBuilder setPhysicalKeyboardHint(@Nullable ULocale languageTag,
                @NonNull String layoutType) {
            Objects.requireNonNull(layoutType, "layoutType cannot be null");
            mPkLanguageTag = languageTag == null ? "" : languageTag.toLanguageTag();
            mPkLayoutType = layoutType;
            return this;
        }
        private String mPkLanguageTag = "";
        private String mPkLayoutType = "";

        /**
         * @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
@@ -322,6 +349,8 @@ public final class InputMethodSubtype implements Parcelable {
    private InputMethodSubtype(InputMethodSubtypeBuilder builder) {
        mSubtypeNameResId = builder.mSubtypeNameResId;
        mSubtypeNameOverride = builder.mSubtypeNameOverride;
        mPkLanguageTag = builder.mPkLanguageTag;
        mPkLayoutType = builder.mPkLayoutType;
        mSubtypeIconResId = builder.mSubtypeIconResId;
        mSubtypeLocale = builder.mSubtypeLocale;
        mSubtypeLanguageTag = builder.mSubtypeLanguageTag;
@@ -346,6 +375,10 @@ public final class InputMethodSubtype implements Parcelable {
        mSubtypeNameResId = source.readInt();
        CharSequence cs = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
        mSubtypeNameOverride = cs != null ? cs : "";
        s = source.readString8();
        mPkLanguageTag = s != null ? s : "";
        s = source.readString8();
        mPkLayoutType = s != null ? s : "";
        mSubtypeIconResId = source.readInt();
        s = source.readString();
        mSubtypeLocale = s != null ? s : "";
@@ -377,6 +410,28 @@ public final class InputMethodSubtype implements Parcelable {
        return mSubtypeNameOverride;
    }

    /**
     * Returns the physical keyboard BCP-47 language tag.
     *
     * @attr ref android.R.styleable#InputMethod_Subtype_physicalKeyboardHintLanguageTag
     * @see InputMethodSubtypeBuilder#setPhysicalKeyboardHint
     */
    @Nullable
    public ULocale getPhysicalKeyboardHintLanguageTag() {
        return TextUtils.isEmpty(mPkLanguageTag) ? null : ULocale.forLanguageTag(mPkLanguageTag);
    }

    /**
     * Returns the physical keyboard layout type string.
     *
     * @attr ref android.R.styleable#InputMethod_Subtype_physicalKeyboardHintLayoutType
     * @see InputMethodSubtypeBuilder#setPhysicalKeyboardHint
     */
    @NonNull
    public String getPhysicalKeyboardHintLayoutType() {
        return mPkLayoutType;
    }

    /**
     * @return Resource ID of the subtype icon drawable.
     */
@@ -729,6 +784,8 @@ public final class InputMethodSubtype implements Parcelable {
    public void writeToParcel(Parcel dest, int parcelableFlags) {
        dest.writeInt(mSubtypeNameResId);
        TextUtils.writeToParcel(mSubtypeNameOverride, dest, parcelableFlags);
        dest.writeString8(mPkLanguageTag);
        dest.writeString8(mPkLayoutType);
        dest.writeInt(mSubtypeIconResId);
        dest.writeString(mSubtypeLocale);
        dest.writeString(mSubtypeLanguageTag);
+11 −0
Original line number Diff line number Diff line
@@ -3812,6 +3812,17 @@
        <!-- The BCP-47 Language Tag of the subtype.  This replaces
        {@link android.R.styleable#InputMethod_Subtype_imeSubtypeLocale}.  -->
        <attr name="languageTag" format="string" />
        <!-- The BCP-47 Language Tag of the preferred physical keyboard of the subtype. If it's not
             specified, {@link android.R.styleable#InputMethod_Subtype_languageTag} will be used.
             See also
             {@link android.view.inputmethod.InputMethodSubtype#getPhysicalKeyboardHintLanguageTag}.
             -->
        <attr name="physicalKeyboardHintLanguageTag" format="string" />
        <!-- The layout type of the preferred physical keyboard of the subtype.
             It matches the layout type string in the keyboard layout definition. See also
             {@link android.view.inputmethod.InputMethodSubtype#getPhysicalKeyboardHintLayoutType}.
             -->
        <attr name="physicalKeyboardHintLayoutType" format="string" />
    </declare-styleable>
    <!-- Use <code>spell-checker</code> as the root tag of the XML resource that
+2 −0
Original line number Diff line number Diff line
@@ -119,6 +119,8 @@
    <public name="requiredDisplayCategory"/>
    <public name="removed_maxConcurrentSessionsCount" />
    <public name="visualQueryDetectionService" />
    <public name="physicalKeyboardHintLanguageTag" />
    <public name="physicalKeyboardHintLayoutType" />
  </staging-public-group>

  <staging-public-group type="id" first-id="0x01cd0000">
Loading