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

Commit ae2ddbcf authored by Linnan Li's avatar Linnan Li Committed by Justin Ghan
Browse files

Fix handwriting trigger fail even isAutoHandwritingEnabled is true



Currently, our focusedView only records the View for which the
isAutoHandwritingEnabled method returns true. If
isAutoHandwritingEnabled returns false when the View gains focus, we
will not record it as focusedView. Unfortunately, if the View then
calls setAutoHandwritingEnabled with true, the focus will not change.
If we attempt to execute Handwriting at this point, it will not
succeed because the View already has focus and the focus request will
not change, thus preventing the initiation of Handwriting. Ideally, we
should notify the HandwritingInitiator of the focus information again
when setAutoHandwritingEnabled is called. However, we currently allow
developers to override the isAutoHandwritingEnabled method, which
makes it difficult to monitor changes to this value.

Here, we attempt to modify focusedView to record the view that actually
has the current focus, even if isAutoHandwritingEnabled still returns
false. When searching for the best candidate View, we will then check
the value of isAutoHandwritingEnabled and make corresponding decisions
to fix this issue.

Bug: 361256391
Test: atest StylusHandwritingTest
Flag: com.android.text.flags.handwriting_track_disabled

Signed-off-by: default avatarLinnan Li <lilinnan@xiaomi.corp-partner.google.com>
(cherry picked from https://partner-android-review.googlesource.com/q/commit:417d6317b06c3fbe9959f05984318b1ad01c117a)
Merged-In: I82ff9936ce8dc51a997d4e73e772e3eced300475
Change-Id: I82ff9936ce8dc51a997d4e73e772e3eced300475
parent ac2b4f52
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -209,3 +209,13 @@ flag {
  description: "Decouple variation settings, weight and style information from Typeface class"
  bug: "361260253"
}

flag {
  name: "handwriting_track_disabled"
  namespace: "text"
  description: "Handwriting initiator tracks focused view even if handwriting is disabled to fix initiation bug."
  bug: "361256391"
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}
+9 −5
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.view;

import static com.android.text.flags.Flags.handwritingCursorPosition;
import static com.android.text.flags.Flags.handwritingTrackDisabled;
import static com.android.text.flags.Flags.handwritingUnsupportedMessage;

import android.annotation.FlaggedApi;
@@ -352,7 +353,7 @@ public class HandwritingInitiator {

        final View focusedView = getFocusedView();

        if (!view.isAutoHandwritingEnabled()) {
        if (!handwritingTrackDisabled() && !view.isAutoHandwritingEnabled()) {
            clearFocusedView(focusedView);
            return;
        }
@@ -363,7 +364,8 @@ public class HandwritingInitiator {
        updateFocusedView(view);

        if (mState != null && mState.mPendingFocusedView != null
                && mState.mPendingFocusedView.get() == view) {
                && mState.mPendingFocusedView.get() == view
                && (!handwritingTrackDisabled() || view.isAutoHandwritingEnabled())) {
            startHandwriting(view);
        }
    }
@@ -416,7 +418,7 @@ public class HandwritingInitiator {
     */
    @VisibleForTesting
    public boolean updateFocusedView(@NonNull View view) {
        if (!view.shouldInitiateHandwriting()) {
        if (!handwritingTrackDisabled() && !view.shouldInitiateHandwriting()) {
            mFocusedView = null;
            return false;
        }
@@ -424,9 +426,11 @@ public class HandwritingInitiator {
        final View focusedView = getFocusedView();
        if (focusedView != view) {
            mFocusedView = new WeakReference<>(view);
            if (!handwritingTrackDisabled() || view.shouldInitiateHandwriting()) {
                // A new view just gain focus. By default, we should show hover icon for it.
                mShowHoverIconForConnectedView = true;
            }
        }

        return true;
    }