Merge "Remove the callback argument to getWords() (A15)"

main
Jean Chalard 2012-06-26 01:53:24 -07:00 committed by Android (Google) Code Review
commit 89239eeb74
8 changed files with 18 additions and 29 deletions

View File

@ -147,8 +147,7 @@ public class BinaryDictionary extends Dictionary {
// proximityInfo and/or prevWordForBigrams may not be null. // proximityInfo and/or prevWordForBigrams may not be null.
@Override @Override
public ArrayList<SuggestedWordInfo> getWords(final WordComposer codes, public ArrayList<SuggestedWordInfo> getWords(final WordComposer codes,
final CharSequence prevWordForBigrams, final WordCallback callback, final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) {
final ProximityInfo proximityInfo) {
final int count = getSuggestions(codes, prevWordForBigrams, proximityInfo, mOutputChars, final int count = getSuggestions(codes, prevWordForBigrams, proximityInfo, mOutputChars,
mScores, mSpaceIndices); mScores, mSpaceIndices);

View File

@ -59,17 +59,15 @@ public abstract class Dictionary {
/** /**
* Searches for words in the dictionary that match the characters in the composer. Matched * Searches for words in the dictionary that match the characters in the composer. Matched
* words are added through the callback object. * words are returned as an ArrayList.
* @param composer the key sequence to match * @param composer the key sequence to match with coordinate info, as a WordComposer
* @param prevWordForBigrams the previous word, or null if none * @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. * @param proximityInfo the object for key proximity. May be ignored by some implementations.
* @return the list of suggestions * @return the list of suggestions
* @see WordCallback#addWord(char[], int, int, int, int, int) * @see WordCallback#addWord(char[], int, int, int, int, int)
*/ */
abstract public ArrayList<SuggestedWordInfo> getWords(final WordComposer composer, abstract public ArrayList<SuggestedWordInfo> getWords(final WordComposer composer,
final CharSequence prevWordForBigrams, final WordCallback callback, final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo);
final ProximityInfo proximityInfo);
/** /**
* Searches for pairs in the bigram dictionary that matches the previous word and all the * Searches for pairs in the bigram dictionary that matches the previous word and all the

View File

@ -53,19 +53,18 @@ public class DictionaryCollection extends Dictionary {
@Override @Override
public ArrayList<SuggestedWordInfo> getWords(final WordComposer composer, public ArrayList<SuggestedWordInfo> getWords(final WordComposer composer,
final CharSequence prevWordForBigrams, final WordCallback callback, final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) {
final ProximityInfo proximityInfo) {
final CopyOnWriteArrayList<Dictionary> dictionaries = mDictionaries; final CopyOnWriteArrayList<Dictionary> dictionaries = mDictionaries;
if (dictionaries.isEmpty()) return null; if (dictionaries.isEmpty()) return null;
// To avoid creating unnecessary objects, we get the list out of the first // To avoid creating unnecessary objects, we get the list out of the first
// dictionary and add the rest to it if not null, hence the get(0) // dictionary and add the rest to it if not null, hence the get(0)
ArrayList<SuggestedWordInfo> suggestions = dictionaries.get(0).getWords(composer, ArrayList<SuggestedWordInfo> suggestions = dictionaries.get(0).getWords(composer,
prevWordForBigrams, callback, proximityInfo); prevWordForBigrams, proximityInfo);
if (null == suggestions) suggestions = new ArrayList<SuggestedWordInfo>(); if (null == suggestions) suggestions = new ArrayList<SuggestedWordInfo>();
final int length = dictionaries.size(); final int length = dictionaries.size();
for (int i = 0; i < length; ++ i) { for (int i = 0; i < length; ++ i) {
final ArrayList<SuggestedWordInfo> sugg = dictionaries.get(i).getWords(composer, final ArrayList<SuggestedWordInfo> sugg = dictionaries.get(i).getWords(composer,
prevWordForBigrams, callback, proximityInfo); prevWordForBigrams, proximityInfo);
if (null != sugg) suggestions.addAll(sugg); if (null != sugg) suggestions.addAll(sugg);
} }
return suggestions; return suggestions;

View File

@ -196,22 +196,19 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
@Override @Override
public ArrayList<SuggestedWordInfo> getWords(final WordComposer codes, public ArrayList<SuggestedWordInfo> getWords(final WordComposer codes,
final CharSequence prevWordForBigrams, final WordCallback callback, final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) {
final ProximityInfo proximityInfo) {
asyncReloadDictionaryIfRequired(); asyncReloadDictionaryIfRequired();
return getWordsInner(codes, prevWordForBigrams, callback, proximityInfo); return getWordsInner(codes, prevWordForBigrams, proximityInfo);
} }
protected final ArrayList<SuggestedWordInfo> getWordsInner(final WordComposer codes, protected final ArrayList<SuggestedWordInfo> getWordsInner(final WordComposer codes,
final CharSequence prevWordForBigrams, final WordCallback callback, final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) {
final ProximityInfo proximityInfo) {
// Ensure that there are no concurrent calls to getWords. If there are, do nothing and // Ensure that there are no concurrent calls to getWords. If there are, do nothing and
// return. // return.
if (mLocalDictionaryController.tryLock()) { if (mLocalDictionaryController.tryLock()) {
try { try {
if (mBinaryDictionary != null) { if (mBinaryDictionary != null) {
return mBinaryDictionary.getWords(codes, prevWordForBigrams, callback, return mBinaryDictionary.getWords(codes, prevWordForBigrams, proximityInfo);
proximityInfo);
} }
} finally { } finally {
mLocalDictionaryController.unlock(); mLocalDictionaryController.unlock();

View File

@ -249,8 +249,7 @@ public class ExpandableDictionary extends Dictionary {
@Override @Override
public ArrayList<SuggestedWordInfo> getWords(final WordComposer codes, public ArrayList<SuggestedWordInfo> getWords(final WordComposer codes,
final CharSequence prevWordForBigrams, final WordCallback callback, final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) {
final ProximityInfo proximityInfo) {
synchronized (mUpdatingLock) { synchronized (mUpdatingLock) {
// If we need to update, start off a background task // If we need to update, start off a background task
if (mRequiresReload) startDictionaryLoadingTaskLocked(); if (mRequiresReload) startDictionaryLoadingTaskLocked();

View File

@ -292,9 +292,8 @@ public class Suggest implements Dictionary.WordCallback {
continue; continue;
final int dicTypeId = sDictKeyToDictIndex.get(key); final int dicTypeId = sDictKeyToDictIndex.get(key);
final Dictionary dictionary = mUnigramDictionaries.get(key); final Dictionary dictionary = mUnigramDictionaries.get(key);
final ArrayList<SuggestedWordInfo> suggestions = final ArrayList<SuggestedWordInfo> suggestions = dictionary.getWords(
dictionary.getWords(wordComposerForLookup, prevWordForBigram, this, wordComposerForLookup, prevWordForBigram, proximityInfo);
proximityInfo);
for (final SuggestedWordInfo suggestion : suggestions) { for (final SuggestedWordInfo suggestion : suggestions) {
final String suggestionStr = suggestion.mWord.toString(); final String suggestionStr = suggestion.mWord.toString();
oldAddWord(suggestionStr.toCharArray(), null, 0, suggestionStr.length(), oldAddWord(suggestionStr.toCharArray(), null, 0, suggestionStr.length(),

View File

@ -33,10 +33,9 @@ public class SynchronouslyLoadedContactsBinaryDictionary extends ContactsBinaryD
@Override @Override
public synchronized ArrayList<SuggestedWordInfo> getWords(final WordComposer codes, public synchronized ArrayList<SuggestedWordInfo> getWords(final WordComposer codes,
final CharSequence prevWordForBigrams, final WordCallback callback, final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) {
final ProximityInfo proximityInfo) {
syncReloadDictionaryIfRequired(); syncReloadDictionaryIfRequired();
return getWordsInner(codes, prevWordForBigrams, callback, proximityInfo); return getWordsInner(codes, prevWordForBigrams, proximityInfo);
} }
@Override @Override

View File

@ -36,10 +36,9 @@ public class SynchronouslyLoadedUserBinaryDictionary extends UserBinaryDictionar
@Override @Override
public synchronized ArrayList<SuggestedWordInfo> getWords(final WordComposer codes, public synchronized ArrayList<SuggestedWordInfo> getWords(final WordComposer codes,
final CharSequence prevWordForBigrams, final WordCallback callback, final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo) {
final ProximityInfo proximityInfo) {
syncReloadDictionaryIfRequired(); syncReloadDictionaryIfRequired();
return getWordsInner(codes, prevWordForBigrams, callback, proximityInfo); return getWordsInner(codes, prevWordForBigrams, proximityInfo);
} }
@Override @Override