summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Justin Ghan <justinghan@google.com> 2024-05-11 02:34:35 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-05-11 02:34:35 +0000
commit83d510126109c65ba60b1310feca80cb0573c4f2 (patch)
treea68f585ec1bf67a4801b2a147192c3a3d5bba2d2
parent0022a4a95aab2053eafa03f58e9934706414e5d8 (diff)
parent7dfa2fce2daf70dc805f987523df58bb749bd377 (diff)
Merge "TextView compatibility with EditorInfoCompat#isStylusHandwritingEnabled" into main
-rw-r--r--core/java/android/view/inputmethod/EditorInfo.java14
-rw-r--r--core/java/android/widget/TextView.java20
2 files changed, 31 insertions, 3 deletions
diff --git a/core/java/android/view/inputmethod/EditorInfo.java b/core/java/android/view/inputmethod/EditorInfo.java
index c5114b9550db..fb3e0831fdc9 100644
--- a/core/java/android/view/inputmethod/EditorInfo.java
+++ b/core/java/android/view/inputmethod/EditorInfo.java
@@ -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.
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index fb1c331171a6..78dd3b18c2a6 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -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);