aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
diff options
context:
space:
mode:
authorsatok <satok@google.com>2011-08-05 19:42:36 +0900
committersatok <satok@google.com>2011-08-05 19:57:47 +0900
commit5bcf8ee66ceb38675a6b70fefcb574978e0fae92 (patch)
tree22c197874fdcb181111dc931009d70873c3f5fcf /java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
parent576722698379e712561728335cf929163abf2e41 (diff)
downloadlatinime-5bcf8ee66ceb38675a6b70fefcb574978e0fae92.tar.gz
latinime-5bcf8ee66ceb38675a6b70fefcb574978e0fae92.tar.xz
latinime-5bcf8ee66ceb38675a6b70fefcb574978e0fae92.zip
Update the spell checker according to API cleanup
Change-Id: Ia95a63963c16265bc9bc7e1fcecf120e17bf8636
Diffstat (limited to 'java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java')
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java68
1 files changed, 41 insertions, 27 deletions
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
index 848dcbed5..7c92bc82a 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java
@@ -18,6 +18,7 @@ package com.android.inputmethod.latin.spellcheck;
import android.content.res.Resources;
import android.service.textservice.SpellCheckerService;
+import android.service.textservice.SpellCheckerService.Session;
import android.util.Log;
import android.view.textservice.SuggestionsInfo;
import android.view.textservice.TextInfo;
@@ -51,6 +52,11 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
private final Map<String, Dictionary> mDictionaries =
Collections.synchronizedMap(new TreeMap<String, Dictionary>());
+ @Override
+ public Session createSession() {
+ return new AndroidSpellCheckerSession();
+ }
+
private static class SuggestionsGatherer implements WordCallback {
private final int DEFAULT_SUGGESTION_LENGTH = 16;
private final String[] mSuggestions;
@@ -112,34 +118,42 @@ public class AndroidSpellCheckerService extends SpellCheckerService {
return dictionary;
}
- // Note : this must be reentrant
- /**
- * 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 even perform grammatical
- * analysis.
- */
- @Override
- public SuggestionsInfo getSuggestions(final TextInfo textInfo, final int suggestionsLimit,
- final String locale) {
- final Dictionary dictionary = getDictionary(locale);
- final String text = textInfo.getText();
-
- final SuggestionsGatherer suggestionsGatherer = new SuggestionsGatherer(suggestionsLimit);
- final WordComposer composer = new WordComposer();
- final int length = text.length();
- for (int i = 0; i < length; ++i) {
- int character = text.codePointAt(i);
- composer.add(character, new int[] { character },
- WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE);
+ private class AndroidSpellCheckerSession extends Session {
+ @Override
+ public void onCreate() {
}
- dictionary.getWords(composer, suggestionsGatherer, mProximityInfo);
- final boolean isInDict = dictionary.isValidWord(text);
- final String[] suggestions = suggestionsGatherer.getGatheredSuggestions();
- final int flags = (isInDict ? SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY : 0)
- | (null != suggestions ? SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO : 0);
- return new SuggestionsInfo(flags, suggestions);
+ // Note : this must be reentrant
+ /**
+ * 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
+ * even perform grammatical analysis.
+ */
+ @Override
+ public SuggestionsInfo onGetSuggestions(final TextInfo textInfo,
+ final int suggestionsLimit) {
+ final String locale = getLocale();
+ final Dictionary dictionary = getDictionary(locale);
+ final String text = textInfo.getText();
+
+ final SuggestionsGatherer suggestionsGatherer =
+ new SuggestionsGatherer(suggestionsLimit);
+ final WordComposer composer = new WordComposer();
+ final int length = text.length();
+ for (int i = 0; i < length; ++i) {
+ int character = text.codePointAt(i);
+ composer.add(character, new int[] { character },
+ WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE);
+ }
+ dictionary.getWords(composer, suggestionsGatherer, mProximityInfo);
+ final boolean isInDict = dictionary.isValidWord(text);
+ final String[] suggestions = suggestionsGatherer.getGatheredSuggestions();
+
+ final int flags =
+ (isInDict ? SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY : 0)
+ | (null != suggestions
+ ? SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO : 0);
+ return new SuggestionsInfo(flags, suggestions);
+ }
}
}