Update suggestions if user typed word is found in dictionary

This change aslo eliminates duplicate suggestion from past
suggestions.  And call setTypedWordVaild to past suggestions.

Bug: 3367722

Change-Id: I7ffaa2f7e4e30b3951b6c2df002d269671c9d654
main
Tadashi G. Takaoka 2011-01-21 15:03:09 +09:00
parent dbc6177985
commit f3df63a93a
2 changed files with 16 additions and 6 deletions

View File

@ -1535,10 +1535,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Basically, we update the suggestion strip only when suggestion count > 1. However, // Basically, we update the suggestion strip only when suggestion count > 1. However,
// there is an exception: We update the suggestion strip whenever typed word's length // there is an exception: We update the suggestion strip whenever typed word's length
// is 1, regardless of suggestion count. Actually, in most cases, suggestion count is 1 // is 1 or typed word is found in dictionary, regardless of suggestion count. Actually,
// when typed word's length is 1, but we do always need to clear the previous state when // in most cases, suggestion count is 1 when typed word's length is 1, but we do always
// the user starts typing a word (i.e. typed word's length == 1). // need to clear the previous state when the user starts typing a word (i.e. typed word's
if (typedWord.length() == 1 || builder.size() > 1 // length == 1).
if (builder.size() > 1 || typedWord.length() == 1 || typedWordValid
|| mCandidateView.isShowingAddToDictionaryHint()) { || mCandidateView.isShowingAddToDictionaryHint()) {
builder.setTypedWordValid(typedWordValid).setHasMinimalSuggestion(correctionAvailable); builder.setTypedWordValid(typedWordValid).setHasMinimalSuggestion(correctionAvailable);
} else { } else {

View File

@ -20,6 +20,7 @@ import android.view.inputmethod.CompletionInfo;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet;
import java.util.List; import java.util.List;
public class SuggestedWords { public class SuggestedWords {
@ -128,10 +129,18 @@ public class SuggestedWords {
SuggestedWords previousSuggestions) { SuggestedWords previousSuggestions) {
mWords.clear(); mWords.clear();
mSuggestedWordInfoList.clear(); mSuggestedWordInfoList.clear();
final HashSet<String> alreadySeen = new HashSet<String>();
addWord(typedWord, null, false); addWord(typedWord, null, false);
alreadySeen.add(typedWord.toString());
final int previousSize = previousSuggestions.size(); final int previousSize = previousSuggestions.size();
for (int pos = 1; pos < previousSize; pos++) for (int pos = 1; pos < previousSize; pos++) {
addWord(previousSuggestions.getWord(pos), null, true); final String prevWord = previousSuggestions.getWord(pos).toString();
// Filter out duplicate suggestion.
if (!alreadySeen.contains(prevWord)) {
addWord(prevWord, null, true);
alreadySeen.add(prevWord);
}
}
mIsCompletions = false; mIsCompletions = false;
mTypedWordValid = false; mTypedWordValid = false;
mHasMinimalSuggestion = false; mHasMinimalSuggestion = false;