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

Commit ae61f711 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Rotate IMEs (subtypes) by Meta+Space.

With this CL, PhoneWindowManager starts monitoring Meta+Space to trigger
input method rotation.

Note that InputMethodManagerService currently supports only one way
rotation.  Currently there is no difference in the behavior between
Meta+Space and Shift+Meta+Space.  Reverse rotation will be supported in
a subsequent CL.

Bug: 25753404
Change-Id: I4005692215edfcf8bed3e86b1e07000148f986f5
parent 540d9842
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -446,6 +446,13 @@ public interface WindowManagerPolicy {
         */
        public void switchKeyboardLayout(int deviceId, int direction);

        /**
         * Switch the input method, to be precise, input method subtype.
         *
         * @param forwardDirection {@code true} to rotate in a forward direction.
         */
        public void switchInputMethod(boolean forwardDirection);

        public void shutdown(boolean confirm);
        public void rebootSafeMode(boolean confirm);

+6 −1
Original line number Diff line number Diff line
@@ -26,5 +26,10 @@ public interface InputMethodManagerInternal {
     * Called by the power manager to tell the input method manager whether it
     * should start watching for wake events.
     */
    public void setInteractive(boolean interactive);
    void setInteractive(boolean interactive);

    /**
     * Called by the window manager to let the input method manager rotate the input method.
     */
    void switchInputMethod(boolean forwardDirection);
}
+23 −0
Original line number Diff line number Diff line
@@ -166,6 +166,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
    static final int MSG_SET_ACTIVE = 3020;
    static final int MSG_SET_INTERACTIVE = 3030;
    static final int MSG_SET_USER_ACTION_NOTIFICATION_SEQUENCE_NUMBER = 3040;
    static final int MSG_SWITCH_IME = 3050;

    static final int MSG_HARD_KEYBOARD_SWITCH_CHANGED = 4000;

@@ -2851,6 +2852,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            case MSG_SET_INTERACTIVE:
                handleSetInteractive(msg.arg1 != 0);
                return true;
            case MSG_SWITCH_IME:
                handleSwitchInputMethod(msg.arg1 != 0);
                return true;
            case MSG_SET_USER_ACTION_NOTIFICATION_SEQUENCE_NUMBER: {
                final int sequenceNumber = msg.arg1;
                final ClientState clientState = (ClientState)msg.obj;
@@ -2887,6 +2891,18 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        }
    }

    private void handleSwitchInputMethod(final boolean forwardDirection) {
        synchronized (mMethodMap) {
            // TODO: Support forwardDirection.
            final ImeSubtypeListItem nextSubtype = mSwitchingController.getNextInputMethodLocked(
                    false, mMethodMap.get(mCurMethodId), mCurrentSubtype);
            if (nextSubtype == null) {
                return;
            }
            setInputMethodLocked(nextSubtype.mImi.getId(), nextSubtype.mSubtypeId);
        }
    }

    private boolean chooseNewDefaultIMELocked() {
        final InputMethodInfo imi = InputMethodUtils.getMostApplicableDefaultIME(
                mSettings.getEnabledInputMethodListLocked());
@@ -3728,6 +3744,13 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            mHandler.sendMessage(mHandler.obtainMessage(MSG_SET_INTERACTIVE,
                    interactive ? 1 : 0, 0));
        }

        @Override
        public void switchInputMethod(boolean forwardDirection) {
            // Do everything in handler so as not to block the caller.
            mHandler.sendMessage(mHandler.obtainMessage(MSG_SWITCH_IME,
                    forwardDirection ? 1 : 0, 0));
        }
    }

    @Override
+13 −4
Original line number Diff line number Diff line
@@ -3056,13 +3056,22 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            hideRecentApps(true, false);
        }

        // Handle keyboard language switching.
        // Handle keyboard layout switching.
        // TODO: Deprecate this behavior when we fully migrate to IME subtype-based layout rotation.
        if (down && repeatCount == 0 && keyCode == KeyEvent.KEYCODE_SPACE
                && ((metaState & KeyEvent.META_CTRL_MASK) != 0)) {
            int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
            mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
            return -1;
        }

        // Handle input method switching.
        if (down && repeatCount == 0
                && (keyCode == KeyEvent.KEYCODE_LANGUAGE_SWITCH
                        || (keyCode == KeyEvent.KEYCODE_SPACE
                                && (metaState & KeyEvent.META_CTRL_MASK) != 0))) {
            int direction = (metaState & KeyEvent.META_SHIFT_MASK) != 0 ? -1 : 1;
            mWindowManagerFuncs.switchKeyboardLayout(event.getDeviceId(), direction);
                                && (metaState & KeyEvent.META_META_MASK) != 0))) {
            final boolean forwardDirection = (metaState & KeyEvent.META_SHIFT_MASK) == 0;
            mWindowManagerFuncs.switchInputMethod(forwardDirection);
            return -1;
        }
        if (mLanguageSwitchKeyPressed && !down
+11 −0
Original line number Diff line number Diff line
@@ -185,6 +185,7 @@ import android.view.WindowManagerInternal;
import android.view.WindowManagerPolicy;
import android.view.WindowManagerPolicy.PointerEventListener;
import android.view.animation.Animation;
import android.view.inputmethod.InputMethodManagerInternal;
import android.widget.Toast;

import com.android.internal.R;
@@ -5279,6 +5280,16 @@ public class WindowManagerService extends IWindowManager.Stub
        mInputManager.switchKeyboardLayout(deviceId, direction);
    }

    // Called by window manager policy.  Not exposed externally.
    @Override
    public void switchInputMethod(boolean forwardDirection) {
        final InputMethodManagerInternal inputMethodManagerInternal =
                LocalServices.getService(InputMethodManagerInternal.class);
        if (inputMethodManagerInternal != null) {
            inputMethodManagerInternal.switchInputMethod(forwardDirection);
        }
    }

    // Called by window manager policy.  Not exposed externally.
    @Override
    public void shutdown(boolean confirm) {