am bf0f4d9c: Remove dupes from suggestions. Fixes 2213629
Merge commit 'bf0f4d9c8b789035255d6b89752c77801929002e' into eclair-mr2 * commit 'bf0f4d9c8b789035255d6b89752c77801929002e': Remove dupes from suggestions. Fixes 2213629main
commit
709d1c61da
|
@ -48,9 +48,9 @@ public class Suggest implements Dictionary.WordCallback {
|
||||||
private int mPrefMaxSuggestions = 12;
|
private int mPrefMaxSuggestions = 12;
|
||||||
|
|
||||||
private int[] mPriorities = new int[mPrefMaxSuggestions];
|
private int[] mPriorities = new int[mPrefMaxSuggestions];
|
||||||
private List<CharSequence> mSuggestions = new ArrayList<CharSequence>();
|
private ArrayList<CharSequence> mSuggestions = new ArrayList<CharSequence>();
|
||||||
private boolean mIncludeTypedWordIfValid;
|
private boolean mIncludeTypedWordIfValid;
|
||||||
private List<CharSequence> mStringPool = new ArrayList<CharSequence>();
|
private ArrayList<CharSequence> mStringPool = new ArrayList<CharSequence>();
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private boolean mHaveCorrection;
|
private boolean mHaveCorrection;
|
||||||
private CharSequence mOriginalWord;
|
private CharSequence mOriginalWord;
|
||||||
|
@ -219,9 +219,37 @@ public class Suggest implements Dictionary.WordCallback {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removeDupes();
|
||||||
return mSuggestions;
|
return mSuggestions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void removeDupes() {
|
||||||
|
final ArrayList<CharSequence> suggestions = mSuggestions;
|
||||||
|
if (suggestions.size() < 2) return;
|
||||||
|
int i = 1;
|
||||||
|
// Don't cache suggestions.size(), since we may be removing items
|
||||||
|
while (i < suggestions.size()) {
|
||||||
|
final CharSequence cur = suggestions.get(i);
|
||||||
|
// Compare each candidate with each previous candidate
|
||||||
|
for (int j = 0; j < i; j++) {
|
||||||
|
CharSequence previous = suggestions.get(j);
|
||||||
|
if (TextUtils.equals(cur, previous)) {
|
||||||
|
removeFromSuggestions(i);
|
||||||
|
i--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeFromSuggestions(int index) {
|
||||||
|
CharSequence garbage = mSuggestions.remove(index);
|
||||||
|
if (garbage != null && garbage instanceof StringBuilder) {
|
||||||
|
mStringPool.add(garbage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasMinimalCorrection() {
|
public boolean hasMinimalCorrection() {
|
||||||
return mHaveCorrection;
|
return mHaveCorrection;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue