diff options
Diffstat (limited to 'java/src')
3 files changed, 107 insertions, 123 deletions
diff --git a/java/src/com/android/inputmethod/latin/InputAttributes.java b/java/src/com/android/inputmethod/latin/InputAttributes.java index 28ce916c9..78b2de342 100644 --- a/java/src/com/android/inputmethod/latin/InputAttributes.java +++ b/java/src/com/android/inputmethod/latin/InputAttributes.java @@ -16,20 +16,97 @@ package com.android.inputmethod.latin; +import android.text.InputType; +import android.util.Log; import android.view.inputmethod.EditorInfo; +import com.android.inputmethod.compat.InputTypeCompatUtils; + /** * Class to hold attributes of the input field. */ public class InputAttributes { private final String TAG = InputAttributes.class.getSimpleName(); - // TODO: make these final - public boolean mInsertSpaceOnPickSuggestionManually; - public boolean mInputTypeNoAutoCorrect; - public boolean mIsSettingsSuggestionStripOn; - public boolean mApplicationSpecifiedCompletionOn; + final public boolean mInsertSpaceOnPickSuggestionManually; + final public boolean mInputTypeNoAutoCorrect; + final public boolean mIsSettingsSuggestionStripOn; + final public boolean mApplicationSpecifiedCompletionOn; + + public InputAttributes(final EditorInfo editorInfo, final boolean isFullscreenMode) { + if (editorInfo == null || editorInfo.inputType == InputType.TYPE_CLASS_TEXT) { + mInsertSpaceOnPickSuggestionManually = false; + mIsSettingsSuggestionStripOn = false; + mInputTypeNoAutoCorrect = false; + mApplicationSpecifiedCompletionOn = false; + } else { + final int inputType = editorInfo.inputType; + if (inputType == InputType.TYPE_NULL) { + // TODO: We should honor TYPE_NULL specification. + Log.i(TAG, "InputType.TYPE_NULL is specified"); + } + final int inputClass = inputType & InputType.TYPE_MASK_CLASS; + final int variation = inputType & InputType.TYPE_MASK_VARIATION; + if (inputClass == 0) { + // TODO: is this check still necessary? + Log.w(TAG, String.format("Unexpected input class: inputType=0x%08x" + + " imeOptions=0x%08x", + inputType, editorInfo.imeOptions)); + } + final boolean flagNoSuggestions = + 0 != (inputType & InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); + final boolean flagMultiLine = + 0 != (inputType & InputType.TYPE_TEXT_FLAG_MULTI_LINE); + final boolean flagAutoCorrect = + 0 != (inputType & InputType.TYPE_TEXT_FLAG_AUTO_CORRECT); + final boolean flagAutoComplete = + 0 != (inputType & InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE); + + // Make sure that passwords are not displayed in {@link SuggestionsView}. + if (InputTypeCompatUtils.isPasswordInputType(inputType) + || InputTypeCompatUtils.isVisiblePasswordInputType(inputType) + || InputTypeCompatUtils.isEmailVariation(variation) + || InputType.TYPE_TEXT_VARIATION_URI == variation + || InputType.TYPE_TEXT_VARIATION_FILTER == variation + || flagNoSuggestions + || flagAutoComplete) { + mIsSettingsSuggestionStripOn = false; + } else { + mIsSettingsSuggestionStripOn = true; + } + + if (InputTypeCompatUtils.isEmailVariation(variation) + || variation == InputType.TYPE_TEXT_VARIATION_PERSON_NAME) { + // The point in turning this off is that we don't want to insert a space after + // a name when filling a form: we can't delete trailing spaces when changing fields + mInsertSpaceOnPickSuggestionManually = false; + } else { + mInsertSpaceOnPickSuggestionManually = true; + } + + // If it's a browser edit field and auto correct is not ON explicitly, then + // disable auto correction, but keep suggestions on. + // If NO_SUGGESTIONS is set, don't do prediction. + // If it's not multiline and the autoCorrect flag is not set, then don't correct + if ((variation == InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT + && !flagAutoCorrect) + || flagNoSuggestions + || (!flagAutoCorrect && !flagMultiLine)) { + mInputTypeNoAutoCorrect = true; + } else { + mInputTypeNoAutoCorrect = false; + } + + mApplicationSpecifiedCompletionOn = flagAutoComplete && isFullscreenMode; + } + } - public InputAttributes(final EditorInfo editorInfo) { + // Pretty print + @Override + public String toString() { + return "\n mInsertSpaceOnPickSuggestionManually = " + mInsertSpaceOnPickSuggestionManually + + "\n mInputTypeNoAutoCorrect = " + mInputTypeNoAutoCorrect + + "\n mIsSettingsSuggestionStripOn = " + mIsSettingsSuggestionStripOn + + "\n mApplicationSpecifiedCompletionOn = " + mApplicationSpecifiedCompletionOn; } } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 238ebc958..f24dc3fe3 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -176,6 +176,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private int mSpaceState; private SettingsValues mSettingsValues; + private InputAttributes mInputAttributes; private View mExtractArea; private View mKeyPreviewBackingView; @@ -196,10 +197,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private UserUnigramDictionary mUserUnigramDictionary; private boolean mIsUserDictionaryAvailable; - private InputAttributes mInputAttributes; - private WordComposer mWordComposer = new WordComposer(); - private boolean mHasUncommittedTypedChars; private int mCorrectionMode; private String mWordSavedForAutoCorrectCancellation; @@ -511,7 +509,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar loadSettings(); // TODO: remove the following when it's not needed by updateCorrectionMode() any more - mInputAttributes = new InputAttributes(null); + mInputAttributes = new InputAttributes(null, false /* isFullscreenMode */); Utils.GCUtils.getInstance().reset(); boolean tryGC = true; for (int i = 0; i < Utils.GCUtils.GC_TRY_LOOP_MAX && tryGC; ++i) { @@ -754,12 +752,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // The EditorInfo might have a flag that affects fullscreen mode. // Note: This call should be done by InputMethodService? updateFullscreenMode(); - initializeInputAttributes(editorInfo); + mInputAttributes = new InputAttributes(editorInfo, isFullscreenMode()); + mApplicationSpecifiedCompletions = null; inputView.closing(); mEnteredText = null; mWordComposer.reset(); - mHasUncommittedTypedChars = false; mDeleteCount = 0; mSpaceState = SPACE_STATE_NONE; @@ -795,87 +793,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (TRACE) Debug.startMethodTracing("/data/trace/latinime"); } - private void initializeInputAttributes(final EditorInfo editorInfo) { - mInputAttributes = new InputAttributes(editorInfo); - - final boolean insertSpaceOnPickSuggestionManually; - final boolean inputTypeNoAutoCorrect; - final boolean isSettingsSuggestionStripOn; - boolean applicationSpecifiedCompletionOn = false; - - if (editorInfo == null || editorInfo.inputType != InputType.TYPE_CLASS_TEXT) { - if (editorInfo.inputType == InputType.TYPE_NULL) { - // TODO: We should honor TYPE_NULL specification. - Log.i(TAG, "InputType.TYPE_NULL is specified"); - } - mApplicationSpecifiedCompletions = null; - insertSpaceOnPickSuggestionManually = false; - isSettingsSuggestionStripOn = false; - inputTypeNoAutoCorrect = false; - } else { - final int inputType = editorInfo.inputType; - final int inputClass = inputType & InputType.TYPE_MASK_CLASS; - final int variation = inputType & InputType.TYPE_MASK_VARIATION; - if (inputClass == 0) { - Log.w(TAG, String.format("Unexpected input class: inputType=0x%08x" - + " imeOptions=0x%08x", - inputType, editorInfo.imeOptions)); - } - final boolean flagNoSuggestions = - 0 != (inputType & InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); - final boolean flagMultiLine = - 0 != (inputType & InputType.TYPE_TEXT_FLAG_MULTI_LINE); - final boolean flagAutoCorrect = - 0 != (inputType & InputType.TYPE_TEXT_FLAG_AUTO_CORRECT); - final boolean flagAutoComplete = - 0 != (inputType & InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE); - - mApplicationSpecifiedCompletions = null; - - // Make sure that passwords are not displayed in {@link SuggestionsView}. - if (InputTypeCompatUtils.isPasswordInputType(inputType) - || InputTypeCompatUtils.isVisiblePasswordInputType(inputType) - || InputTypeCompatUtils.isEmailVariation(variation) - || InputType.TYPE_TEXT_VARIATION_URI == variation - || InputType.TYPE_TEXT_VARIATION_FILTER == variation - || flagNoSuggestions - || flagAutoComplete) { - isSettingsSuggestionStripOn = false; - } else { - isSettingsSuggestionStripOn = true; - } - - if (InputTypeCompatUtils.isEmailVariation(variation) - || variation == InputType.TYPE_TEXT_VARIATION_PERSON_NAME) { - // The point in turning this off is that we don't want to insert a space after - // a name when filling a form: we can't delete trailing spaces when changing fields - insertSpaceOnPickSuggestionManually = false; - } else { - insertSpaceOnPickSuggestionManually = true; - } - - // If it's a browser edit field and auto correct is not ON explicitly, then - // disable auto correction, but keep suggestions on. - // If NO_SUGGESTIONS is set, don't do prediction. - // If it's not multiline and the autoCorrect flag is not set, then don't correct - if ((variation == InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT && !flagAutoCorrect) - || flagNoSuggestions - || (!flagAutoCorrect && !flagMultiLine)) { - inputTypeNoAutoCorrect = true; - } else { - inputTypeNoAutoCorrect = false; - } - if (flagAutoComplete) { - applicationSpecifiedCompletionOn = isFullscreenMode(); - } - } - - mInputAttributes.mInsertSpaceOnPickSuggestionManually = insertSpaceOnPickSuggestionManually; - mInputAttributes.mInputTypeNoAutoCorrect = inputTypeNoAutoCorrect; - mInputAttributes.mIsSettingsSuggestionStripOn = isSettingsSuggestionStripOn; - mInputAttributes.mApplicationSpecifiedCompletionOn = applicationSpecifiedCompletionOn; - } - @Override public void onWindowHidden() { super.onWindowHidden(); @@ -944,11 +861,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // newly inserted punctuation. mSpaceState = SPACE_STATE_NONE; } - if (((mWordComposer.size() > 0 && mHasUncommittedTypedChars) + if (((mWordComposer.isComposingWord()) || mVoiceProxy.isVoiceInputHighlighted()) && (selectionChanged || candidatesCleared)) { mWordComposer.reset(); - mHasUncommittedTypedChars = false; updateSuggestions(); final InputConnection ic = getCurrentInputConnection(); if (ic != null) { @@ -956,7 +872,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } mComposingStateManager.onFinishComposingText(); mVoiceProxy.setVoiceInputHighlighted(false); - } else if (!mHasUncommittedTypedChars) { + } else if (!mWordComposer.isComposingWord()) { updateSuggestions(); } } @@ -1157,8 +1073,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } public void commitTyped(final InputConnection ic) { - if (!mHasUncommittedTypedChars) return; - mHasUncommittedTypedChars = false; + if (!mWordComposer.isComposingWord()) return; final CharSequence typedWord = mWordComposer.getTypedWord(); mWordComposer.onCommitWord(); if (typedWord.length() > 0) { @@ -1433,18 +1348,18 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar return; } - if (mHasUncommittedTypedChars) { + if (mWordComposer.isComposingWord()) { final int length = mWordComposer.size(); if (length > 0) { mWordComposer.deleteLast(); ic.setComposingText(getTextWithUnderline(mWordComposer.getTypedWord()), 1); - if (mWordComposer.size() == 0) { - mHasUncommittedTypedChars = false; - // Remaining size equals zero means we just erased the last character of the - // word, so we can show bigrams. + // If we have deleted the last remaining character of a word, then we are not + // isComposingWord() any more. + if (!mWordComposer.isComposingWord()) { + // Not composing word any more, so we can show bigrams. mHandler.postUpdateBigramPredictions(); } else { - // length > 1, so we still have letters to deduce a suggestion from. + // Still composing a word, so we still have letters to deduce a suggestion from. mHandler.postUpdateSuggestions(); } } else { @@ -1533,7 +1448,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (null != ic) removeTrailingSpaceWhileInBatchEdit(ic); } - boolean isComposingWord = mHasUncommittedTypedChars; + boolean isComposingWord = mWordComposer.isComposingWord(); int code = primaryCode; if ((isAlphabet(code) || mSettingsValues.isSymbolExcludedFromWordSeparators(code)) && isSuggestionsRequested() && !isCursorTouchingWord()) { @@ -1570,7 +1485,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } } if (isComposingWord) { - mHasUncommittedTypedChars = true; mWordComposer.add(code, keyCodes, x, y); if (ic != null) { // If it's the first letter, make note of auto-caps state @@ -1616,7 +1530,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // Reset the saved word in all cases. If this separator causes an autocorrection, // it will overwrite this null with the actual word we need to save. mWordSavedForAutoCorrectCancellation = null; - if (mHasUncommittedTypedChars) { + if (mWordComposer.isComposingWord()) { // In certain languages where single quote is a separator, it's better // not to auto correct, but accept the typed word. For instance, // in Italian dov' should not be expanded to dove' because the elision @@ -1791,7 +1705,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mHandler.cancelUpdateSuggestions(); mHandler.cancelUpdateBigramPredictions(); - if (!mHasUncommittedTypedChars) { + if (!mWordComposer.isComposingWord()) { setPunctuationSuggestions(); return; } @@ -1966,11 +1880,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } return; } - if (!mHasUncommittedTypedChars) { - // If we are not composing a word, then it was a suggestion inferred from - // context - no user input. We should reset the word composer. - mWordComposer.reset(); - } mExpectingUpdateSelection = true; commitBestWord(suggestion); // Add the word to the auto dictionary if it's not a known word @@ -1980,8 +1889,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } else { addToOnlyBigramDictionary(suggestion, 1); } - // TODO: the following is fishy, because if !mHasUncommittedTypedChars we are - // going to log an empty string + // TODO: the following is fishy, because it seems there may be cases where we are not + // composing a word at all. Maybe throw an exception if !mWordComposer.isComposingWord() ? LatinImeLogger.logOnManualSuggestion(mWordComposer.getTypedWord().toString(), suggestion.toString(), index, suggestions.mWords); // Follow it with a space @@ -2046,7 +1955,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar ic.commitText(bestWord, 1); } } - mHasUncommittedTypedChars = false; mWordComposer.onCommitWord(); } @@ -2190,7 +2098,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private void restartSuggestionsOnWordBeforeCursor(final InputConnection ic, final CharSequence word) { mWordComposer.setComposingWord(word, mKeyboardSwitcher.getLatinKeyboard()); - mHasUncommittedTypedChars = true; mComposingStateManager.onStartComposingText(); ic.deleteSurroundingText(word.length(), 0); ic.setComposingText(word, 1); @@ -2249,7 +2156,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // Note: in the interest of code simplicity, we may want to just call // restartSuggestionsOnWordBeforeCursorIfAtEndOfWord instead, but retrieving // the old WordComposer allows to reuse the actual typed coordinates. - mHasUncommittedTypedChars = true; mWordComposer.resumeSuggestionOnKeptWord(); ic.setComposingText(mWordComposer.getTypedWord(), 1); mHandler.cancelUpdateBigramPredictions(); @@ -2537,14 +2443,11 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar p.println(" Keyboard mode = " + keyboardMode); p.println(" mIsSuggestionsRequested=" + mInputAttributes.mIsSettingsSuggestionStripOn); p.println(" mCorrectionMode=" + mCorrectionMode); - p.println(" mHasUncommittedTypedChars=" + mHasUncommittedTypedChars); + p.println(" isComposingWord=" + mWordComposer.isComposingWord()); p.println(" mAutoCorrectEnabled=" + mSettingsValues.mAutoCorrectEnabled); - p.println(" mInsertSpaceOnPickSuggestionManually=" - + mInputAttributes.mInsertSpaceOnPickSuggestionManually); - p.println(" mApplicationSpecifiedCompletionOn=" - + mInputAttributes.mApplicationSpecifiedCompletionOn); p.println(" mSoundOn=" + mSettingsValues.mSoundOn); p.println(" mVibrateOn=" + mSettingsValues.mVibrateOn); p.println(" mKeyPreviewPopupOn=" + mSettingsValues.mKeyPreviewPopupOn); + p.println(" mInputAttributes=" + mInputAttributes.toString()); } } diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java index c0204c2a6..b88e73fc7 100644 --- a/java/src/com/android/inputmethod/latin/WordComposer.java +++ b/java/src/com/android/inputmethod/latin/WordComposer.java @@ -120,6 +120,10 @@ public class WordComposer { return mCurrentWord.mTypedWord.length(); } + public final boolean isComposingWord() { + return size() > 0; + } + /** * Returns the codes at a particular position in the word. * @param index the position in the word |