Fix language switch key behavior

Bug: 7075923
Change-Id: I306e1ff5d9f873541e84e1fafb64b9473947f623
main
Tadashi G. Takaoka 2012-10-02 18:40:06 +09:00
parent eaaee28647
commit 1931c1cab1
2 changed files with 35 additions and 18 deletions

View File

@ -56,7 +56,6 @@ import android.view.WindowManager;
import android.view.inputmethod.CompletionInfo; import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.CorrectionInfo; import android.view.inputmethod.CorrectionInfo;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodSubtype; import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.accessibility.AccessibilityUtils; import com.android.inputmethod.accessibility.AccessibilityUtils;
@ -142,7 +141,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
private SharedPreferences mPrefs; private SharedPreferences mPrefs;
@UsedForTesting final KeyboardSwitcher mKeyboardSwitcher; @UsedForTesting final KeyboardSwitcher mKeyboardSwitcher;
private final SubtypeSwitcher mSubtypeSwitcher; private final SubtypeSwitcher mSubtypeSwitcher;
private boolean mShouldSwitchToLastSubtype = true; private final SubtypeState mSubtypeState = new SubtypeState();
private boolean mIsMainDictionaryAvailable; private boolean mIsMainDictionaryAvailable;
private UserBinaryDictionary mUserDictionary; 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() { public LatinIME() {
super(); super();
mSubtypeSwitcher = SubtypeSwitcher.getInstance(); mSubtypeSwitcher = SubtypeSwitcher.getInstance();
@ -897,6 +923,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
// Make a note of the cursor position // Make a note of the cursor position
mLastSelectionStart = newSelStart; mLastSelectionStart = newSelStart;
mLastSelectionEnd = newSelEnd; mLastSelectionEnd = newSelEnd;
mSubtypeState.currentSubtypeUsed();
} }
/** /**
@ -1244,20 +1271,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
mRichImm.switchToNextInputMethod(token, false /* onlyCurrentIme */); mRichImm.switchToNextInputMethod(token, false /* onlyCurrentIme */);
return; return;
} }
if (mShouldSwitchToLastSubtype) { mSubtypeState.switchSubtype(token, mRichImm);
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 */);
}
} }
private void sendDownUpKeyEventForBackwardCompatibility(final int code) { private void sendDownUpKeyEventForBackwardCompatibility(final int code) {
@ -1326,7 +1340,6 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
handleBackspace(spaceState); handleBackspace(spaceState);
mDeleteCount++; mDeleteCount++;
mExpectingUpdateSelection = true; mExpectingUpdateSelection = true;
mShouldSwitchToLastSubtype = true;
LatinImeLogger.logOnDelete(x, y); LatinImeLogger.logOnDelete(x, y);
break; break;
case Constants.CODE_SHIFT: case Constants.CODE_SHIFT:
@ -1382,7 +1395,6 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
handleCharacter(primaryCode, keyX, keyY, spaceState); handleCharacter(primaryCode, keyX, keyY, spaceState);
} }
mExpectingUpdateSelection = true; mExpectingUpdateSelection = true;
mShouldSwitchToLastSubtype = true;
break; break;
} }
switcher.onCodeInput(primaryCode); switcher.onCodeInput(primaryCode);

View File

@ -206,6 +206,11 @@ public final class RichInputMethodManager {
return null; return null;
} }
public void setInputMethodAndSubtype(final IBinder token, final InputMethodSubtype subtype) {
mImmWrapper.mImm.setInputMethodAndSubtype(
token, mInputMethodInfoOfThisIme.getId(), subtype);
}
public void setAdditionalInputMethodSubtypes(final InputMethodSubtype[] subtypes) { public void setAdditionalInputMethodSubtypes(final InputMethodSubtype[] subtypes) {
mImmWrapper.mImm.setAdditionalInputMethodSubtypes( mImmWrapper.mImm.setAdditionalInputMethodSubtypes(
mInputMethodInfoOfThisIme.getId(), subtypes); mInputMethodInfoOfThisIme.getId(), subtypes);