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

Commit 9915c4ba authored by Justin Ghan's avatar Justin Ghan
Browse files

Revert "Handle non-initalized InkWindow"

This reverts commit c87e17af.

Reason for revert: Breaks stylus handwriting

Change-Id: Ifb11d327eac4b8858aaccfa7e171327f8eb18cdd
parent c87e17af
Loading
Loading
Loading
Loading
+5 −13
Original line number Original line Diff line number Diff line
@@ -967,7 +967,7 @@ public class InputMethodService extends AbstractInputMethodService {
                Log.d(TAG, "Input should have started before starting Stylus handwriting.");
                Log.d(TAG, "Input should have started before starting Stylus handwriting.");
                return;
                return;
            }
            }
            maybeCreateAndInitInkWindow();
            maybeCreateInkWindow();
            if (!mOnPreparedStylusHwCalled) {
            if (!mOnPreparedStylusHwCalled) {
                // prepare hasn't been called by Stylus HOVER.
                // prepare hasn't been called by Stylus HOVER.
                onPrepareStylusHandwriting();
                onPrepareStylusHandwriting();
@@ -1027,7 +1027,8 @@ public class InputMethodService extends AbstractInputMethodService {
         */
         */
        @Override
        @Override
        public void initInkWindow() {
        public void initInkWindow() {
            maybeCreateAndInitInkWindow();
            maybeCreateInkWindow();
            mInkWindow.initOnly();
            onPrepareStylusHandwriting();
            onPrepareStylusHandwriting();
            mOnPreparedStylusHwCalled = true;
            mOnPreparedStylusHwCalled = true;
        }
        }
@@ -1035,13 +1036,11 @@ public class InputMethodService extends AbstractInputMethodService {
        /**
        /**
         * Create and attach token to Ink window if it wasn't already created.
         * Create and attach token to Ink window if it wasn't already created.
         */
         */
        private void maybeCreateAndInitInkWindow() {
        private void maybeCreateInkWindow() {
            if (mInkWindow == null) {
            if (mInkWindow == null) {
                mInkWindow = new InkWindow(mWindow.getContext());
                mInkWindow = new InkWindow(mWindow.getContext());
                mInkWindow.setToken(mToken);
                mInkWindow.setToken(mToken);
            }
            }
            mInkWindow.initOnly();
            setInkViewVisibilityListener();
            // TODO(b/243571274): set an idle-timeout after which InkWindow is removed.
            // TODO(b/243571274): set an idle-timeout after which InkWindow is removed.
        }
        }


@@ -2470,19 +2469,13 @@ public class InputMethodService extends AbstractInputMethodService {
     * @param motionEvent {@link MotionEvent} from stylus.
     * @param motionEvent {@link MotionEvent} from stylus.
     */
     */
    public void onStylusHandwritingMotionEvent(@NonNull MotionEvent motionEvent) {
    public void onStylusHandwritingMotionEvent(@NonNull MotionEvent motionEvent) {
        if (mInkWindow != null && mInkWindow.isInkViewVisible()) {
        if (mInkWindow.isInkViewVisible()) {
            mInkWindow.getDecorView().dispatchTouchEvent(motionEvent);
            mInkWindow.getDecorView().dispatchTouchEvent(motionEvent);
        } else {
        } else {
            if (mPendingEvents == null) {
            if (mPendingEvents == null) {
                mPendingEvents = new RingBuffer(MotionEvent.class, MAX_EVENTS_BUFFER);
                mPendingEvents = new RingBuffer(MotionEvent.class, MAX_EVENTS_BUFFER);
            }
            }
            mPendingEvents.append(motionEvent);
            mPendingEvents.append(motionEvent);
            setInkViewVisibilityListener();
        }
    }

    private void setInkViewVisibilityListener() {
        if (mInkWindow != null) {
            mInkWindow.setInkViewVisibilityListener(() -> {
            mInkWindow.setInkViewVisibilityListener(() -> {
                if (mPendingEvents != null && !mPendingEvents.isEmpty()) {
                if (mPendingEvents != null && !mPendingEvents.isEmpty()) {
                    for (MotionEvent event : mPendingEvents.toArray()) {
                    for (MotionEvent event : mPendingEvents.toArray()) {
@@ -2546,7 +2539,6 @@ public class InputMethodService extends AbstractInputMethodService {
            mHandler.removeCallbacks(mFinishHwRunnable);
            mHandler.removeCallbacks(mFinishHwRunnable);
        }
        }
        mFinishHwRunnable = null;
        mFinishHwRunnable = null;
        mPendingEvents.clear();


        final int requestId = mHandwritingRequestId.getAsInt();
        final int requestId = mHandwritingRequestId.getAsInt();
        mHandwritingRequestId = OptionalInt.empty();
        mHandwritingRequestId = OptionalInt.empty();