Update the spell checker according to API cleanup

Change-Id: Ia95a63963c16265bc9bc7e1fcecf120e17bf8636
This commit is contained in:
satok 2011-08-05 19:42:36 +09:00
parent 5767226983
commit 5bcf8ee66c

View file

@ -18,6 +18,7 @@ package com.android.inputmethod.latin.spellcheck;
import android.content.res.Resources; import android.content.res.Resources;
import android.service.textservice.SpellCheckerService; import android.service.textservice.SpellCheckerService;
import android.service.textservice.SpellCheckerService.Session;
import android.util.Log; import android.util.Log;
import android.view.textservice.SuggestionsInfo; import android.view.textservice.SuggestionsInfo;
import android.view.textservice.TextInfo; import android.view.textservice.TextInfo;
@ -51,6 +52,11 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
private final Map<String, Dictionary> mDictionaries = private final Map<String, Dictionary> mDictionaries =
Collections.synchronizedMap(new TreeMap<String, Dictionary>()); Collections.synchronizedMap(new TreeMap<String, Dictionary>());
@Override
public Session createSession() {
return new AndroidSpellCheckerSession();
}
private static class SuggestionsGatherer implements WordCallback { private static class SuggestionsGatherer implements WordCallback {
private final int DEFAULT_SUGGESTION_LENGTH = 16; private final int DEFAULT_SUGGESTION_LENGTH = 16;
private final String[] mSuggestions; private final String[] mSuggestions;
@ -112,21 +118,26 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
return dictionary; return dictionary;
} }
private class AndroidSpellCheckerSession extends Session {
@Override
public void onCreate() {
}
// Note : this must be reentrant // Note : this must be reentrant
/** /**
* Gets a list of suggestions for a specific string. * Gets a list of suggestions for a specific string. This returns a list of possible
* * corrections for the text passed as an arguments. It may split or group words, and
* This returns a list of possible corrections for the text passed as an * even perform grammatical analysis.
* arguments. It may split or group words, and even perform grammatical
* analysis.
*/ */
@Override @Override
public SuggestionsInfo getSuggestions(final TextInfo textInfo, final int suggestionsLimit, public SuggestionsInfo onGetSuggestions(final TextInfo textInfo,
final String locale) { final int suggestionsLimit) {
final String locale = getLocale();
final Dictionary dictionary = getDictionary(locale); final Dictionary dictionary = getDictionary(locale);
final String text = textInfo.getText(); final String text = textInfo.getText();
final SuggestionsGatherer suggestionsGatherer = new SuggestionsGatherer(suggestionsLimit); final SuggestionsGatherer suggestionsGatherer =
new SuggestionsGatherer(suggestionsLimit);
final WordComposer composer = new WordComposer(); final WordComposer composer = new WordComposer();
final int length = text.length(); final int length = text.length();
for (int i = 0; i < length; ++i) { for (int i = 0; i < length; ++i) {
@ -138,8 +149,11 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
final boolean isInDict = dictionary.isValidWord(text); final boolean isInDict = dictionary.isValidWord(text);
final String[] suggestions = suggestionsGatherer.getGatheredSuggestions(); final String[] suggestions = suggestionsGatherer.getGatheredSuggestions();
final int flags = (isInDict ? SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY : 0) final int flags =
| (null != suggestions ? SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO : 0); (isInDict ? SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY : 0)
| (null != suggestions
? SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO : 0);
return new SuggestionsInfo(flags, suggestions); return new SuggestionsInfo(flags, suggestions);
} }
}
} }