aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com
diff options
context:
space:
mode:
authorsatok <satok@google.com>2011-10-12 10:08:50 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-10-12 10:08:50 -0700
commitef0a7b75462c75b756caa09d9dd356309968abf3 (patch)
tree362f16dc041cf142df49a730b34051b2ba020ce2 /java/src/com
parent9ad9425e9bc44c593e14da1f5953925cbf75a8a5 (diff)
parent604d80c67185954d4691ac775be59c499eee3b1c (diff)
downloadlatinime-ef0a7b75462c75b756caa09d9dd356309968abf3.tar.gz
latinime-ef0a7b75462c75b756caa09d9dd356309968abf3.tar.xz
latinime-ef0a7b75462c75b756caa09d9dd356309968abf3.zip
Merge "Suppress flickers of the auto correction indicator" into ics-mr0
Diffstat (limited to 'java/src/com')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java79
1 files changed, 71 insertions, 8 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 74fc18523..3c878d0a8 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -229,6 +229,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 +613,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;
@@ -881,6 +885,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (ic != null) {
ic.finishComposingText();
}
+ mComposingStateManager.onFinishComposingText();
mVoiceProxy.setVoiceInputHighlighted(false);
} else if (!mHasUncommittedTypedChars) {
TextEntryState.reset();
@@ -1336,7 +1341,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 +1437,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mComposingStringBuilder.setLength(0);
mWordComposer.reset();
clearSuggestions();
+ mComposingStateManager.onFinishComposingText();
}
}
final KeyboardSwitcher switcher = mKeyboardSwitcher;
@@ -1458,8 +1469,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 +1495,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 +1633,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 +1757,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 +2305,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);