diff options
| author | 2023-03-31 19:17:39 +0000 | |
|---|---|---|
| committer | 2023-03-31 19:24:51 +0000 | |
| commit | 0cb1ad008a9976c8b64cbe39206e4b02a8a4220f (patch) | |
| tree | 3347854024e2457b3cfc6d69c105ba8110d3d2b5 | |
| parent | 528dfcfe70f51cd1642f7f98b13d8fedc1d01f41 (diff) | |
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
4 files changed, 19 insertions, 3 deletions
diff --git a/core/java/android/inputmethodservice/InkWindow.java b/core/java/android/inputmethodservice/InkWindow.java index 70bd5046524e..15ed45041d32 100644 --- a/core/java/android/inputmethodservice/InkWindow.java +++ b/core/java/android/inputmethodservice/InkWindow.java @@ -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); + } } diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java index ee9d8a44167c..a9c4818393a8 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -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(); } diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 152fa08d2a9d..c30b5953adce 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -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); } diff --git a/services/core/java/com/android/server/inputmethod/HandwritingModeController.java b/services/core/java/com/android/server/inputmethod/HandwritingModeController.java index bb1a445b52e9..effef47e21d6 100644 --- a/services/core/java/com/android/server/inputmethod/HandwritingModeController.java +++ b/services/core/java/com/android/server/inputmethod/HandwritingModeController.java @@ -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); } |