From 5bcf8ee66ceb38675a6b70fefcb574978e0fae92 Mon Sep 17 00:00:00 2001 From: satok Date: Fri, 5 Aug 2011 19:42:36 +0900 Subject: [PATCH] Update the spell checker according to API cleanup Change-Id: Ia95a63963c16265bc9bc7e1fcecf120e17bf8636 --- .../AndroidSpellCheckerService.java | 68 +++++++++++-------- 1 file 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 mDictionaries = Collections.synchronizedMap(new TreeMap()); + @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); + } } }