Merge "[IL115] Cleanup continues"

main
Jean Chalard 2014-03-04 07:46:10 +00:00 committed by Android (Google) Code Review
commit 1940f26edb
1 changed files with 25 additions and 28 deletions

View File

@ -1228,10 +1228,15 @@ public final class InputLogic {
SuggestedWords.NOT_A_SEQUENCE_NUMBER, new OnGetSuggestedWordsCallback() { SuggestedWords.NOT_A_SEQUENCE_NUMBER, new OnGetSuggestedWordsCallback() {
@Override @Override
public void onGetSuggestedWords(final SuggestedWords suggestedWords) { public void onGetSuggestedWords(final SuggestedWords suggestedWords) {
final SuggestedWords suggestedWordsWithMaybeOlderSuggestions = final String typedWord = mWordComposer.getTypedWord();
maybeRetrieveOlderSuggestions(mWordComposer.getTypedWord(), // Show new suggestions if we have at least one. Otherwise keep the old
suggestedWords, mSuggestedWords); // suggestions with the new typed word. Exception: if the length of the
holder.set(suggestedWordsWithMaybeOlderSuggestions); // typed word is <= 1 (after a deletion typically) we clear old suggestions.
if (suggestedWords.size() > 1 || typedWord.length() <= 1) {
holder.set(suggestedWords);
} else {
holder.set(retrieveOlderSuggestions(typedWord, mSuggestedWords));
}
} }
} }
); );
@ -1656,32 +1661,24 @@ public final class InputLogic {
} }
/** /**
* Given a typed word and computed suggested words, return an object that may or may not * Make a {@link com.android.inputmethod.latin.SuggestedWords} object containing a typed word
* contain older suggestions according to the contents of the current suggestions. * and obsolete suggestions.
* See {@link com.android.inputmethod.latin.SuggestedWords#getTypedWordAndPreviousSuggestions(
* String, com.android.inputmethod.latin.SuggestedWords)}.
* @param typedWord The typed word as a string. * @param typedWord The typed word as a string.
* @param suggestedWords The computed suggested words for this typed word. * @param previousSuggestedWords The previously suggested words.
* @param previousSuggestedWords The previous suggested words. * @return Obsolete suggestions with the newly typed word.
* @return suggestions possibly enriched with older suggestions.
*/ */
private SuggestedWords maybeRetrieveOlderSuggestions(final String typedWord, private SuggestedWords retrieveOlderSuggestions(final String typedWord,
final SuggestedWords suggestedWords, final SuggestedWords previousSuggestedWords) { final SuggestedWords previousSuggestedWords) {
// TODO: consolidate this into performUpdateSuggestionStripSync? final SuggestedWords oldSuggestedWords =
// We update the suggestion strip only when we have some suggestions to show, i.e. when previousSuggestedWords.isPunctuationSuggestions() ? SuggestedWords.EMPTY
// the suggestion count is > 1; else, we leave the old suggestions, with the typed word : previousSuggestedWords;
// replaced with the new one. However, when the length of the typed word is 1 or 0 (after final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions =
// a deletion typically), we do want to remove the old suggestions. SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord, oldSuggestedWords);
if (suggestedWords.size() > 1 || typedWord.length() <= 1) { return new SuggestedWords(typedWordAndPreviousSuggestions, null /* rawSuggestions */,
return suggestedWords; false /* typedWordValid */, false /* hasAutoCorrectionCandidate */,
} else { true /* isObsoleteSuggestions */, false /* isPrediction */);
final SuggestedWords oldSuggestedWords =
previousSuggestedWords.isPunctuationSuggestions() ? SuggestedWords.EMPTY
: previousSuggestedWords;
final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions =
SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord, oldSuggestedWords);
return new SuggestedWords(typedWordAndPreviousSuggestions, null /* rawSuggestions */,
false /* typedWordValid */, false /* hasAutoCorrectionCandidate */,
true /* isObsoleteSuggestions */, false /* isPrediction */);
}
} }
/** /**