From ac27e4544b5b5ff7b4f365a4bde5c288d511ae13 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 17 Apr 2012 12:43:53 +0900 Subject: [PATCH] Pass the previous word to getSuggestions This is a preparative change to bug#6313806 Change-Id: I1be9ec49b21005c1f45ce459fa93712bc74ef3f0 --- .../android/inputmethod/latin/BinaryDictionary.java | 13 ++++++++----- .../com/android/inputmethod/latin/Dictionary.java | 4 +++- .../inputmethod/latin/DictionaryCollection.java | 6 +++--- .../latin/ExpandableBinaryDictionary.java | 11 ++++++----- .../inputmethod/latin/ExpandableDictionary.java | 9 +++++---- java/src/com/android/inputmethod/latin/Suggest.java | 2 +- ...SynchronouslyLoadedContactsBinaryDictionary.java | 5 +++-- .../SynchronouslyLoadedContactsDictionary.java | 5 +++-- .../latin/SynchronouslyLoadedUserDictionary.java | 5 +++-- .../android/inputmethod/latin/UserDictionary.java | 5 +++-- .../spellcheck/AndroidSpellCheckerService.java | 2 +- 11 files changed, 39 insertions(+), 28 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index 2d958e17d..f4c8e61ed 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -135,11 +135,12 @@ public class BinaryDictionary extends Dictionary { } } - // proximityInfo may not be null. + // proximityInfo and/or prevWordForBigrams may not be null. @Override - public void getWords(final WordComposer codes, final WordCallback callback, - final ProximityInfo proximityInfo) { - final int count = getSuggestions(codes, proximityInfo, mOutputChars, mScores); + public void getWords(final WordComposer codes, final CharSequence prevWordForBigrams, + final WordCallback callback, final ProximityInfo proximityInfo) { + final int count = getSuggestions(codes, prevWordForBigrams, proximityInfo, mOutputChars, + mScores); for (int j = 0; j < count; ++j) { if (mScores[j] < 1) break; @@ -161,7 +162,8 @@ public class BinaryDictionary extends Dictionary { // proximityInfo may not be null. /* package for test */ int getSuggestions(final WordComposer codes, - final ProximityInfo proximityInfo, char[] outputChars, int[] scores) { + final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo, + char[] outputChars, int[] scores) { if (!isValidDictionary()) return -1; final int codesSize = codes.size(); @@ -175,6 +177,7 @@ public class BinaryDictionary extends Dictionary { Arrays.fill(outputChars, (char) 0); Arrays.fill(scores, 0); + // TODO: pass the previous word to native code return getSuggestionsNative( mNativeDict, proximityInfo.getNativeProximityInfo(), codes.getXCoordinates(), codes.getYCoordinates(), mInputCodes, codesSize, diff --git a/java/src/com/android/inputmethod/latin/Dictionary.java b/java/src/com/android/inputmethod/latin/Dictionary.java index 9d26a2343..a405aa409 100644 --- a/java/src/com/android/inputmethod/latin/Dictionary.java +++ b/java/src/com/android/inputmethod/latin/Dictionary.java @@ -61,11 +61,13 @@ public abstract class Dictionary { * Searches for words in the dictionary that match the characters in the composer. Matched * words are added through the callback object. * @param composer the key sequence to match + * @param prevWordForBigrams the previous word, or null if none * @param callback the callback object to send matched words to as possible candidates * @param proximityInfo the object for key proximity. May be ignored by some implementations. * @see WordCallback#addWord(char[], int, int, int, int, int) */ - abstract public void getWords(final WordComposer composer, final WordCallback callback, + abstract public void getWords(final WordComposer composer, + final CharSequence prevWordForBigrams, final WordCallback callback, final ProximityInfo proximityInfo); /** diff --git a/java/src/com/android/inputmethod/latin/DictionaryCollection.java b/java/src/com/android/inputmethod/latin/DictionaryCollection.java index 5de770a4a..37deb0c5d 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryCollection.java +++ b/java/src/com/android/inputmethod/latin/DictionaryCollection.java @@ -50,10 +50,10 @@ public class DictionaryCollection extends Dictionary { } @Override - public void getWords(final WordComposer composer, final WordCallback callback, - final ProximityInfo proximityInfo) { + public void getWords(final WordComposer composer, final CharSequence prevWordForBigrams, + final WordCallback callback, final ProximityInfo proximityInfo) { for (final Dictionary dict : mDictionaries) - dict.getWords(composer, callback, proximityInfo); + dict.getWords(composer, prevWordForBigrams, callback, proximityInfo); } @Override diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java index 53e8b74de..7d2ccdf5f 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java @@ -173,20 +173,21 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { } @Override - public void getWords(final WordComposer codes, final WordCallback callback, - final ProximityInfo proximityInfo) { + public void getWords(final WordComposer codes, final CharSequence prevWordForBigrams, + final WordCallback callback, final ProximityInfo proximityInfo) { asyncReloadDictionaryIfRequired(); - getWordsInner(codes, callback, proximityInfo); + getWordsInner(codes, prevWordForBigrams, callback, proximityInfo); } - protected final void getWordsInner(final WordComposer codes, final WordCallback callback, + protected final void getWordsInner(final WordComposer codes, + final CharSequence prevWordForBigrams, final WordCallback callback, final ProximityInfo proximityInfo) { // Ensure that there are no concurrent calls to getWords. If there are, do nothing and // return. if (mLocalDictionaryController.tryLock()) { try { if (mBinaryDictionary != null) { - mBinaryDictionary.getWords(codes, callback, proximityInfo); + mBinaryDictionary.getWords(codes, prevWordForBigrams, callback, proximityInfo); } } finally { mLocalDictionaryController.unlock(); diff --git a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java index 46d11fa37..fe21ebe87 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java @@ -192,8 +192,8 @@ public class ExpandableDictionary extends Dictionary { } @Override - public void getWords(final WordComposer codes, final WordCallback callback, - 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(); @@ -203,10 +203,11 @@ public class ExpandableDictionary extends Dictionary { if (codes.size() >= BinaryDictionary.MAX_WORD_LENGTH) { return; } - getWordsInner(codes, callback, proximityInfo); + getWordsInner(codes, prevWordForBigrams, callback, proximityInfo); } - protected final void getWordsInner(final WordComposer codes, final WordCallback callback, + protected final void getWordsInner(final WordComposer codes, + final CharSequence prevWordForBigrams, final WordCallback callback, @SuppressWarnings("unused") final ProximityInfo proximityInfo) { mInputLength = codes.size(); if (mCodes.length < mInputLength) mCodes = new int[mInputLength][]; diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 51ebfdad6..86753e2cc 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -340,7 +340,7 @@ public class Suggest implements Dictionary.WordCallback { if (key.equals(DICT_KEY_USER_HISTORY_UNIGRAM) || key.equals(DICT_KEY_WHITELIST)) continue; final Dictionary dictionary = mUnigramDictionaries.get(key); - dictionary.getWords(wordComposerForLookup, this, proximityInfo); + dictionary.getWords(wordComposerForLookup, prevWordForBigram, this, proximityInfo); } } diff --git a/java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsBinaryDictionary.java b/java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsBinaryDictionary.java index 80825a887..188259ff8 100644 --- a/java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsBinaryDictionary.java @@ -30,10 +30,11 @@ public class SynchronouslyLoadedContactsBinaryDictionary extends ContactsBinaryD } @Override - public synchronized void getWords(final WordComposer codes, final WordCallback callback, + public synchronized void getWords(final WordComposer codes, + final CharSequence prevWordForBigrams, final WordCallback callback, final ProximityInfo proximityInfo) { syncReloadDictionaryIfRequired(); - getWordsInner(codes, callback, proximityInfo); + getWordsInner(codes, prevWordForBigrams, callback, proximityInfo); } @Override diff --git a/java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsDictionary.java b/java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsDictionary.java index 444c7f5f0..a8b871cdf 100644 --- a/java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsDictionary.java +++ b/java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsDictionary.java @@ -29,10 +29,11 @@ public class SynchronouslyLoadedContactsDictionary extends ContactsDictionary { } @Override - public synchronized void getWords(final WordComposer codes, final WordCallback callback, + public synchronized void getWords(final WordComposer codes, + final CharSequence prevWordForBigrams, final WordCallback callback, final ProximityInfo proximityInfo) { blockingReloadDictionaryIfRequired(); - getWordsInner(codes, callback, proximityInfo); + getWordsInner(codes, prevWordForBigrams, callback, proximityInfo); } @Override diff --git a/java/src/com/android/inputmethod/latin/SynchronouslyLoadedUserDictionary.java b/java/src/com/android/inputmethod/latin/SynchronouslyLoadedUserDictionary.java index e52b46ac0..50e8b249e 100644 --- a/java/src/com/android/inputmethod/latin/SynchronouslyLoadedUserDictionary.java +++ b/java/src/com/android/inputmethod/latin/SynchronouslyLoadedUserDictionary.java @@ -32,10 +32,11 @@ public class SynchronouslyLoadedUserDictionary extends UserDictionary { } @Override - public synchronized void getWords(final WordComposer codes, final WordCallback callback, + public synchronized void getWords(final WordComposer codes, + final CharSequence prevWordForBigrams, final WordCallback callback, final ProximityInfo proximityInfo) { blockingReloadDictionaryIfRequired(); - getWordsInner(codes, callback, proximityInfo); + getWordsInner(codes, prevWordForBigrams, callback, proximityInfo); } @Override diff --git a/java/src/com/android/inputmethod/latin/UserDictionary.java b/java/src/com/android/inputmethod/latin/UserDictionary.java index 51b993343..6beeaace9 100644 --- a/java/src/com/android/inputmethod/latin/UserDictionary.java +++ b/java/src/com/android/inputmethod/latin/UserDictionary.java @@ -174,9 +174,10 @@ public class UserDictionary extends ExpandableDictionary { } @Override - public synchronized void getWords(final WordComposer codes, final WordCallback callback, + public synchronized void getWords(final WordComposer codes, + final CharSequence prevWordForBigrams, final WordCallback callback, final ProximityInfo proximityInfo) { - super.getWords(codes, callback, proximityInfo); + super.getWords(codes, prevWordForBigrams, callback, proximityInfo); } @Override diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java index 44dac30d7..34e214da7 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java @@ -588,7 +588,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService try { dictInfo = mDictionaryPool.takeOrGetNull(); if (null == dictInfo) return getNotInDictEmptySuggestions(); - dictInfo.mDictionary.getWords(composer, suggestionsGatherer, + dictInfo.mDictionary.getWords(composer, null, suggestionsGatherer, dictInfo.mProximityInfo); isInDict = dictInfo.mDictionary.isValidWord(text); if (!isInDict && CAPITALIZE_NONE != capitalizeType) {