From 341bd2b47e47b408aa355adb9327526a93bd19c9 Mon Sep 17 00:00:00 2001 From: Linnan Li Date: Wed, 31 Jul 2024 21:57:01 +0000 Subject: Notify focus view to HandwritingInitiator after inputType changes. Currently, after a View or window obtains focus, we notify the HandwritingInitiator. There is a necessary condition that `onCheckIsTextEditor` must pass its check. This leads to a situation where if the View doesn't pass the `onCheckIsTextEditor` check when it initially gains focus, even if the check is passed later on, it cannot notify again because there's no change in focus. Here, we try to address this issue by re-notifying the HandwritingInitiator of the focus event when the `inputType` changes. Bug: 353472560 Test: atest StylusHandwritingTest Flag: android.view.inputmethod.initiation_without_input_connection Signed-off-by: Linnan Li (cherry picked from https://partner-android-review.googlesource.com/q/commit:743573de8cb589b872c8c86db39a6d03693fe367) Merged-In: I6403bc6471bb5db1fa00a576d916a24114992b5d Change-Id: I6403bc6471bb5db1fa00a576d916a24114992b5d --- core/java/android/widget/TextView.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 9099db8d7e66..ac899f4c2b5e 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -31,6 +31,7 @@ import static android.view.inputmethod.EditorInfo.STYLUS_HANDWRITING_ENABLED_AND import static com.android.text.flags.Flags.FLAG_FIX_LINE_HEIGHT_FOR_LOCALE; import static com.android.text.flags.Flags.FLAG_USE_BOUNDS_FOR_WIDTH; +import static android.view.inputmethod.Flags.initiationWithoutInputConnection; import android.R; import android.annotation.CallSuper; @@ -2738,6 +2739,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener InputMethodManager imm = getInputMethodManager(); if (imm != null) imm.restartInput(this); + + ensureEditorFocusedNotifiedToHandwritingInitiator(); } private void setInputTypeFromEditor() { @@ -7843,6 +7846,20 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (type == InputType.TYPE_NULL && mEditor == null) return; //TYPE_NULL is the default value createEditorIfNeeded(); mEditor.mInputType = type; + ensureEditorFocusedNotifiedToHandwritingInitiator(); + } + + private void ensureEditorFocusedNotifiedToHandwritingInitiator() { + if (!initiationWithoutInputConnection() || isHandwritingDelegate()) { + return; + } + ViewRootImpl viewRoot = getViewRootImpl(); + if (viewRoot == null) { + return; + } + if (isFocused() && hasWindowFocus() && onCheckIsTextEditor()) { + viewRoot.getHandwritingInitiator().onEditorFocused(this); + } } @Override -- cgit v1.2.3-59-g8ed1b