summaryrefslogtreecommitdiffstats
path: root/core/java/android/view/textservice
diff options
context:
space:
mode:
authorsatok <satok@google.com>2011-08-26 13:58:29 +0900
committersatok <satok@google.com>2011-08-26 14:04:46 +0900
commitc714531952fe1c22cae77631aa25dc7441b2b878 (patch)
tree86ddaabfb73a78c5c8cfffbc2474345b10fda7f0 /core/java/android/view/textservice
parent10975366bee242d527ec82aa1d6ce3c587355b25 (diff)
downloadframeworks_base-c714531952fe1c22cae77631aa25dc7441b2b878.zip
frameworks_base-c714531952fe1c22cae77631aa25dc7441b2b878.tar.gz
frameworks_base-c714531952fe1c22cae77631aa25dc7441b2b878.tar.bz2
Add getDisplayName to SpellCheckerSubtype
Change-Id: Ic4d1f494a1fb67eda73ffc8e3be1caf690a602ce
Diffstat (limited to 'core/java/android/view/textservice')
-rw-r--r--core/java/android/view/textservice/SpellCheckerSubtype.java45
1 files changed, 45 insertions, 0 deletions
diff --git a/core/java/android/view/textservice/SpellCheckerSubtype.java b/core/java/android/view/textservice/SpellCheckerSubtype.java
index dbd3081..aeb3ba6 100644
--- a/core/java/android/view/textservice/SpellCheckerSubtype.java
+++ b/core/java/android/view/textservice/SpellCheckerSubtype.java
@@ -17,13 +17,16 @@
package android.view.textservice;
import android.content.Context;
+import android.content.pm.ApplicationInfo;
import android.os.Parcel;
import android.os.Parcelable;
+import android.text.TextUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
+import java.util.Locale;
/**
* This class is used to specify meta information of a subtype contained in a spell checker.
@@ -97,6 +100,48 @@ public final class SpellCheckerSubtype implements Parcelable {
return false;
}
+ private static Locale constructLocaleFromString(String localeStr) {
+ if (TextUtils.isEmpty(localeStr))
+ return null;
+ String[] localeParams = localeStr.split("_", 3);
+ // The length of localeStr is guaranteed to always return a 1 <= value <= 3
+ // because localeStr is not empty.
+ if (localeParams.length == 1) {
+ return new Locale(localeParams[0]);
+ } else if (localeParams.length == 2) {
+ return new Locale(localeParams[0], localeParams[1]);
+ } else if (localeParams.length == 3) {
+ return new Locale(localeParams[0], localeParams[1], localeParams[2]);
+ }
+ return null;
+ }
+
+ /**
+ * @param context Context will be used for getting Locale and PackageManager.
+ * @param packageName The package name of the spell checker
+ * @param appInfo The application info of the spell checker
+ * @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 Locale locale = constructLocaleFromString(mSubtypeLocale);
+ final String localeStr = locale != null ? locale.getDisplayName() : mSubtypeLocale;
+ if (mSubtypeNameResId == 0) {
+ return localeStr;
+ }
+ final CharSequence subtypeName = context.getPackageManager().getText(
+ packageName, mSubtypeNameResId, appInfo);
+ if (!TextUtils.isEmpty(subtypeName)) {
+ return String.format(subtypeName.toString(), localeStr);
+ } else {
+ return localeStr;
+ }
+ }
+
@Override
public int describeContents() {
return 0;