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

Commit 83d51012 authored by Justin Ghan's avatar Justin Ghan Committed by Android (Google) Code Review
Browse files

Merge "TextView compatibility with EditorInfoCompat#isStylusHandwritingEnabled" into main

parents 0022a4a9 7dfa2fce
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -720,6 +720,20 @@ public class EditorInfo implements InputType, Parcelable {

    private boolean mIsStylusHandwritingEnabled;


    /**
     * AndroidX Core library 1.13.0 introduced EditorInfoCompat#setStylusHandwritingEnabled and
     * EditorInfoCompat#isStylusHandwritingEnabled which used a boolean value in the EditorInfo
     * extras bundle. These methods do not set or check the Android V property since the Android V
     * SDK was not yet available. In order for EditorInfoCompat#isStylusHandwritingEnabled to return
     * the correct value for EditorInfo created by Android V TextView, the extras bundle value
     * should be set. This is the extras bundle key.
     *
     * @hide
     */
    public static final String STYLUS_HANDWRITING_ENABLED_ANDROIDX_EXTRAS_KEY =
            "androidx.core.view.inputmethod.EditorInfoCompat.STYLUS_HANDWRITING_ENABLED";

    /**
     * Set {@code true} if the {@code Editor} has
     * {@link InputMethodManager#startStylusHandwriting stylus handwriting} enabled.
+17 −3
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import static android.view.accessibility.AccessibilityNodeInfo.EXTRA_DATA_TEXT_C
import static android.view.accessibility.AccessibilityNodeInfo.EXTRA_DATA_TEXT_CHARACTER_LOCATION_ARG_START_INDEX;
import static android.view.accessibility.AccessibilityNodeInfo.EXTRA_DATA_TEXT_CHARACTER_LOCATION_KEY;
import static android.view.inputmethod.CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION;
import static android.view.inputmethod.EditorInfo.STYLUS_HANDWRITING_ENABLED_ANDROIDX_EXTRAS_KEY;
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;
@@ -10062,9 +10063,22 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                outAttrs.initialCapsMode = ic.getCursorCapsMode(getInputType());
                outAttrs.setInitialSurroundingText(mText);
                outAttrs.contentMimeTypes = getReceiveContentMimeTypes();
                if (android.view.inputmethod.Flags.editorinfoHandwritingEnabled()
                        && isAutoHandwritingEnabled()) {
                    outAttrs.setStylusHandwritingEnabled(true);
                if (android.view.inputmethod.Flags.editorinfoHandwritingEnabled()) {
                    boolean handwritingEnabled = isAutoHandwritingEnabled();
                    outAttrs.setStylusHandwritingEnabled(handwritingEnabled);
                    // AndroidX Core library 1.13.0 introduced
                    // EditorInfoCompat#setStylusHandwritingEnabled and
                    // EditorInfoCompat#isStylusHandwritingEnabled which used a boolean value in the
                    // EditorInfo extras bundle. These methods do not set or check the Android V
                    // property since the Android V SDK was not yet available. In order for
                    // EditorInfoCompat#isStylusHandwritingEnabled to return the correct value for
                    // EditorInfo created by Android V TextView, the extras bundle value is also set
                    // here.
                    if (outAttrs.extras == null) {
                        outAttrs.extras = new Bundle();
                    }
                    outAttrs.extras.putBoolean(
                            STYLUS_HANDWRITING_ENABLED_ANDROIDX_EXTRAS_KEY, handwritingEnabled);
                }
                ArrayList<Class<? extends HandwritingGesture>> gestures = new ArrayList<>();
                gestures.add(SelectGesture.class);