diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/ExpandableDictionary.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/ExpandableDictionary.java | 47 |
1 files changed, 21 insertions, 26 deletions
diff --git a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java index 76213c0da..f5886aa12 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java @@ -38,6 +38,7 @@ public class ExpandableDictionary extends Dictionary { private Context mContext; private char[] mWordBuilder = new char[BinaryDictionary.MAX_WORD_LENGTH]; + private int mDicTypeId; private int mMaxDepth; private int mInputLength; @@ -151,11 +152,11 @@ public class ExpandableDictionary extends Dictionary { private int[][] mCodes; - public ExpandableDictionary(final Context context, final String dictType) { - super(dictType); + public ExpandableDictionary(Context context, int dicTypeId) { mContext = context; clearDictionary(); mCodes = new int[BinaryDictionary.MAX_WORD_LENGTH][]; + mDicTypeId = dicTypeId; } public void loadDictionary() { @@ -247,20 +248,20 @@ public class ExpandableDictionary extends Dictionary { } @Override - public ArrayList<SuggestedWordInfo> getWords(final WordComposer codes, - final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) { + public void getWords(final WordComposer codes, final CharSequence prevWordForBigrams, + final WordCallback callback, final ProximityInfo proximityInfo) { synchronized (mUpdatingLock) { // If we need to update, start off a background task if (mRequiresReload) startDictionaryLoadingTaskLocked(); // Currently updating contacts, don't return any results. - if (mUpdatingDictionary) return null; + if (mUpdatingDictionary) return; } if (codes.size() >= BinaryDictionary.MAX_WORD_LENGTH) { - return null; + return; } final ArrayList<SuggestedWordInfo> suggestions = getWordsInner(codes, prevWordForBigrams, proximityInfo); - return suggestions; + Utils.addAllSuggestions(mDicTypeId, Dictionary.UNIGRAM, suggestions, callback); } protected final ArrayList<SuggestedWordInfo> getWordsInner(final WordComposer codes, @@ -268,9 +269,8 @@ public class ExpandableDictionary extends Dictionary { final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<SuggestedWordInfo>(); mInputLength = codes.size(); if (mCodes.length < mInputLength) mCodes = new int[mInputLength][]; - final InputPointers ips = codes.getInputPointers(); - final int[] xCoordinates = ips.getXCoordinates(); - final int[] yCoordinates = ips.getYCoordinates(); + final int[] xCoordinates = codes.getXCoordinates(); + final int[] yCoordinates = codes.getYCoordinates(); // Cache the codes so that we don't have to lookup an array list for (int i = 0; i < mInputLength; i++) { // TODO: Calculate proximity info here. @@ -383,7 +383,7 @@ public class ExpandableDictionary extends Dictionary { // the respective size of the typed word and the suggestion if it matters sometime // in the future. suggestions.add(new SuggestedWordInfo(new String(word, 0, depth + 1), finalFreq, - SuggestedWordInfo.KIND_CORRECTION, mDictType)); + SuggestedWordInfo.KIND_CORRECTION)); if (suggestions.size() >= Suggest.MAX_SUGGESTIONS) return false; } if (null != node.mShortcutTargets) { @@ -391,7 +391,7 @@ public class ExpandableDictionary extends Dictionary { for (int shortcutIndex = 0; shortcutIndex < length; ++shortcutIndex) { final char[] shortcut = node.mShortcutTargets.get(shortcutIndex); suggestions.add(new SuggestedWordInfo(new String(shortcut, 0, shortcut.length), - finalFreq, SuggestedWordInfo.KIND_SHORTCUT, mDictType)); + finalFreq, SuggestedWordInfo.KIND_SHORTCUT)); if (suggestions.size() > Suggest.MAX_SUGGESTIONS) return false; } } @@ -600,25 +600,22 @@ public class ExpandableDictionary extends Dictionary { } private void runBigramReverseLookUp(final CharSequence previousWord, - final ArrayList<SuggestedWordInfo> suggestions) { + final WordCallback callback) { // Search for the lowercase version of the word only, because that's where bigrams // store their sons. Node prevWord = searchNode(mRoots, previousWord.toString().toLowerCase(), 0, previousWord.length()); if (prevWord != null && prevWord.mNGrams != null) { - reverseLookUp(prevWord.mNGrams, suggestions); + reverseLookUp(prevWord.mNGrams, callback); } } @Override - public ArrayList<SuggestedWordInfo> getBigrams(final WordComposer codes, - final CharSequence previousWord) { + public void getBigrams(final WordComposer codes, final CharSequence previousWord, + final WordCallback callback) { if (!reloadDictionaryIfRequired()) { - final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<SuggestedWordInfo>(); - runBigramReverseLookUp(previousWord, suggestions); - return suggestions; + runBigramReverseLookUp(previousWord, callback); } - return null; } /** @@ -645,12 +642,11 @@ public class ExpandableDictionary extends Dictionary { /** * reverseLookUp retrieves the full word given a list of terminal nodes and adds those words - * to the suggestions list passed as an argument. + * through callback. * @param terminalNodes list of terminal nodes we want to add - * @param suggestions the suggestion collection to add the word to */ private void reverseLookUp(LinkedList<NextWord> terminalNodes, - final ArrayList<SuggestedWordInfo> suggestions) { + final WordCallback callback) { Node node; int freq; for (NextWord nextWord : terminalNodes) { @@ -664,9 +660,8 @@ public class ExpandableDictionary extends Dictionary { } while (node != null); if (freq >= 0) { - suggestions.add(new SuggestedWordInfo(new String(mLookedUpString, index, - BinaryDictionary.MAX_WORD_LENGTH - index), - freq, SuggestedWordInfo.KIND_CORRECTION, mDictType)); + callback.addWord(mLookedUpString, index, BinaryDictionary.MAX_WORD_LENGTH - index, + freq, mDicTypeId, Dictionary.BIGRAM); } } } |