aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/LatinIME.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIME.java')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java87
1 files changed, 50 insertions, 37 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 3dfffc4a6..5f7907326 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -56,7 +56,6 @@ import android.view.WindowManager;
import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.CorrectionInfo;
import android.view.inputmethod.EditorInfo;
-import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.accessibility.AccessibilityUtils;
@@ -142,7 +141,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
private SharedPreferences mPrefs;
@UsedForTesting final KeyboardSwitcher mKeyboardSwitcher;
private final SubtypeSwitcher mSubtypeSwitcher;
- private boolean mShouldSwitchToLastSubtype = true;
+ private final SubtypeState mSubtypeState = new SubtypeState();
private boolean mIsMainDictionaryAvailable;
private UserBinaryDictionary mUserDictionary;
@@ -366,6 +365,33 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
}
}
+ static final class SubtypeState {
+ private InputMethodSubtype mLastActiveSubtype;
+ private boolean mCurrentSubtypeUsed;
+
+ public void currentSubtypeUsed() {
+ mCurrentSubtypeUsed = true;
+ }
+
+ public void switchSubtype(final IBinder token, final RichInputMethodManager richImm) {
+ final InputMethodSubtype currentSubtype = richImm.getInputMethodManager()
+ .getCurrentInputMethodSubtype();
+ final InputMethodSubtype lastActiveSubtype = mLastActiveSubtype;
+ final boolean currentSubtypeUsed = mCurrentSubtypeUsed;
+ if (currentSubtypeUsed) {
+ mLastActiveSubtype = currentSubtype;
+ mCurrentSubtypeUsed = false;
+ }
+ if (currentSubtypeUsed
+ && richImm.checkIfSubtypeBelongsToThisImeAndEnabled(lastActiveSubtype)
+ && !currentSubtype.equals(lastActiveSubtype)) {
+ richImm.setInputMethodAndSubtype(token, lastActiveSubtype);
+ return;
+ }
+ richImm.switchToNextInputMethod(token, true /* onlyCurrentIme */);
+ }
+ }
+
public LatinIME() {
super();
mSubtypeSwitcher = SubtypeSwitcher.getInstance();
@@ -710,21 +736,17 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
updateFullscreenMode();
mApplicationSpecifiedCompletions = null;
- if (isDifferentTextField || selectionChanged) {
- // If the selection changed, we reset the input state. Essentially, we come here with
- // restarting == true when the app called setText() or similar. We should reset the
- // state if the app set the text to something else, but keep it if it set a suggestion
- // or something.
- mEnteredText = null;
- resetComposingState(true /* alsoResetLastComposedWord */);
- mDeleteCount = 0;
- mSpaceState = SPACE_STATE_NONE;
+ // The app calling setText() has the effect of clearing the composing
+ // span, so we should reset our state unconditionally, even if restarting is true.
+ mEnteredText = null;
+ resetComposingState(true /* alsoResetLastComposedWord */);
+ mDeleteCount = 0;
+ mSpaceState = SPACE_STATE_NONE;
- if (mSuggestionStripView != null) {
- // This will set the punctuation suggestions if next word suggestion is off;
- // otherwise it will clear the suggestion strip.
- setPunctuationSuggestions();
- }
+ if (mSuggestionStripView != null) {
+ // This will set the punctuation suggestions if next word suggestion is off;
+ // otherwise it will clear the suggestion strip.
+ setPunctuationSuggestions();
}
mConnection.resetCachesUponCursorMove(editorInfo.initialSelStart);
@@ -897,6 +919,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
// Make a note of the cursor position
mLastSelectionStart = newSelStart;
mLastSelectionEnd = newSelEnd;
+ mSubtypeState.currentSubtypeUsed();
}
/**
@@ -1244,20 +1267,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
mRichImm.switchToNextInputMethod(token, false /* onlyCurrentIme */);
return;
}
- if (mShouldSwitchToLastSubtype) {
- final InputMethodManager imm = mRichImm.getInputMethodManager();
- final InputMethodSubtype lastSubtype = imm.getLastInputMethodSubtype();
- final boolean lastSubtypeBelongsToThisIme =
- mRichImm.checkIfSubtypeBelongsToThisImeAndEnabled(lastSubtype);
- if (lastSubtypeBelongsToThisIme && imm.switchToLastInputMethod(token)) {
- mShouldSwitchToLastSubtype = false;
- } else {
- mRichImm.switchToNextInputMethod(token, true /* onlyCurrentIme */);
- mShouldSwitchToLastSubtype = true;
- }
- } else {
- mRichImm.switchToNextInputMethod(token, true /* onlyCurrentIme */);
- }
+ mSubtypeState.switchSubtype(token, mRichImm);
}
private void sendDownUpKeyEventForBackwardCompatibility(final int code) {
@@ -1326,7 +1336,6 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
handleBackspace(spaceState);
mDeleteCount++;
mExpectingUpdateSelection = true;
- mShouldSwitchToLastSubtype = true;
LatinImeLogger.logOnDelete(x, y);
break;
case Constants.CODE_SHIFT:
@@ -1382,7 +1391,6 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
handleCharacter(primaryCode, keyX, keyY, spaceState);
}
mExpectingUpdateSelection = true;
- mShouldSwitchToLastSubtype = true;
break;
}
switcher.onCodeInput(primaryCode);
@@ -1411,7 +1419,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
mHandler.postUpdateSuggestionStrip();
final String text = specificTldProcessingOnTextInput(rawText);
if (SPACE_STATE_PHANTOM == mSpaceState) {
- sendKeyCodePoint(Constants.CODE_SPACE);
+ promotePhantomSpace();
}
mConnection.commitText(text, 1);
mConnection.endBatchEdit();
@@ -1574,7 +1582,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
mWordComposer.setBatchInputWord(batchInputText);
mConnection.beginBatchEdit();
if (SPACE_STATE_PHANTOM == mSpaceState) {
- sendKeyCodePoint(Constants.CODE_SPACE);
+ promotePhantomSpace();
}
mConnection.setComposingText(batchInputText, 1);
mExpectingUpdateSelection = true;
@@ -1729,7 +1737,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
// Sanity check
throw new RuntimeException("Should not be composing here");
}
- sendKeyCodePoint(Constants.CODE_SPACE);
+ promotePhantomSpace();
}
// NOTE: isCursorTouchingWord() is a blocking IPC call, so it often takes several
@@ -1806,7 +1814,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
if (SPACE_STATE_PHANTOM == spaceState &&
mCurrentSettings.isPhantomSpacePromotingSymbol(primaryCode)) {
- sendKeyCodePoint(Constants.CODE_SPACE);
+ promotePhantomSpace();
}
sendKeyCodePoint(primaryCode);
@@ -2070,7 +2078,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
int firstChar = Character.codePointAt(suggestion, 0);
if ((!mCurrentSettings.isWeakSpaceStripper(firstChar))
&& (!mCurrentSettings.isWeakSpaceSwapper(firstChar))) {
- sendKeyCodePoint(Constants.CODE_SPACE);
+ promotePhantomSpace();
}
}
@@ -2247,6 +2255,11 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
mHandler.postUpdateSuggestionStrip();
}
+ // This essentially inserts a space, and that's it.
+ public void promotePhantomSpace() {
+ sendKeyCodePoint(Constants.CODE_SPACE);
+ }
+
// Used by the RingCharBuffer
public boolean isWordSeparator(final int code) {
return mCurrentSettings.isWordSeparator(code);