diff options
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIME.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinIME.java | 91 |
1 files changed, 43 insertions, 48 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 99b6c739a..46b735ab2 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -77,7 +77,6 @@ import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; -import java.util.List; import java.util.Locale; /** @@ -162,7 +161,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // Keep track of the last selection range to decide if we need to show word alternatives private int mLastSelectionStart; private int mLastSelectionEnd; - private List<CharSequence> mSuggestPuncList; + private SuggestedWords mSuggestPuncList; // Input type is such that we should not auto-correct private boolean mInputTypeNoAutoCorrect; @@ -212,7 +211,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen return mChosenWord; } - public abstract List<CharSequence> getAlternatives(); + public abstract SuggestedWords.Builder getAlternatives(); } public class TypedWordAlternatives extends WordAlternatives { @@ -233,7 +232,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } @Override - public List<CharSequence> getAlternatives() { + public SuggestedWords.Builder getAlternatives() { return getTypedSuggestions(word); } } @@ -655,7 +654,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen super.onFinishInput(); LatinImeLogger.commit(); - onAutoCompletionStateChanged(false); + mKeyboardSwitcher.onAutoCompletionStateChanged(false); mVoiceConnector.flushVoiceInputLogs(mConfigurationChanging); @@ -790,7 +789,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen @Override public void hideWindow() { LatinImeLogger.commit(); - onAutoCompletionStateChanged(false); + mKeyboardSwitcher.onAutoCompletionStateChanged(false); if (TRACE) Debug.stopMethodTracing(); if (mOptionsDialog != null && mOptionsDialog.isShowing()) { @@ -818,13 +817,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen return; } - List<CharSequence> stringList = new ArrayList<CharSequence>(); - for (int i = 0; i < completions.length; i++) { - CompletionInfo ci = completions[i]; - if (ci != null) stringList.add(ci.getText()); - } + SuggestedWords.Builder builder = new SuggestedWords.Builder() + .setApplicationSpecifiedCompletions(completions) + .setTypedWordValid(true) + .setHasMinimalSuggestion(true); // When in fullscreen mode, show completions generated by the application - setSuggestions(stringList, true, true, true); + setSuggestions(builder.build()); mBestWord = null; setCandidatesViewShown(true); } @@ -1382,7 +1380,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } private boolean isShowingPunctuationList() { - return mSuggestPuncList.equals(mCandidateView.getSuggestions()); + return mSuggestPuncList == mCandidateView.getSuggestions(); } private boolean isSuggestionShown() { @@ -1422,22 +1420,18 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } public void clearSuggestions() { - setSuggestions(null, false, false, false); + setSuggestions(SuggestedWords.EMPTY); } - public void setSuggestions( - List<CharSequence> suggestions, - boolean completions, - boolean typedWordValid, - boolean haveMinimalSuggestion) { - + public void setSuggestions(SuggestedWords words) { if (mVoiceConnector.getAndResetIsShowingHint()) { setCandidatesView(mCandidateViewContainer); } if (mCandidateView != null) { - mCandidateView.setSuggestions( - suggestions, completions, typedWordValid, haveMinimalSuggestion); + mCandidateView.setSuggestions(words); + if (mCandidateView.isConfigCandidateHighlightFontColorEnabled()) + mKeyboardSwitcher.onAutoCompletionStateChanged(words.hasAutoCorrectionWord()); } } @@ -1457,16 +1451,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen showSuggestions(mWord); } - private List<CharSequence> getTypedSuggestions(WordComposer word) { - List<CharSequence> stringList = mSuggest.getSuggestions( + private SuggestedWords.Builder getTypedSuggestions(WordComposer word) { + return mSuggest.getSuggestedWordBuilder( mKeyboardSwitcher.getInputView(), word, false, null); - return stringList; } private void showCorrections(WordAlternatives alternatives) { mKeyboardSwitcher.setPreferredLetters(null); - List<CharSequence> stringList = alternatives.getAlternatives(); - showSuggestions(stringList, alternatives.getOriginalWord(), false, false); + SuggestedWords.Builder builder = alternatives.getAlternatives(); + builder.setTypedWordValid(false).setHasMinimalSuggestion(false); + showSuggestions(builder.build(), alternatives.getOriginalWord()); } private void showSuggestions(WordComposer word) { @@ -1474,7 +1468,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // TODO Maybe need better way of retrieving previous word CharSequence prevWord = EditingUtils.getPreviousWord(getCurrentInputConnection(), mWordSeparators); - List<CharSequence> stringList = mSuggest.getSuggestions( + SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder( mKeyboardSwitcher.getInputView(), word, false, prevWord); // long stopTime = System.currentTimeMillis(); // TIME MEASUREMENT! // Log.d("LatinIME","Suggest Total Time - " + (stopTime - startTime)); @@ -1497,15 +1491,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen correctionAvailable &= !word.isMostlyCaps(); correctionAvailable &= !TextEntryState.isCorrecting(); - showSuggestions(stringList, typedWord, typedWordValid, correctionAvailable); + builder.setTypedWordValid(typedWordValid).setHasMinimalSuggestion(correctionAvailable); + showSuggestions(builder.build(), typedWord); } - private void showSuggestions(List<CharSequence> stringList, CharSequence typedWord, - boolean typedWordValid, boolean correctionAvailable) { - setSuggestions(stringList, false, typedWordValid, correctionAvailable); - if (stringList.size() > 0) { - if (correctionAvailable && !typedWordValid && stringList.size() > 1) { - mBestWord = stringList.get(1); + private void showSuggestions(SuggestedWords suggestedWords, CharSequence typedWord) { + setSuggestions(suggestedWords); + if (suggestedWords.size() > 0) { + if (suggestedWords.mHasMinimalSuggestion + && !suggestedWords.mTypedWordValid && suggestedWords.size() > 1) { + mBestWord = suggestedWords.getWord(1); } else { mBestWord = typedWord; } @@ -1534,7 +1529,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } public void pickSuggestionManually(int index, CharSequence suggestion) { - List<CharSequence> suggestions = mCandidateView.getSuggestions(); + SuggestedWords suggestions = mCandidateView.getSuggestions(); mVoiceConnector.flushAndLogAllTextModificationCounters(index, suggestion, mWordSeparators); final boolean correcting = TextEntryState.isCorrecting(); @@ -1565,7 +1560,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // Word separators are suggested before the user inputs something. // So, LatinImeLogger logs "" as a user's input. LatinImeLogger.logOnManualSuggestion( - "", suggestion.toString(), index, suggestions); + "", suggestion.toString(), index, suggestions.mWords); final char primaryCode = suggestion.charAt(0); onKey(primaryCode, new int[]{primaryCode}, KeyboardView.NOT_A_TOUCH_COORDINATE, KeyboardView.NOT_A_TOUCH_COORDINATE); @@ -1583,7 +1578,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen addToBigramDictionary(suggestion, 1); } LatinImeLogger.logOnManualSuggestion(mComposing.toString(), suggestion.toString(), - index, suggestions); + index, suggestions.mWords); TextEntryState.acceptedSuggestion(mComposing.toString(), suggestion); // Follow it with a space if (mAutoSpace && !correcting) { @@ -1718,7 +1713,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private void setPunctuationSuggestions() { setCandidatesViewShown(isCandidateStripVisible()); - setSuggestions(mSuggestPuncList, false, false, false); + setSuggestions(mSuggestPuncList); } private void addToDictionaries(CharSequence suggestion, int frequencyDelta) { @@ -2106,13 +2101,17 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } private void initSuggestPuncList() { - mSuggestPuncList = new ArrayList<CharSequence>(); - mSuggestPuncs = mResources.getString(R.string.suggested_punctuations); - if (mSuggestPuncs != null) { - for (int i = 0; i < mSuggestPuncs.length(); i++) { - mSuggestPuncList.add(mSuggestPuncs.subSequence(i, i + 1)); + if (mSuggestPuncs != null || mSuggestPuncList != null) + return; + SuggestedWords.Builder builder = new SuggestedWords.Builder(); + String puncs = mResources.getString(R.string.suggested_punctuations); + if (puncs != null) { + for (int i = 0; i < puncs.length(); i++) { + builder.addWord(puncs.subSequence(i, i + 1)); } } + mSuggestPuncList = builder.build(); + mSuggestPuncs = puncs; } private boolean isSuggestedPunctuation(int code) { @@ -2192,10 +2191,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen System.out.println("CPS = " + ((CPS_BUFFER_SIZE * 1000f) / total)); } - public void onAutoCompletionStateChanged(boolean isAutoCompletion) { - mKeyboardSwitcher.onAutoCompletionStateChanged(isAutoCompletion); - } - @Override public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype) { SubtypeSwitcher.getInstance().updateSubtype(subtype); |