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

Commit 44e7c8a2 authored by Cosmin Băieș's avatar Cosmin Băieș
Browse files

Introduce IME Subtype getLayoutDisplayName API

Following the existing IME Subtype getDisplayName API, this new method
will return the name of the IME Subtype's layout as specified by the IME.

When available, this will be displayed on a separate line in the IME
Switcher Menu, under the IME Subtype's display name.

Flag: android.view.inputmethod.ime_switcher_revamp_api
Bug: 371168848
Test: atest
  InputMethodInfoTest#testInputMethodSubtypeWriteToParcel
  InputMethodSubtypeTest#testLayoutLabelNonLocalizedParcel
  InputMethodSubtypeTest#testNoLayoutLabelNonLocalizedParcel
  InputMethodSubtypeTest#testSetLayoutLabelNonLocalized
  InputMethodSubtypeTest#testSetLayoutLabelNonLocalizedWithLayoutLabelResource
Change-Id: I39a82cf66f0890a671df35f3c73adcdf88959617
parent 374bde7e
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -1074,6 +1074,7 @@ package android {
    field public static final int layout = 16842994; // 0x10100f2
    field public static final int layoutAnimation = 16842988; // 0x10100ec
    field public static final int layoutDirection = 16843698; // 0x10103b2
    field @FlaggedApi("android.view.inputmethod.ime_switcher_revamp_api") public static final int layoutLabel;
    field public static final int layoutMode = 16843738; // 0x10103da
    field public static final int layout_above = 16843140; // 0x1010184
    field public static final int layout_alignBaseline = 16843142; // 0x1010186
@@ -56975,6 +56976,9 @@ package android.view.inputmethod {
    method public String getExtraValueOf(String);
    method public int getIconResId();
    method @NonNull public String getLanguageTag();
    method @FlaggedApi("android.view.inputmethod.ime_switcher_revamp_api") @NonNull public CharSequence getLayoutDisplayName(@NonNull android.content.Context, @NonNull android.content.pm.ApplicationInfo);
    method @FlaggedApi("android.view.inputmethod.ime_switcher_revamp_api") @NonNull public CharSequence getLayoutLabelNonLocalized();
    method @FlaggedApi("android.view.inputmethod.ime_switcher_revamp_api") @StringRes public int getLayoutLabelResource();
    method @Deprecated @NonNull public String getLocale();
    method public String getMode();
    method @NonNull public CharSequence getNameOverride();
@@ -56994,6 +56998,8 @@ package android.view.inputmethod {
    method public android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder setIsAsciiCapable(boolean);
    method public android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder setIsAuxiliary(boolean);
    method public android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder setLanguageTag(String);
    method @FlaggedApi("android.view.inputmethod.ime_switcher_revamp_api") @NonNull public android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder setLayoutLabelNonLocalized(@NonNull CharSequence);
    method @FlaggedApi("android.view.inputmethod.ime_switcher_revamp_api") @NonNull public android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder setLayoutLabelResource(@StringRes int);
    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);
+124 −1
Original line number Diff line number Diff line
@@ -17,8 +17,10 @@
package android.view.inputmethod;

import android.annotation.AnyThread;
import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.StringRes;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.res.Configuration;
@@ -87,8 +89,17 @@ public final class InputMethodSubtype implements Parcelable {
    private final boolean mIsAsciiCapable;
    private final int mSubtypeHashCode;
    private final int mSubtypeIconResId;
    /** The subtype name resource identifier. */
    private final int mSubtypeNameResId;
    /** The untranslatable name of the subtype. */
    @NonNull
    private final CharSequence mSubtypeNameOverride;
    /** The layout label string resource identifier. */
    @StringRes
    private final int mLayoutLabelResId;
    /** The non-localized layout label. */
    @NonNull
    private final CharSequence mLayoutLabelNonLocalized;
    private final String mPkLanguageTag;
    private final String mPkLayoutType;
    private final int mSubtypeId;
@@ -176,6 +187,7 @@ public final class InputMethodSubtype implements Parcelable {
            mSubtypeNameResId = subtypeNameResId;
            return this;
        }
        /** The subtype name resource identifier. */
        private int mSubtypeNameResId = 0;

        /**
@@ -191,8 +203,55 @@ public final class InputMethodSubtype implements Parcelable {
            mSubtypeNameOverride = nameOverride;
            return this;
        }
        /** The untranslatable name of the subtype. */
        @NonNull
        private CharSequence mSubtypeNameOverride = "";

        /**
         * Sets the layout label string resource identifier.
         *
         * @param layoutLabelResId the layout label string resource identifier.
         *
         * @see #getLayoutDisplayName
         */
        @FlaggedApi(Flags.FLAG_IME_SWITCHER_REVAMP_API)
        @NonNull
        public InputMethodSubtypeBuilder setLayoutLabelResource(
                @StringRes int layoutLabelResId) {
            if (!Flags.imeSwitcherRevampApi()) {
                return this;
            }
            mLayoutLabelResId = layoutLabelResId;
            return this;
        }
        /** The layout label string resource identifier. */
        @StringRes
        private int mLayoutLabelResId = 0;

        /**
         * Sets the non-localized layout label. This is used as the layout display name if the
         * {@link #getLayoutLabelResource layoutLabelResource} is not set ({@code 0}).
         *
         * @param layoutLabelNonLocalized the non-localized layout label.
         *
         * @see #getLayoutDisplayName
         */
        @FlaggedApi(Flags.FLAG_IME_SWITCHER_REVAMP_API)
        @NonNull
        public InputMethodSubtypeBuilder setLayoutLabelNonLocalized(
                @NonNull CharSequence layoutLabelNonLocalized) {
            if (!Flags.imeSwitcherRevampApi()) {
                return this;
            }
            Objects.requireNonNull(layoutLabelNonLocalized,
                    "layoutLabelNonLocalized cannot be null");
            mLayoutLabelNonLocalized = layoutLabelNonLocalized;
            return this;
        }
        /** The non-localized layout label. */
        @NonNull
        private CharSequence mLayoutLabelNonLocalized = "";

        /**
         * Sets the physical keyboard hint information, such as language and layout.
         *
@@ -350,6 +409,8 @@ public final class InputMethodSubtype implements Parcelable {
    private InputMethodSubtype(InputMethodSubtypeBuilder builder) {
        mSubtypeNameResId = builder.mSubtypeNameResId;
        mSubtypeNameOverride = builder.mSubtypeNameOverride;
        mLayoutLabelResId = builder.mLayoutLabelResId;
        mLayoutLabelNonLocalized = builder.mLayoutLabelNonLocalized;
        mPkLanguageTag = builder.mPkLanguageTag;
        mPkLayoutType = builder.mPkLayoutType;
        mSubtypeIconResId = builder.mSubtypeIconResId;
@@ -376,6 +437,9 @@ public final class InputMethodSubtype implements Parcelable {
        mSubtypeNameResId = source.readInt();
        CharSequence cs = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
        mSubtypeNameOverride = cs != null ? cs : "";
        mLayoutLabelResId = source.readInt();
        cs = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
        mLayoutLabelNonLocalized = cs != null ? cs : "";
        s = source.readString8();
        mPkLanguageTag = s != null ? s : "";
        s = source.readString8();
@@ -411,6 +475,24 @@ public final class InputMethodSubtype implements Parcelable {
        return mSubtypeNameOverride;
    }

    /**
     * Returns the layout label string resource identifier.
     */
    @FlaggedApi(Flags.FLAG_IME_SWITCHER_REVAMP_API)
    @StringRes
    public int getLayoutLabelResource() {
        return mLayoutLabelResId;
    }

    /**
     * Returns the non-localized layout label.
     */
    @FlaggedApi(Flags.FLAG_IME_SWITCHER_REVAMP_API)
    @NonNull
    public CharSequence getLayoutLabelNonLocalized() {
        return mLayoutLabelNonLocalized;
    }

    /**
     * Returns the physical keyboard BCP-47 language tag.
     *
@@ -648,6 +730,44 @@ public final class InputMethodSubtype implements Parcelable {
        }
    }

    /**
     * Returns the layout display name.
     *
     * <p>If {@code layoutLabelResource} is non-zero (specified through
     * {@link InputMethodSubtypeBuilder#setLayoutLabelResource setLayoutLabelResource}), the
     * text generated from that resource will be returned. The localized string resource of the
     * label should be capitalized for inclusion in UI lists.
     *
     * <p>If {@code layoutLabelResource} is zero, the framework returns the non-localized
     * layout label, if specified through
     * {@link InputMethodSubtypeBuilder#setLayoutLabelNonLocalized setLayoutLabelNonLocalized}.
     *
     * @param context The context used for getting the
     * {@link android.content.pm.PackageManager PackageManager}.
     * @param imeAppInfo The {@link ApplicationInfo} of the input method.
     * @return the layout display name.
     */
    @NonNull
    @FlaggedApi(Flags.FLAG_IME_SWITCHER_REVAMP_API)
    public CharSequence getLayoutDisplayName(@NonNull Context context,
            @NonNull ApplicationInfo imeAppInfo) {
        if (!Flags.imeSwitcherRevampApi()) {
            return "";
        }
        Objects.requireNonNull(context, "context cannot be null");
        Objects.requireNonNull(imeAppInfo, "imeAppInfo cannot be null");
        if (mLayoutLabelResId == 0) {
            return mLayoutLabelNonLocalized;
        }

        final CharSequence subtypeLayoutName = context.getPackageManager().getText(
                imeAppInfo.packageName, mLayoutLabelResId, imeAppInfo);
        if (TextUtils.isEmpty(subtypeLayoutName)) {
            return "";
        }
        return subtypeLayoutName;
    }

    @Nullable
    private static Locale getLocaleFromContext(@Nullable final Context context) {
        if (context == null) {
@@ -778,6 +898,8 @@ public final class InputMethodSubtype implements Parcelable {
    public void writeToParcel(Parcel dest, int parcelableFlags) {
        dest.writeInt(mSubtypeNameResId);
        TextUtils.writeToParcel(mSubtypeNameOverride, dest, parcelableFlags);
        dest.writeInt(mLayoutLabelResId);
        TextUtils.writeToParcel(mLayoutLabelNonLocalized, dest, parcelableFlags);
        dest.writeString8(mPkLanguageTag);
        dest.writeString8(mPkLayoutType);
        dest.writeInt(mSubtypeIconResId);
@@ -794,6 +916,7 @@ public final class InputMethodSubtype implements Parcelable {

    void dump(@NonNull Printer pw, @NonNull String prefix) {
        pw.println(prefix + "mSubtypeNameOverride=" + mSubtypeNameOverride
                + " mLayoutLabelNonLocalized=" + mLayoutLabelNonLocalized
                + " mPkLanguageTag=" + mPkLanguageTag
                + " mPkLayoutType=" + mPkLayoutType
                + " mSubtypeId=" + mSubtypeId
+20 −3
Original line number Diff line number Diff line
@@ -18,18 +18,20 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/list_item"
    android:layout_width="match_parent"
    android:layout_height="72dp"
    android:layout_height="wrap_content"
    android:minHeight="72dp"
    android:background="@drawable/input_method_switch_item_background"
    android:gravity="center_vertical"
    android:orientation="horizontal"
    android:layout_marginHorizontal="16dp"
    android:layout_marginBottom="8dp"
    android:paddingStart="20dp"
    android:paddingEnd="24dp">
    android:paddingEnd="24dp"
    android:paddingVertical="8dp">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="start|center_vertical"
        android:orientation="vertical">
@@ -39,11 +41,26 @@
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ellipsize="marquee"
            android:marqueeRepeatLimit="1"
            android:singleLine="true"
            android:fontFamily="google-sans-text"
            android:textColor="@color/input_method_switch_on_item"
            android:textAppearance="?attr/textAppearanceListItem"/>

        <TextView
            android:id="@+id/text2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:ellipsize="marquee"
            android:marqueeRepeatLimit="1"
            android:singleLine="true"
            android:fontFamily="google-sans-text"
            android:textColor="?attr/materialColorOnSurfaceVariant"
            android:textAppearance="?attr/textAppearanceListItemSecondary"
            android:textAllCaps="true"
            android:visibility="gone"/>

    </LinearLayout>

    <ImageView
+4 −0
Original line number Diff line number Diff line
@@ -4418,6 +4418,10 @@
    <declare-styleable name="InputMethod_Subtype">
        <!-- The name of the subtype. -->
        <attr name="label" />
        <!-- The layout label of the subtype.
             {@link android.view.inputmethod.InputMethodSubtype#getLayoutDisplayName} returns the
             value specified in this attribute. -->
        <attr name="layoutLabel" format="reference" />
        <!-- The icon of the subtype. -->
        <attr name="icon" />
        <!-- The locale of the subtype. This string should be a locale (for example en_US and fr_FR)
+2 −0
Original line number Diff line number Diff line
@@ -125,6 +125,8 @@
    <public name="supplementalDescription"/>
    <!-- @FlaggedApi("android.security.enable_intent_matching_flags") -->
    <public name="intentMatchingFlags"/>
    <!-- @FlaggedApi(android.view.inputmethod.Flags.FLAG_IME_SWITCHER_REVAMP_API) -->
    <public name="layoutLabel"/>
  </staging-public-group>

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