diff options
| author | Haoyu Zhang <haoyuchang@google.com> | 2022-01-27 05:38:14 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2022-01-27 05:38:14 +0000 |
| commit | 2a96a54ce81f7d797cd7a62edeac370fc7145b2e (patch) | |
| tree | d806243e4d673bc1dfc42e6df5c67999579192cb /core/java/android/view/View.java | |
| parent | 1fcff333b911539a49dd81ee2f9ef9f581cef448 (diff) | |
| parent | bd346bad9e924ad31ec62278db10d6abc25679ac (diff) | |
Merge "Scribe in View: Introduce View#autoHandwritingEnabled"
Diffstat (limited to 'core/java/android/view/View.java')
| -rw-r--r-- | core/java/android/view/View.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index 93fdee07b58e..75592730067a 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -3517,6 +3517,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, * 1 PFLAG4_DETACHED * 1 PFLAG4_HAS_TRANSLATION_TRANSIENT_STATE * 1 PFLAG4_DRAG_A11Y_STARTED + * 1 PFLAG4_AUTO_HANDWRITING_INITIATION_ENABLED * |-------|-------|-------|-------| */ @@ -3593,6 +3594,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback, */ private static final int PFLAG4_DRAG_A11Y_STARTED = 0x000008000; + /** + * Indicates that the view enables auto handwriting initiation. + */ + private static final int PFLAG4_AUTO_HANDWRITING_ENABLED = 0x000010000; /* End of masks for mPrivateFlags4 */ /** @hide */ @@ -5321,6 +5326,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, (TEXT_ALIGNMENT_DEFAULT << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT) | (PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT) | (IMPORTANT_FOR_ACCESSIBILITY_DEFAULT << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT); + mPrivateFlags4 = PFLAG4_AUTO_HANDWRITING_ENABLED; final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = configuration.getScaledTouchSlop(); @@ -6034,6 +6040,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, case R.styleable.View_preferKeepClear: setPreferKeepClear(a.getBoolean(attr, false)); break; + case R.styleable.View_autoHandwritingEnabled: + setAutoHandwritingEnabled(a.getBoolean(attr, true)); + break; } } @@ -31118,6 +31127,42 @@ public class View implements Drawable.Callback, KeyEvent.Callback, } /** + * Set whether this view enables automatic handwriting initiation. + * + * For a view with an active {@link InputConnection}, if auto handwriting is enabled then + * stylus movement within its view boundary will automatically trigger the handwriting mode. + * Check {@link android.view.inputmethod.InputMethodManager#startStylusHandwriting(View)} for + * more details about handwriting mode. + * + * If the View wants to initiate handwriting mode by itself, it can set this field to + * {@code false} and call + * {@link android.view.inputmethod.InputMethodManager#startStylusHandwriting(View)} when there + * is stylus movement detected. + * + * @see #onCreateInputConnection(EditorInfo) + * @see android.view.inputmethod.InputMethodManager#startStylusHandwriting(View) + * @param enabled whether auto handwriting initiation is enabled for this view. + * @attr ref android.R.styleable#View_autoHandwritingEnabled + */ + public void setAutoHandwritingEnabled(boolean enabled) { + if (enabled) { + mPrivateFlags4 |= PFLAG4_AUTO_HANDWRITING_ENABLED; + } else { + mPrivateFlags4 &= ~PFLAG4_AUTO_HANDWRITING_ENABLED; + } + } + + /** + * Return whether the View allows automatic handwriting initiation. Returns true if automatic + * handwriting initiation is enabled, and verse visa. + * @see #setAutoHandwritingEnabled(boolean) + */ + public boolean isAutoHandwritingEnabled() { + return (mPrivateFlags4 & PFLAG4_AUTO_HANDWRITING_ENABLED) + == PFLAG4_AUTO_HANDWRITING_ENABLED; + } + + /** * Collects a {@link ViewTranslationRequest} which represents the content to be translated in * the view. * |
