diff options
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinIME.java | 92 |
1 files changed, 81 insertions, 11 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 74fc18523..2c4b34f4d 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -160,6 +160,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private Settings.Values mSettingsValues; + private View mExtractArea; private View mKeyPreviewBackingView; private View mSuggestionsContainer; private SuggestionsView mSuggestionsView; @@ -229,6 +230,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // Keeps track of most recently inserted text (multi-character key) for reverting private CharSequence mEnteredText; + private final ComposingStateManager mComposingStateManager = + new ComposingStateManager(); + public final UIHandler mHandler = new UIHandler(this); public static class UIHandler extends StaticInnerHandlerWrapper<LatinIME> { @@ -610,6 +614,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar @Override public void onConfigurationChanged(Configuration conf) { mSubtypeSwitcher.onConfigurationChanged(conf); + mComposingStateManager.onFinishComposingText(); // If orientation changed while predicting, commit the change if (mDisplayOrientation != conf.orientation) { mDisplayOrientation = conf.orientation; @@ -638,6 +643,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar @Override public void setInputView(View view) { super.setInputView(view); + mExtractArea = getWindow().getWindow().getDecorView() + .findViewById(android.R.id.extractArea); mKeyPreviewBackingView = view.findViewById(R.id.key_preview_backing); mSuggestionsContainer = view.findViewById(R.id.suggestions_container); mSuggestionsView = (SuggestionsView) view.findViewById(R.id.suggestions_view); @@ -881,6 +888,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (ic != null) { ic.finishComposingText(); } + mComposingStateManager.onFinishComposingText(); mVoiceProxy.setVoiceInputHighlighted(false); } else if (!mHasUncommittedTypedChars) { TextEntryState.reset(); @@ -1000,11 +1008,15 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar final KeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); if (inputView == null || mSuggestionsContainer == null) return; + // In fullscreen mode, the height of the extract area managed by InputMethodService should + // be considered. + // See {@link android.inputmethodservice.InputMethodService#onComputeInsets}. + final int extractHeight = isFullscreenMode() ? mExtractArea.getHeight() : 0; final int backingHeight = (mKeyPreviewBackingView.getVisibility() == View.GONE) ? 0 : mKeyPreviewBackingView.getHeight(); final int suggestionsHeight = (mSuggestionsContainer.getVisibility() == View.GONE) ? 0 : mSuggestionsContainer.getHeight(); - final int extraHeight = backingHeight + suggestionsHeight; + final int extraHeight = extractHeight + backingHeight + suggestionsHeight; int touchY = extraHeight; // Need to set touchable region only if input view is being shown if (mKeyboardSwitcher.isInputViewShown()) { @@ -1045,9 +1057,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar super.updateFullscreenMode(); if (mKeyPreviewBackingView == null) return; - // In fullscreen mode, no need to have extra space to show the key preview. + // In extract mode, no need to have extra space to show the key preview. // If not, we should have extra space above the keyboard to show the key preview. - mKeyPreviewBackingView.setVisibility(isFullscreenMode() ? View.GONE : View.VISIBLE); + mKeyPreviewBackingView.setVisibility(isExtractViewShown() ? View.GONE : View.VISIBLE); } @Override @@ -1336,7 +1348,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (length > 0) { mComposingStringBuilder.delete(length - 1, length); mWordComposer.deleteLast(); - ic.setComposingText(mComposingStringBuilder, 1); + final CharSequence textWithUnderline = + mComposingStateManager.isAutoCorrectionIndicatorOn() + ? SuggestionSpanUtils.getTextWithAutoCorrectionIndicatorUnderline( + this, mComposingStringBuilder) + : mComposingStringBuilder; + ic.setComposingText(textWithUnderline, 1); if (mComposingStringBuilder.length() == 0) { mHasUncommittedTypedChars = false; } @@ -1427,6 +1444,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mComposingStringBuilder.setLength(0); mWordComposer.reset(); clearSuggestions(); + mComposingStateManager.onFinishComposingText(); } } final KeyboardSwitcher switcher = mKeyboardSwitcher; @@ -1458,8 +1476,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // If it's the first letter, make note of auto-caps state if (mWordComposer.size() == 1) { mWordComposer.setAutoCapitalized(getCurrentAutoCapsState()); + mComposingStateManager.onStartComposingText(); } - ic.setComposingText(mComposingStringBuilder, 1); + final CharSequence textWithUnderline = + mComposingStateManager.isAutoCorrectionIndicatorOn() + ? SuggestionSpanUtils.getTextWithAutoCorrectionIndicatorUnderline( + this, mComposingStringBuilder) + : mComposingStringBuilder; + ic.setComposingText(textWithUnderline, 1); } mHandler.postUpdateSuggestions(); } else { @@ -1478,6 +1502,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private void handleSeparator(int primaryCode, int x, int y) { mVoiceProxy.handleSeparator(); + mComposingStateManager.onFinishComposingText(); // Should dismiss the "Touch again to save" message when handling separator if (mSuggestionsView != null && mSuggestionsView.dismissAddToDictionaryHint()) { @@ -1615,12 +1640,19 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // Put a blue underline to a word in TextView which will be auto-corrected. final InputConnection ic = getCurrentInputConnection(); - if (ic != null && Utils.willAutoCorrect(words)) { - final CharSequence textWithUnderline = - SuggestionSpanUtils.getTextWithAutoCorrectionIndicatorUnderline( - this, mComposingStringBuilder); - if (!TextUtils.isEmpty(textWithUnderline)) { - ic.setComposingText(textWithUnderline, 1); + if (ic != null) { + final boolean oldAutoCorrectionIndicator = + mComposingStateManager.isAutoCorrectionIndicatorOn(); + final boolean newAutoCorrectionIndicator = Utils.willAutoCorrect(words); + if (oldAutoCorrectionIndicator != newAutoCorrectionIndicator) { + final CharSequence textWithUnderline = newAutoCorrectionIndicator + ? SuggestionSpanUtils.getTextWithAutoCorrectionIndicatorUnderline( + this, mComposingStringBuilder) + : mComposingStringBuilder; + if (!TextUtils.isEmpty(textWithUnderline)) { + ic.setComposingText(textWithUnderline, 1); + } + mComposingStateManager.setAutoCorrectionIndicatorOn(newAutoCorrectionIndicator); } } } @@ -1732,6 +1764,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar @Override public void pickSuggestionManually(int index, CharSequence suggestion) { + mComposingStateManager.onFinishComposingText(); SuggestedWords suggestions = mSuggestionsView.getSuggestions(); mVoiceProxy.flushAndLogAllTextModificationCounters(index, suggestion, mSettingsValues.mWordSeparators); @@ -2279,6 +2312,43 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar showOptionDialogInternal(builder.create()); } + private static class ComposingStateManager { + private boolean mAutoCorrectionIndicatorOn; + private boolean mIsComposing; + public ComposingStateManager() { + mAutoCorrectionIndicatorOn = false; + mIsComposing = false; + } + + private void onStartComposingText() { + if (!mIsComposing) { + if (LatinImeLogger.sDBG) { + Log.i(TAG, "Start composing text."); + } + mAutoCorrectionIndicatorOn = false; + mIsComposing = true; + } + } + + private void onFinishComposingText() { + if (mIsComposing) { + if (LatinImeLogger.sDBG) { + Log.i(TAG, "Finish composing text."); + } + mAutoCorrectionIndicatorOn = false; + mIsComposing = false; + } + } + + public boolean isAutoCorrectionIndicatorOn() { + return mAutoCorrectionIndicatorOn; + } + + public void setAutoCorrectionIndicatorOn(boolean on) { + mAutoCorrectionIndicatorOn = on; + } + } + @Override protected void dump(FileDescriptor fd, PrintWriter fout, String[] args) { super.dump(fd, fout, args); |