From e110018e2a7cc5809aaadb4c0e9cfef70760543f Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Wed, 26 Feb 2014 16:32:40 +0900 Subject: [PATCH] [IL114] Move a method to InputLogic Bug: 8636060 Change-Id: I0d8f93985ddc6e93ce9af0d92a8056620351a498 --- .../android/inputmethod/latin/LatinIME.java | 22 ------------ .../latin/inputlogic/InputLogic.java | 34 +++++++++++++++++-- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 3c5c8bf70..0b0769423 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1443,28 +1443,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen sequenceNumber, callback); } - // TODO[IL]: Move this to InputLogic - public SuggestedWords maybeRetrieveOlderSuggestions(final String typedWord, - final SuggestedWords suggestedWords, final SuggestedWords previousSuggestedWords) { - // TODO: consolidate this into getSuggestedWords - // 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 = - previousSuggestedWords.isPunctuationSuggestions() ? SuggestedWords.EMPTY - : previousSuggestedWords; - final ArrayList typedWordAndPreviousSuggestions = - SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord, oldSuggestedWords); - return new SuggestedWords(typedWordAndPreviousSuggestions, null /* rawSuggestions */, - false /* typedWordValid */, false /* hasAutoCorrectionCandidate */, - true /* isObsoleteSuggestions */, false /* isPrediction */); - } - } - @Override public void showSuggestionStrip(final SuggestedWords sourceSuggestedWords) { final SuggestedWords suggestedWords = diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index 8b83155ea..7be60fd31 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -1229,9 +1229,8 @@ public final class InputLogic { @Override public void onGetSuggestedWords(final SuggestedWords suggestedWords) { final SuggestedWords suggestedWordsWithMaybeOlderSuggestions = - mLatinIME.maybeRetrieveOlderSuggestions( - mWordComposer.getTypedWord(), suggestedWords, - mSuggestedWords); + maybeRetrieveOlderSuggestions(mWordComposer.getTypedWord(), + suggestedWords, mSuggestedWords); holder.set(suggestedWordsWithMaybeOlderSuggestions); } } @@ -1656,6 +1655,35 @@ public final class InputLogic { } } + /** + * Given a typed word and computed suggested words, return an object that may or may not + * contain older suggestions according to the contents of the current suggestions. + * @param typedWord The typed word as a string. + * @param suggestedWords The computed suggested words for this typed word. + * @param previousSuggestedWords The previous suggested words. + * @return suggestions possibly enriched with older suggestions. + */ + private SuggestedWords maybeRetrieveOlderSuggestions(final String typedWord, + final SuggestedWords suggestedWords, 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 = + previousSuggestedWords.isPunctuationSuggestions() ? SuggestedWords.EMPTY + : previousSuggestedWords; + final ArrayList typedWordAndPreviousSuggestions = + SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord, oldSuggestedWords); + return new SuggestedWords(typedWordAndPreviousSuggestions, null /* rawSuggestions */, + false /* typedWordValid */, false /* hasAutoCorrectionCandidate */, + true /* isObsoleteSuggestions */, false /* isPrediction */); + } + } + /** * Gets a chunk of text with or the auto-correction indicator underline span as appropriate. *