From 4ee186920e642ae8ebe0b6c97dfdceb0ad2fdeef Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 13 Mar 2012 18:21:35 +0900 Subject: [PATCH] Remove a method that causes annoying side-effects. ...and replace by a call to a central method. Change-Id: I93d0a2c2e99963a5b69923d1062d0e01853216b6 --- .../android/inputmethod/latin/LatinIME.java | 9 ++++++++- .../inputmethod/latin/SuggestedWords.java | 20 ++++++------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index dc5bd2efc..39cbfa7a0 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -72,6 +72,7 @@ import com.android.inputmethod.latin.suggestions.SuggestionsView; import java.io.FileDescriptor; import java.io.PrintWriter; +import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -1782,8 +1783,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (previousSuggestions == mSettingsValues.mSuggestPuncList) { previousSuggestions = SuggestedWords.EMPTY; } + final ArrayList typedWordAndPreviousSuggestions = + SuggestedWords.Builder.getTypedWordAndPreviousSuggestions( + typedWord, previousSuggestions); final SuggestedWords.Builder obsoleteSuggestionsBuilder = new SuggestedWords.Builder() - .addTypedWordAndPreviousSuggestions(typedWord, previousSuggestions); + .addWords(typedWordAndPreviousSuggestions) + .setTypedWordValid(false) + .setHasMinimalSuggestion(false); + showSuggestions(obsoleteSuggestionsBuilder.build(), typedWord); } } diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index 7dd85f65b..31f50e4f5 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -87,12 +87,6 @@ public class SuggestedWords { // Nothing to do here. } - // TODO: the following method is a wrapper to satisfy tests. Update tests and remove it. - public Builder addWords(final List words, - final List suggestedWordInfoList) { - return addWords(suggestedWordInfoList); - } - public Builder addWords(List suggestedWordInfoList) { final int N = suggestedWordInfoList.size(); for (int i = 0; i < N; ++i) { @@ -161,24 +155,22 @@ public class SuggestedWords { // Should get rid of the first one (what the user typed previously) from suggestions // and replace it with what the user currently typed. - public Builder addTypedWordAndPreviousSuggestions(CharSequence typedWord, - SuggestedWords previousSuggestions) { - mSuggestedWordInfoList.clear(); + public static ArrayList getTypedWordAndPreviousSuggestions( + final CharSequence typedWord, final SuggestedWords previousSuggestions) { + final ArrayList suggestionsList = new ArrayList(); final HashSet alreadySeen = new HashSet(); - addWord(typedWord, new SuggestedWordInfo(typedWord, null, false)); + suggestionsList.add(new SuggestedWordInfo(typedWord, null, false)); alreadySeen.add(typedWord.toString()); final int previousSize = previousSuggestions.size(); for (int pos = 1; pos < previousSize; pos++) { final String prevWord = previousSuggestions.getWord(pos).toString(); // Filter out duplicate suggestion. if (!alreadySeen.contains(prevWord)) { - addWord(prevWord, new SuggestedWordInfo(prevWord, null, true)); + suggestionsList.add(new SuggestedWordInfo(prevWord, null, true)); alreadySeen.add(prevWord); } } - mTypedWordValid = false; - mHasMinimalSuggestion = false; - return this; + return suggestionsList; } public SuggestedWords build() {