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

Commit 342509f0 authored by Taran Singh's avatar Taran Singh
Browse files

Scribe in IMF: Early InkWindow preparation 6/N

Allow stylus hover events for:
1. send early signal to IME onPrepareStylusHandwriting()
2. Prepare InkWindow internally.

Test: atest StylusHandwritingTest
Bug: 210039666
Bug: 203086136

Change-Id: Iebbd62659cb98b3c61edfa35d5a84a1c6837eb23
parent 52f33049
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -18659,6 +18659,7 @@ package android.inputmethodservice {
    method public boolean onKeyLongPress(int, android.view.KeyEvent);
    method public boolean onKeyMultiple(int, int, android.view.KeyEvent);
    method public boolean onKeyUp(int, android.view.KeyEvent);
    method public void onPrepareStylusHandwriting();
    method public boolean onShowInputRequested(int, boolean);
    method public void onStartCandidatesView(android.view.inputmethod.EditorInfo, boolean);
    method public void onStartInput(android.view.inputmethod.EditorInfo, boolean);
+11 −0
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ class IInputMethodWrapper extends IInputMethod.Stub
    private static final int DO_CREATE_INLINE_SUGGESTIONS_REQUEST = 90;
    private static final int DO_CAN_START_STYLUS_HANDWRITING = 100;
    private static final int DO_START_STYLUS_HANDWRITING = 110;
    private static final int DO_INIT_INK_WINDOW = 120;

    final WeakReference<InputMethodServiceInternal> mTarget;
    final Context mContext;
@@ -250,6 +251,10 @@ class IInputMethodWrapper extends IInputMethod.Stub
                args.recycle();
                return;
            }
            case DO_INIT_INK_WINDOW: {
                inputMethod.initInkWindow();
                return;
            }

        }
        Log.w(TAG, "Unhandled message code: " + msg.what);
@@ -400,4 +405,10 @@ class IInputMethodWrapper extends IInputMethod.Stub
                mCaller.obtainMessageIOO(DO_START_STYLUS_HANDWRITING, requestId, channel,
                        stylusEvents));
    }

    @BinderThread
    @Override
    public void initInkWindow() {
        mCaller.executeOrSendMessage(mCaller.obtainMessage(DO_INIT_INK_WINDOW));
    }
}
+19 −1
Original line number Diff line number Diff line
@@ -58,16 +58,27 @@ final class InkWindow extends PhoneWindow {
        mWindowManager = context.getSystemService(WindowManager.class);
    }

    /**
     * Initialize InkWindow if we only want to create and draw surface but not show it.
     */
    void initOnly() {
        show(true /* keepInvisible */);
    }

    /**
     * Method to show InkWindow on screen.
     * Emulates internal behavior similar to Dialog.show().
     */
    void show() {
        show(false /* keepInvisible */);
    }

    private void show(boolean keepInvisible) {
        if (getDecorView() == null) {
            Slog.i(InputMethodService.TAG, "DecorView is not set for InkWindow. show() failed.");
            return;
        }
        getDecorView().setVisibility(View.VISIBLE);
        getDecorView().setVisibility(keepInvisible ? View.INVISIBLE : View.VISIBLE);
        if (!mIsViewAdded) {
            mWindowManager.addView(getDecorView(), getAttributes());
            mIsViewAdded = true;
@@ -91,4 +102,11 @@ final class InkWindow extends PhoneWindow {
        lp.token = token;
        setAttributes(lp);
    }

    /**
     * Returns {@code true} if Window was created and added to WM.
     */
    boolean isInitialized() {
        return mIsViewAdded;
    }
}
+31 −1
Original line number Diff line number Diff line
@@ -742,6 +742,10 @@ public class InputMethodService extends AbstractInputMethodService {
            onUnbindInput();
            mInputBinding = null;
            mInputConnection = null;
            // free-up cached InkWindow surface on detaching from current client.
            if (mInkWindow != null) {
                mInkWindow.hide(true /* remove */);
            }
        }

        /**
@@ -902,6 +906,10 @@ public class InputMethodService extends AbstractInputMethodService {
                Log.d(TAG, "Input should have started before starting Stylus handwriting.");
                return;
            }
            if (!mInkWindow.isInitialized()) {
                // prepare hasn't been called by Stylus HOVER.
                onPrepareStylusHandwriting();
            }
            if (onStartStylusHandwriting()) {
                mPrivOps.onStylusHandwritingReady(requestId);
            } else {
@@ -947,6 +955,16 @@ public class InputMethodService extends AbstractInputMethodService {
        }


        /**
         * {@inheritDoc}
         * @hide
         */
        @Override
        public void initInkWindow() {
            mInkWindow.initOnly();
            onPrepareStylusHandwriting();
        }

        /**
         * {@inheritDoc}
         */
@@ -2319,6 +2337,18 @@ public class InputMethodService extends AbstractInputMethodService {
        }
    }

    /**
     * Called to prepare stylus handwriting.
     * The system calls this before the first {@link #onStartStylusHandwriting} request.
     *
     * <p>Note: The system tries to call this as early as possible, when it detects that
     * handwriting stylus input is imminent. However, that a subsequent call to
     * {@link #onStartStylusHandwriting} actually happens is not guaranteed.</p>
     */
    public void onPrepareStylusHandwriting() {
        // Intentionally empty
    }

    /**
     * Called when an app requests stylus handwriting
     * {@link InputMethodManager#startStylusHandwriting(View)}.
+8 −0
Original line number Diff line number Diff line
@@ -409,4 +409,12 @@ public interface InputMethod {
        // intentionally empty
    }

    /**
     * Initialize Ink window early-on.
     * @hide
     */
    default void initInkWindow() {
        // intentionally empty
    }

}
Loading