From 92c48e3e03c9947342fa3af31be2090f7346c95c Mon Sep 17 00:00:00 2001 From: Justin Ghan Date: Fri, 14 Oct 2022 11:07:17 -0700 Subject: [PATCH] Suppress scrolling when handwriting initiator requests focus When stylus handwriting is started on an unfocused view which is partially scrolled off screen, the handwriting initiator will request focus on the view, which can cause the scroll position to jump to move the view to the visible area. This is particularly problematic if performing a rich gesture (such as circling to select some text), since the position of the gesture relative to the view is important. View#setRevealOnFocusHint is used to suppress the scroll. This setting is currently respected by ScrollView and HorizontalScrollView. Bug: 250920261 Test: Manually tested Change-Id: I0da67f48876ab52e92a463992e8075c983e71819 --- core/java/android/view/HandwritingInitiator.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/java/android/view/HandwritingInitiator.java b/core/java/android/view/HandwritingInitiator.java index a1ece9298e7fa..a0a07b30662f5 100644 --- a/core/java/android/view/HandwritingInitiator.java +++ b/core/java/android/view/HandwritingInitiator.java @@ -162,7 +162,13 @@ public class HandwritingInitiator { if (candidateView == getConnectedView()) { startHandwriting(candidateView); } else { - candidateView.requestFocus(); + if (candidateView.getRevealOnFocusHint()) { + candidateView.setRevealOnFocusHint(false); + candidateView.requestFocus(); + candidateView.setRevealOnFocusHint(true); + } else { + candidateView.requestFocus(); + } } } }