Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4a3d4620 authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka Committed by Android (Google) Code Review
Browse files

Merge "Fix language switch key behavior"

parents 8590667d 1931c1ca
Loading
Loading
Loading
Loading
+30 −18
Original line number Diff line number Diff line
@@ -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();
@@ -893,6 +919,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
        // Make a note of the cursor position
        mLastSelectionStart = newSelStart;
        mLastSelectionEnd = newSelEnd;
        mSubtypeState.currentSubtypeUsed();
    }

    /**
@@ -1240,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) {
@@ -1322,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:
@@ -1378,7 +1391,6 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
                handleCharacter(primaryCode, keyX, keyY, spaceState);
            }
            mExpectingUpdateSelection = true;
            mShouldSwitchToLastSubtype = true;
            break;
        }
        switcher.onCodeInput(primaryCode);
+5 −0
Original line number Diff line number Diff line
@@ -206,6 +206,11 @@ public final class RichInputMethodManager {
        return null;
    }

    public void setInputMethodAndSubtype(final IBinder token, final InputMethodSubtype subtype) {
        mImmWrapper.mImm.setInputMethodAndSubtype(
                token, mInputMethodInfoOfThisIme.getId(), subtype);
    }

    public void setAdditionalInputMethodSubtypes(final InputMethodSubtype[] subtypes) {
        mImmWrapper.mImm.setAdditionalInputMethodSubtypes(
                mInputMethodInfoOfThisIme.getId(), subtypes);