Merge "Support system locale as the locale of the spell checkers"
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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 = Integer.valueOf(subtypeHashCodeStr);
|
||||
if (hashCode == 0) {
|
||||
final int hashCode;
|
||||
if (!TextUtils.isEmpty(subtypeHashCodeStr)) {
|
||||
hashCode = Integer.valueOf(subtypeHashCodeStr);
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user