diff options
author | 2009-10-27 18:08:19 -0700 | |
---|---|---|
committer | 2009-10-28 10:53:29 -0700 | |
commit | bf0f4d9c8b789035255d6b89752c77801929002e (patch) | |
tree | 6d04732fecc82a5c6d3433cd538280daafe08bad /src | |
parent | b04157a83614f386d2a43b1839f8d22c80151ea7 (diff) | |
download | latinime-bf0f4d9c8b789035255d6b89752c77801929002e.tar.gz latinime-bf0f4d9c8b789035255d6b89752c77801929002e.tar.xz latinime-bf0f4d9c8b789035255d6b89752c77801929002e.zip |
Remove dupes from suggestions. Fixes 2213629
Dupes are sometimes generated, especially for names, from Contacts
and main dictionary. Check for dupes before showing suggestions.
Diffstat (limited to 'src')
-rwxr-xr-x | src/com/android/inputmethod/latin/Suggest.java | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/com/android/inputmethod/latin/Suggest.java b/src/com/android/inputmethod/latin/Suggest.java index bb6a153dc..c025566b7 100755 --- a/src/com/android/inputmethod/latin/Suggest.java +++ b/src/com/android/inputmethod/latin/Suggest.java @@ -48,9 +48,9 @@ public class Suggest implements Dictionary.WordCallback { private int mPrefMaxSuggestions = 12; private int[] mPriorities = new int[mPrefMaxSuggestions]; - private List<CharSequence> mSuggestions = new ArrayList<CharSequence>(); + private ArrayList<CharSequence> mSuggestions = new ArrayList<CharSequence>(); private boolean mIncludeTypedWordIfValid; - private List<CharSequence> mStringPool = new ArrayList<CharSequence>(); + private ArrayList<CharSequence> mStringPool = new ArrayList<CharSequence>(); private Context mContext; private boolean mHaveCorrection; private CharSequence mOriginalWord; @@ -218,10 +218,38 @@ public class Suggest implements Dictionary.WordCallback { } i++; } - + + removeDupes(); 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() { return mHaveCorrection; } |