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

Commit cc28a669 authored by satok's avatar satok Committed by Android (Google) Code Review
Browse files

Merge "Add an api to get the display name for InputMethodSubtype"

parents f9886f3e 4f31353c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -23190,6 +23190,7 @@ package android.view.inputmethod {
  public final class InputMethodSubtype implements android.os.Parcelable {
    method public boolean containsExtraValueKey(java.lang.String);
    method public int describeContents();
    method public java.lang.CharSequence getDisplayName(android.content.Context, java.lang.String, android.content.pm.ApplicationInfo);
    method public java.lang.String getExtraValue();
    method public java.lang.String getExtraValueOf(java.lang.String);
    method public int getIconResId();
+3 −1
Original line number Diff line number Diff line
@@ -145,7 +145,9 @@ public final class InputMethodInfo implements Parcelable {
                            a.getString(com.android.internal.R.styleable
                                    .InputMethod_Subtype_imeSubtypeMode),
                            a.getString(com.android.internal.R.styleable
                                    .InputMethod_Subtype_imeSubtypeExtraValue));
                                    .InputMethod_Subtype_imeSubtypeExtraValue),
                            a.getBoolean(com.android.internal.R.styleable
                                    .InputMethod_Subtype_isAuxiliary, false));
                    mSubtypes.add(subtype);
                }
            }
+27 −0
Original line number Diff line number Diff line
@@ -17,8 +17,10 @@
package android.view.inputmethod;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.Slog;

import java.util.ArrayList;
@@ -137,6 +139,31 @@ public final class InputMethodSubtype implements Parcelable {
        return mIsAuxiliary;
    }

    /**
     * @param context Context will be used for getting Locale and PackageManager.
     * @param packageName The package name of the IME
     * @param appInfo The application info of the IME
     * @return a display name for this subtype. The string resource of the label (mSubtypeNameResId)
     * can have only one %s in it. If there is, the %s part will be replaced with the locale's
     * display name by the formatter. If there is not, this method simply returns the string
     * specified by mSubtypeNameResId. If mSubtypeNameResId is not specified (== 0), it's up to the
     * framework to generate an appropriate display name.
     */
    public CharSequence getDisplayName(
            Context context, String packageName, ApplicationInfo appInfo) {
        final String locale = context.getResources().getConfiguration().locale.getDisplayName();
        if (mSubtypeNameResId == 0) {
            return locale;
        }
        final String subtypeName = context.getPackageManager().getText(
                packageName, mSubtypeNameResId, appInfo).toString();
        if (!TextUtils.isEmpty(subtypeName)) {
            return String.format(subtypeName, locale);
        } else {
            return locale;
        }
    }

    private HashMap<String, String> getExtraValueHashMap() {
        if (mExtraValueHashMapCache == null) {
            mExtraValueHashMapCache = new HashMap<String, String>();
+2 −3
Original line number Diff line number Diff line
@@ -422,9 +422,8 @@ public class InputMethodsPanel extends LinearLayout implements StatusBarPanel,
            Log.d(TAG, "Get text from: " + imi.getPackageName() + subtype.getNameResId()
                    + imi.getServiceInfo().applicationInfo);
        }
        // TODO: Change the language of subtype name according to subtype's locale.
        return mPackageManager.getText(
                imi.getPackageName(), subtype.getNameResId(), imi.getServiceInfo().applicationInfo);
        return subtype.getDisplayName(
                mContext, imi.getPackageName(), imi.getServiceInfo().applicationInfo);
    }

    private Drawable getSubtypeIcon(InputMethodInfo imi, InputMethodSubtype subtype) {
+2 −2
Original line number Diff line number Diff line
@@ -1885,8 +1885,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                            int nameResId = subtype.getNameResId();
                            String mode = subtype.getMode();
                            if (nameResId != 0) {
                                title = TextUtils.concat(pm.getText(imi.getPackageName(),
                                        nameResId, imi.getServiceInfo().applicationInfo),
                                title = TextUtils.concat(subtype.getDisplayName(context,
                                        imi.getPackageName(), imi.getServiceInfo().applicationInfo),
                                        (TextUtils.isEmpty(label) ? "" : " (" + label + ")"));
                            } else {
                                CharSequence language = subtype.getLocale();