am 1940f26e: Merge "[IL115] Cleanup continues"

* commit '1940f26edbdb99f04a5a1edbb20316b674209489':
  [IL115] Cleanup continues
main
Jean Chalard 2014-03-03 23:48:47 -08:00 committed by Android Git Automerger
commit 4a3816383d
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,23 +1661,16 @@ 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?
// We update the suggestion strip only when we have some suggestions to show, i.e. when
// the suggestion count is > 1; else, we leave the old suggestions, with the typed word
// replaced with the new one. However, when the length of the typed word is 1 or 0 (after
// a deletion typically), we do want to remove the old suggestions.
if (suggestedWords.size() > 1 || typedWord.length() <= 1) {
return suggestedWords;
} else {
final SuggestedWords oldSuggestedWords = final SuggestedWords oldSuggestedWords =
previousSuggestedWords.isPunctuationSuggestions() ? SuggestedWords.EMPTY previousSuggestedWords.isPunctuationSuggestions() ? SuggestedWords.EMPTY
: previousSuggestedWords; : previousSuggestedWords;
@ -1682,7 +1680,6 @@ public final class InputLogic {
false /* typedWordValid */, false /* hasAutoCorrectionCandidate */, false /* typedWordValid */, false /* hasAutoCorrectionCandidate */,
true /* isObsoleteSuggestions */, false /* isPrediction */); true /* isObsoleteSuggestions */, false /* isPrediction */);
} }
}
/** /**
* Gets a chunk of text with or the auto-correction indicator underline span as appropriate. * Gets a chunk of text with or the auto-correction indicator underline span as appropriate.