diff options
| author | 2024-02-28 10:12:40 -0800 | |
|---|---|---|
| committer | 2024-02-28 18:18:17 +0000 | |
| commit | b51f07d796e5a026b0516e40509d212260a14902 (patch) | |
| tree | 274d83843769d5eb728020fe0224d606669841f6 | |
| parent | 4055e248101dc1def4322b10229e1e399a174ee5 (diff) | |
Improve HandwritingInitiator handling of disabled views
Disabled views should still be tracked and considered for the purpose of
finding the best candidate view. However if the best candidate view is
disabled, then the handwriting initiator shouldn't take any further
action. Before this change, the handwriting initiator would try to
request focus which would fail, or try to start handwriting which would
fail.
Test: atest HandwritingInitiatorTest
Change-Id: I69a66dcf702bed54714bb09314fad8700ec510f2
| -rw-r--r-- | core/java/android/view/HandwritingInitiator.java | 2 | ||||
| -rw-r--r-- | core/tests/coretests/src/android/view/stylus/HandwritingInitiatorTest.java | 20 |
2 files changed, 21 insertions, 1 deletions
diff --git a/core/java/android/view/HandwritingInitiator.java b/core/java/android/view/HandwritingInitiator.java index f40f3c41e1e9..66655fca8fc3 100644 --- a/core/java/android/view/HandwritingInitiator.java +++ b/core/java/android/view/HandwritingInitiator.java @@ -220,7 +220,7 @@ public class HandwritingInitiator { mState.mExceedHandwritingSlop = true; View candidateView = findBestCandidateView(mState.mStylusDownX, mState.mStylusDownY, /* isHover */ false); - if (candidateView != null) { + if (candidateView != null && candidateView.isEnabled()) { if (candidateView == getConnectedOrFocusedView()) { if (!mInitiateWithoutConnection && !candidateView.hasFocus()) { requestFocusWithoutReveal(candidateView); diff --git a/core/tests/coretests/src/android/view/stylus/HandwritingInitiatorTest.java b/core/tests/coretests/src/android/view/stylus/HandwritingInitiatorTest.java index 51eb41c5a271..b60b806f3444 100644 --- a/core/tests/coretests/src/android/view/stylus/HandwritingInitiatorTest.java +++ b/core/tests/coretests/src/android/view/stylus/HandwritingInitiatorTest.java @@ -472,6 +472,26 @@ public class HandwritingInitiatorTest { } @Test + public void onTouchEvent_doesNothing_viewDisabled() { + mTestView1.setEnabled(false); + + final int x1 = (sHwArea1.left + sHwArea1.right) / 2; + final int y1 = (sHwArea1.top + sHwArea1.bottom) / 2; + MotionEvent stylusEvent1 = createStylusEvent(ACTION_DOWN, x1, y1, 0); + mHandwritingInitiator.onTouchEvent(stylusEvent1); + + final int x2 = x1 + mHandwritingSlop * 2; + final int y2 = y1; + + MotionEvent stylusEvent2 = createStylusEvent(ACTION_MOVE, x2, y2, 0); + mHandwritingInitiator.onTouchEvent(stylusEvent2); + + // HandwritingInitiator will not request focus if it is disabled. + verify(mTestView1, never()).requestFocus(); + verify(mHandwritingInitiator, never()).startHandwriting(mTestView1); + } + + @Test public void onTouchEvent_focusView_inputConnectionAlreadyBuilt_stylusMoveOnce_withinHWArea() { if (!mInitiateWithoutConnection) { mHandwritingInitiator.onInputConnectionCreated(mTestView1); |