Remove dependency on WordCallback from BinaryDictionary (A7)

Bug: 6252660
Bug: 6166228
Bug: 2704000
Bug: 6225530
Change-Id: I8245698fbd170e0f5cbad3c0109774bcaddc0614
main
Jean Chalard 2012-06-13 03:31:46 +09:00
parent 17111afcd6
commit bda7eaa63a
1 changed files with 14 additions and 5 deletions

View File

@ -20,7 +20,9 @@ import android.content.Context;
import android.text.TextUtils; import android.text.TextUtils;
import com.android.inputmethod.keyboard.ProximityInfo; import com.android.inputmethod.keyboard.ProximityInfo;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Locale; import java.util.Locale;
@ -125,6 +127,7 @@ public class BinaryDictionary extends Dictionary {
count = MAX_BIGRAMS; count = MAX_BIGRAMS;
} }
final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<SuggestedWordInfo>();
for (int j = 0; j < count; ++j) { for (int j = 0; j < count; ++j) {
if (codesSize > 0 && mBigramScores[j] < 1) break; if (codesSize > 0 && mBigramScores[j] < 1) break;
final int start = j * MAX_WORD_LENGTH; final int start = j * MAX_WORD_LENGTH;
@ -133,19 +136,22 @@ public class BinaryDictionary extends Dictionary {
++len; ++len;
} }
if (len > 0) { if (len > 0) {
callback.addWord(mOutputChars_bigrams, null, start, len, mBigramScores[j], suggestions.add(new SuggestedWordInfo(
mDicTypeId, Dictionary.BIGRAM); new String(mOutputChars_bigrams, start, len),
mBigramScores[j], SuggestedWordInfo.KIND_CORRECTION));
} }
} }
Utils.addAllSuggestions(mDicTypeId, Dictionary.BIGRAM, suggestions, callback);
} }
// proximityInfo and/or prevWordForBigrams may not be null. // proximityInfo and/or prevWordForBigrams may not be null.
@Override @Override
public void getWords(final WordComposer codes, final CharSequence prevWordForBigrams, public void getWords(final WordComposer codes, final CharSequence prevWordForBigrams,
final WordCallback callback, final ProximityInfo proximityInfo) { final WordCallback callback, final ProximityInfo proximityInfo) {
final int count = getSuggestions(codes, prevWordForBigrams, proximityInfo, mOutputChars, final int count = getSuggestions(codes, prevWordForBigrams, proximityInfo, mOutputChars,
mScores, mSpaceIndices); mScores, mSpaceIndices);
final ArrayList<SuggestedWordInfo> suggestions = new ArrayList<SuggestedWordInfo>();
for (int j = 0; j < count; ++j) { for (int j = 0; j < count; ++j) {
if (mScores[j] < 1) break; if (mScores[j] < 1) break;
final int start = j * MAX_WORD_LENGTH; final int start = j * MAX_WORD_LENGTH;
@ -154,10 +160,13 @@ public class BinaryDictionary extends Dictionary {
++len; ++len;
} }
if (len > 0) { if (len > 0) {
callback.addWord(mOutputChars, null, start, len, mScores[j], mDicTypeId, // TODO: actually get the kind from native code
Dictionary.UNIGRAM); suggestions.add(new SuggestedWordInfo(
new String(mOutputChars, start, len),
mScores[j], SuggestedWordInfo.KIND_CORRECTION));
} }
} }
Utils.addAllSuggestions(mDicTypeId, Dictionary.UNIGRAM, suggestions, callback);
} }
/* package for test */ boolean isValidDictionary() { /* package for test */ boolean isValidDictionary() {