Pass the previous word to getSuggestions
This is a preparative change to bug#6313806 Change-Id: I1be9ec49b21005c1f45ce459fa93712bc74ef3f0
This commit is contained in:
parent
9c2a96aa6c
commit
ac27e4544b
11 changed files with 39 additions and 28 deletions
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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][];
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue