diff options
| author | 2011-06-02 02:34:32 -0700 | |
|---|---|---|
| committer | 2011-06-02 02:34:32 -0700 | |
| commit | cc28a669f61c71ec95e5cca2b25eab4266ea0cfb (patch) | |
| tree | fe0f7631c0a03fd10cfdf56bf9d22c3a065361ab | |
| parent | f9886f3ee9db23cc5a553b92e2aeff0ae842c915 (diff) | |
| parent | 4f31353cb3b00c77c9420ef27ec949fd570ede3b (diff) | |
Merge "Add an api to get the display name for InputMethodSubtype"
5 files changed, 35 insertions, 6 deletions
diff --git a/api/current.txt b/api/current.txt index d8d3cbc7ea2c..3a90ef7a3c3c 100644 --- a/api/current.txt +++ b/api/current.txt @@ -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(); diff --git a/core/java/android/view/inputmethod/InputMethodInfo.java b/core/java/android/view/inputmethod/InputMethodInfo.java index 1f7441de49cf..fee69e0f6566 100644 --- a/core/java/android/view/inputmethod/InputMethodInfo.java +++ b/core/java/android/view/inputmethod/InputMethodInfo.java @@ -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); } } diff --git a/core/java/android/view/inputmethod/InputMethodSubtype.java b/core/java/android/view/inputmethod/InputMethodSubtype.java index de38fbea6e5a..20cf93d36067 100644 --- a/core/java/android/view/inputmethod/InputMethodSubtype.java +++ b/core/java/android/view/inputmethod/InputMethodSubtype.java @@ -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>(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodsPanel.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodsPanel.java index e9db9983a186..339e3f3812b9 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodsPanel.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodsPanel.java @@ -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) { diff --git a/services/java/com/android/server/InputMethodManagerService.java b/services/java/com/android/server/InputMethodManagerService.java index c96273b2c629..f4308cdd4a45 100644 --- a/services/java/com/android/server/InputMethodManagerService.java +++ b/services/java/com/android/server/InputMethodManagerService.java @@ -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(); |