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

Commit 0cb1ad00 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

Integrate PointerIcon with Scribe

Here, we do two things:

1. To account for the case where the changed the stylus's PointerIcon,
   reset the PointerIcon when handwriting is successfully initiated.

2. Inject the handwriting events directly into the InkWindow's view root
   instead of dispatching it using the view's dispatchTouchEvent()
   method so that things that are handled by the InkView's root will
   work as expected, such as setting the pointer icon. This will allow
   the InkView to change the PointerIcon using onResolvePointerIcon.

Bug: 275851541
Test: Manual
Change-Id: I97d8d4293a5440a6d6531f279ed7811370671111
parent 528dfcfe
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -26,13 +26,17 @@ import android.annotation.NonNull;
import android.content.Context;
import android.os.IBinder;
import android.util.Slog;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewRootImpl;
import android.view.ViewTreeObserver;
import android.view.WindowManager;

import com.android.internal.policy.PhoneWindow;

import java.util.Objects;

/**
 * Window of type {@code LayoutParams.TYPE_INPUT_METHOD_DIALOG} for drawing
 * Handwriting Ink on screen.
@@ -185,4 +189,12 @@ final class InkWindow extends PhoneWindow {
        return getDecorView().getVisibility() == View.VISIBLE
                && mInkView != null && mInkView.isVisibleToUser();
    }

    void dispatchHandwritingEvent(@NonNull MotionEvent event) {
        final View decor = getDecorView();
        Objects.requireNonNull(decor);
        final ViewRootImpl viewRoot = decor.getViewRootImpl();
        Objects.requireNonNull(viewRoot);
        viewRoot.enqueueInputEvent(event);
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -2563,7 +2563,7 @@ public class InputMethodService extends AbstractInputMethodService {
     */
    public void onStylusHandwritingMotionEvent(@NonNull MotionEvent motionEvent) {
        if (mInkWindow != null && mInkWindow.isInkViewVisible()) {
            mInkWindow.getDecorView().dispatchTouchEvent(motionEvent);
            mInkWindow.dispatchHandwritingEvent(motionEvent);
        } else {
            if (mPendingEvents == null) {
                mPendingEvents = new RingBuffer(MotionEvent.class, MAX_EVENTS_BUFFER);
@@ -2576,7 +2576,7 @@ public class InputMethodService extends AbstractInputMethodService {
                            if (mInkWindow == null) {
                                break;
                            }
                            mInkWindow.getDecorView().dispatchTouchEvent(event);
                            mInkWindow.dispatchHandwritingEvent(event);
                        }
                        mPendingEvents.clear();
                    }
+1 −1
Original line number Diff line number Diff line
@@ -9272,7 +9272,7 @@ public final class ViewRootImpl implements ViewParent,
    }

    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    void enqueueInputEvent(InputEvent event) {
    public void enqueueInputEvent(InputEvent event) {
        enqueueInputEvent(event, null, 0, false);
    }

+4 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.view.InputChannel;
import android.view.InputEvent;
import android.view.InputEventReceiver;
import android.view.MotionEvent;
import android.view.PointerIcon;
import android.view.SurfaceControl;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
@@ -273,6 +274,9 @@ final class HandwritingModeController {
        }
        mHandwritingSurface.startIntercepting(imePid, imeUid);

        // Unset the pointer icon for the stylus in case the app had set it.
        InputManagerGlobal.getInstance().setPointerIconType(PointerIcon.TYPE_NOT_SPECIFIED);

        return new HandwritingSession(mCurrentRequestId, mHandwritingSurface.getInputChannel(),
                mHandwritingBuffer);
    }