import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
-import android.view.textservice.SpellCheckerInfo;
import android.service.textservice.SpellCheckerSession;
import android.service.textservice.SpellCheckerSession.SpellCheckerSessionListener;
+import android.util.Log;
import java.util.Locale;
*/
public final class TextServicesManager {
private static final String TAG = TextServicesManager.class.getSimpleName();
+ private static final boolean DBG = false;
private static TextServicesManager sInstance;
private static ITextServicesManager sService;
// TODO: Handle referToSpellCheckerLanguageSettings
public SpellCheckerSession newSpellCheckerSession(Locale locale,
SpellCheckerSessionListener listener, boolean referToSpellCheckerLanguageSettings) {
- if (locale == null || listener == null) {
+ 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 info;
try {
- info = sService.getCurrentSpellChecker(locale.toString());
+ info = sService.getCurrentSpellChecker(localeString);
} catch (RemoteException e) {
return null;
}
}
final SpellCheckerSession session = new SpellCheckerSession(info, sService, listener);
try {
- sService.getSpellCheckerService(
- info, locale.toString(), session.getTextServicesSessionListener(),
+ sService.getSpellCheckerService(info, localeString,
+ session.getTextServicesSessionListener(),
session.getSpellCheckerSessionListener());
} catch (RemoteException e) {
return null;
*/
public SpellCheckerInfo[] getEnabledSpellCheckers() {
try {
- return sService.getEnabledSpellCheckers();
+ final SpellCheckerInfo[] retval = sService.getEnabledSpellCheckers();
+ if (DBG) {
+ Log.d(TAG, "getEnabledSpellCheckers: " + (retval != null ? retval.length : "null"));
+ }
+ return retval;
} catch (RemoteException e) {
+ Log.e(TAG, "Error in getEnabledSpellCheckers: " + e);
return null;
}
}
buildSpellCheckerMapLocked(mContext, mSpellCheckerList, mSpellCheckerMap);
// TODO: Update for each locale
SpellCheckerInfo sci = getCurrentSpellChecker(null);
- if (sci == null) {
- sci = findAvailSpellCheckerLocked(null, null);
- if (sci == null) return;
- // Set the current spell checker if there is one or more spell checkers
- // available. In this case, "sci" is the first one in the available spell
- // checkers.
- setCurrentSpellChecker(sci);
- }
+ if (sci == null) return;
final String packageName = sci.getPackageName();
final int change = isPackageDisappearing(packageName);
if (change == PACKAGE_PERMANENT_CHANGE || change == PACKAGE_TEMPORARY_CHANGE) {
list.add(sci);
map.put(sci.getId(), sci);
}
+ if (DBG) {
+ Slog.d(TAG, "buildSpellCheckerMapLocked: " + list.size() + "," + map.size());
+ }
}
// TODO: find an appropriate spell checker for specified locale
for (int i = 0; i < spellCheckersCount; ++i) {
final SpellCheckerInfo sci = mSpellCheckerList.get(i);
if (prefPackage.equals(sci.getPackageName())) {
+ if (DBG) {
+ Slog.d(TAG, "findAvailSpellCheckerLocked: " + sci.getPackageName());
+ }
return sci;
}
}
@Override
public SpellCheckerInfo getCurrentSpellChecker(String locale) {
synchronized (mSpellCheckerMap) {
- final String curSpellCheckerId =
+ String curSpellCheckerId =
Settings.Secure.getString(mContext.getContentResolver(),
Settings.Secure.SPELL_CHECKER_SERVICE);
if (DBG) {
Slog.w(TAG, "getCurrentSpellChecker: " + curSpellCheckerId);
}
if (TextUtils.isEmpty(curSpellCheckerId)) {
- return null;
+ final SpellCheckerInfo sci = findAvailSpellCheckerLocked(null, null);
+ if (sci == null) return null;
+ // Set the current spell checker if there is one or more spell checkers
+ // available. In this case, "sci" is the first one in the available spell
+ // checkers.
+ setCurrentSpellChecker(sci);
+ return sci;
}
return mSpellCheckerMap.get(curSpellCheckerId);
}
@Override
public SpellCheckerInfo[] getEnabledSpellCheckers() {
+ if (DBG) {
+ Slog.d(TAG, "getEnabledSpellCheckers: " + mSpellCheckerList.size());
+ for (int i = 0; i < mSpellCheckerList.size(); ++i) {
+ Slog.d(TAG, "EnabledSpellCheckers: " + mSpellCheckerList.get(i).getPackageName());
+ }
+ }
return mSpellCheckerList.toArray(new SpellCheckerInfo[mSpellCheckerList.size()]);
}
@Override
public void finishSpellCheckerService(ISpellCheckerSessionListener listener) {
+ if (DBG) {
+ Slog.d(TAG, "FinishSpellCheckerService");
+ }
synchronized(mSpellCheckerMap) {
for (SpellCheckerBindGroup group : mSpellCheckerBindGroups.values()) {
if (group == null) continue;
}
public void onServiceConnected(ISpellCheckerService spellChecker) {
+ if (DBG) {
+ Slog.d(TAG, "onServiceConnected");
+ }
synchronized(mSpellCheckerMap) {
for (InternalDeathRecipient listener : mListeners) {
try {
public void addListener(ITextServicesSessionListener tsListener, String locale,
ISpellCheckerSessionListener scListener) {
+ if (DBG) {
+ Slog.d(TAG, "addListener: " + locale);
+ }
synchronized(mSpellCheckerMap) {
try {
final int size = mListeners.size();
}
public void removeListener(ISpellCheckerSessionListener listener) {
+ if (DBG) {
+ Slog.d(TAG, "remove listener");
+ }
synchronized(mSpellCheckerMap) {
final int size = mListeners.size();
final ArrayList<InternalDeathRecipient> removeList =
}
private void cleanLocked() {
+ if (DBG) {
+ Slog.d(TAG, "cleanLocked");
+ }
if (mListeners.isEmpty()) {
mSpellCheckerBindGroups.remove(this);
// Unbind service when there is no active clients.