From 28eeb35d149468514a65379e9d0d1672cf26981e Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Tue, 26 Jun 2012 15:17:51 +0900 Subject: [PATCH] Merge the interface of two methods that do the same thing (A9) Change-Id: Ia5701d713d0fd5bb646b54a03a1a5602dad0a9e6 --- .../android/inputmethod/latin/LatinIME.java | 6 ++-- .../android/inputmethod/latin/Suggest.java | 31 +++++++++++++------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 8a5fc495e..25b8fd566 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1710,7 +1710,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // getSuggestedWords handles gracefully a null value of prevWord final SuggestedWords suggestedWords = mSuggest.getSuggestedWords(mWordComposer, prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), - mCurrentSettings.mCorrectionEnabled); + mCurrentSettings.mCorrectionEnabled, false); // 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 @@ -1922,7 +1922,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (mCurrentSettings.mCorrectionEnabled) { final CharSequence prevWord = mConnection.getThisWord(mCurrentSettings.mWordSeparators); if (!TextUtils.isEmpty(prevWord)) { - suggestedWords = mSuggest.getBigramPredictions(prevWord); + suggestedWords = mSuggest.getSuggestedWords(mWordComposer, + prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), + mCurrentSettings.mCorrectionEnabled, true); } else { suggestedWords = null; } diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 2f22df34b..61a8e2831 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -234,13 +234,22 @@ public class Suggest implements Dictionary.WordCallback { true /* isPrediction */); } - // TODO: cleanup dictionaries looking up and suggestions building with SuggestedWords.Builder + // Compatibility for tests. TODO: remove this public SuggestedWords getSuggestedWords( final WordComposer wordComposer, CharSequence prevWordForBigram, final ProximityInfo proximityInfo, final boolean isCorrectionEnabled) { + return getSuggestedWords(wordComposer, prevWordForBigram, proximityInfo, + isCorrectionEnabled, false); + } + + // TODO: cleanup dictionaries looking up and suggestions building with SuggestedWords.Builder + public SuggestedWords getSuggestedWords( + final WordComposer wordComposer, CharSequence prevWordForBigram, + final ProximityInfo proximityInfo, final boolean isCorrectionEnabled, + final boolean isPrediction) { LatinImeLogger.onStartSuggestion(prevWordForBigram); - mIsFirstCharCapitalized = wordComposer.isFirstCharCapitalized(); - mIsAllUpperCase = wordComposer.isAllUpperCase(); + mIsFirstCharCapitalized = !isPrediction && wordComposer.isFirstCharCapitalized(); + mIsAllUpperCase = !isPrediction && wordComposer.isAllUpperCase(); mTrailingSingleQuotesCount = wordComposer.trailingSingleQuotesCount(); mSuggestions = new ArrayList(MAX_SUGGESTIONS); @@ -305,12 +314,14 @@ public class Suggest implements Dictionary.WordCallback { } } - mSuggestions.add(0, new SuggestedWordInfo(typedWord, SuggestedWordInfo.MAX_SCORE, - SuggestedWordInfo.KIND_TYPED)); + if (!isPrediction) { + mSuggestions.add(0, new SuggestedWordInfo(typedWord, SuggestedWordInfo.MAX_SCORE, + SuggestedWordInfo.KIND_TYPED)); + } SuggestedWordInfo.removeDups(mSuggestions); final ArrayList suggestionsList; - if (DBG) { + if (DBG && !mSuggestions.isEmpty()) { suggestionsList = getSuggestionsInfoListWithDebugInfo(typedWord, mSuggestions); } else { suggestionsList = mSuggestions; @@ -343,12 +354,12 @@ public class Suggest implements Dictionary.WordCallback { autoCorrectionAvailable = false; } return new SuggestedWords(suggestionsList, - !allowsToBeAutoCorrected /* typedWordValid */, - autoCorrectionAvailable /* hasAutoCorrectionCandidate */, - allowsToBeAutoCorrected /* allowsToBeAutoCorrected */, + !isPrediction && !allowsToBeAutoCorrected /* typedWordValid */, + !isPrediction && autoCorrectionAvailable /* hasAutoCorrectionCandidate */, + !isPrediction && allowsToBeAutoCorrected /* allowsToBeAutoCorrected */, false /* isPunctuationSuggestions */, false /* isObsoleteSuggestions */, - false /* isPrediction */); + isPrediction); } /**