summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author satok <satok@google.com> 2011-08-26 02:55:06 -0700
committer Android (Google) Code Review <android-gerrit@google.com> 2011-08-26 02:55:06 -0700
commitca6d29da777cffd40d9f3e38f95663ba1a2002c5 (patch)
treec8e1949e4d6231f23ec623b14596e0e866dd4be8
parentbc81b692d51a9cd6f9d61584aacd8308ac3366ea (diff)
parentb387954a92eb6f15b7f49d5b946745f492a26363 (diff)
Merge "Support system locale as the locale of the spell checkers"
-rw-r--r--core/java/android/view/textservice/TextServicesManager.java33
-rw-r--r--services/java/com/android/server/TextServicesManagerService.java35
2 files changed, 50 insertions, 18 deletions
diff --git a/core/java/android/view/textservice/TextServicesManager.java b/core/java/android/view/textservice/TextServicesManager.java
index 3e376da8e54b..adfb0dfd4653 100644
--- a/core/java/android/view/textservice/TextServicesManager.java
+++ b/core/java/android/view/textservice/TextServicesManager.java
@@ -72,27 +72,48 @@ public final class TextServicesManager {
* languages in settings will be returned.
* @return the spell checker session of the spell checker
*/
- // TODO: Add a method to get enabled spell checkers.
- // TODO: Handle referToSpellCheckerLanguageSettings
public SpellCheckerSession newSpellCheckerSession(Bundle bundle, Locale locale,
SpellCheckerSessionListener listener, boolean referToSpellCheckerLanguageSettings) {
if (listener == null) {
throw new NullPointerException();
}
- // TODO: set a proper locale instead of the dummy locale
- final String localeString = locale == null ? "en" : locale.toString();
final SpellCheckerInfo sci;
try {
- sci = sService.getCurrentSpellChecker(localeString);
+ sci = sService.getCurrentSpellChecker(null);
} catch (RemoteException e) {
return null;
}
if (sci == null) {
return null;
}
+ SpellCheckerSubtype subtypeInUse = null;
+ if (referToSpellCheckerLanguageSettings) {
+ subtypeInUse = getCurrentSpellCheckerSubtype(true);
+ if (subtypeInUse == null) {
+ return null;
+ }
+ if (locale != null) {
+ final String subtypeLocale = subtypeInUse.getLocale();
+ final String inputLocale = locale.toString();
+ if (subtypeLocale.length() < 2 || inputLocale.length() < 2
+ || !subtypeLocale.substring(0, 2).equals(inputLocale.substring(0, 2))) {
+ return null;
+ }
+ }
+ } else {
+ for (int i = 0; i < sci.getSubtypeCount(); ++i) {
+ final SpellCheckerSubtype subtype = sci.getSubtypeAt(i);
+ if (subtype.getLocale().equals(locale)) {
+ subtypeInUse = subtype;
+ }
+ }
+ }
+ if (subtypeInUse == null) {
+ return null;
+ }
final SpellCheckerSession session = new SpellCheckerSession(sci, sService, listener);
try {
- sService.getSpellCheckerService(sci.getId(), localeString,
+ sService.getSpellCheckerService(sci.getId(), subtypeInUse.getLocale(),
session.getTextServicesSessionListener(),
session.getSpellCheckerSessionListener(), bundle);
} catch (RemoteException e) {
diff --git a/services/java/com/android/server/TextServicesManagerService.java b/services/java/com/android/server/TextServicesManagerService.java
index c65f2990cddc..e27c11f70446 100644
--- a/services/java/com/android/server/TextServicesManagerService.java
+++ b/services/java/com/android/server/TextServicesManagerService.java
@@ -210,29 +210,40 @@ public class TextServicesManagerService extends ITextServicesManager.Stub {
}
return null;
}
- if (TextUtils.isEmpty(subtypeHashCodeStr)) {
- if (DBG) {
- Slog.w(TAG, "Return first subtype in " + sci.getId());
- }
- return null;
+ final int hashCode;
+ if (!TextUtils.isEmpty(subtypeHashCodeStr)) {
+ hashCode = Integer.valueOf(subtypeHashCodeStr);
+ } else {
+ hashCode = 0;
}
- final int hashCode = Integer.valueOf(subtypeHashCodeStr);
- if (hashCode == 0) {
+ if (hashCode == 0 && !allowImplicitlySelectedSubtype) {
return null;
}
+ final String systemLocale =
+ mContext.getResources().getConfiguration().locale.toString();
+ SpellCheckerSubtype candidate = null;
for (int i = 0; i < sci.getSubtypeCount(); ++i) {
final SpellCheckerSubtype scs = sci.getSubtypeAt(i);
- if (scs.hashCode() == hashCode) {
+ if (hashCode == 0) {
+ if (systemLocale.equals(locale)) {
+ return scs;
+ } else if (candidate == null) {
+ final String scsLocale = scs.getLocale();
+ if (systemLocale.length() >= 2
+ && scsLocale.length() >= 2
+ && systemLocale.substring(0, 2).equals(
+ scsLocale.substring(0, 2))) {
+ candidate = scs;
+ }
+ }
+ } else if (scs.hashCode() == hashCode) {
if (DBG) {
Slog.w(TAG, "Return subtype " + scs.hashCode());
}
return scs;
}
}
- if (DBG) {
- Slog.w(TAG, "Return first subtype in " + sci.getId());
- }
- return null;
+ return candidate;
}
}