Make sure view has focus before starting handwriting
It is possible for a view to have an active input connection without having focus. If stylus movement occurs on a view in this state, the view should be focused before starting handwriting. Bug: 272522428 Test: atest android.view.stylus.HandwritingInitiatorTest Change-Id: I1bf9ed46a747ccf42c7d1ca6ff271e7e4a20415f
This commit is contained in:
@@ -170,6 +170,9 @@ public class HandwritingInitiator {
|
||||
findBestCandidateView(mState.mStylusDownX, mState.mStylusDownY);
|
||||
if (candidateView != null) {
|
||||
if (candidateView == getConnectedView()) {
|
||||
if (!candidateView.hasFocus()) {
|
||||
requestFocusWithoutReveal(candidateView);
|
||||
}
|
||||
startHandwriting(candidateView);
|
||||
} else if (candidateView.getHandwritingDelegatorCallback() != null) {
|
||||
String delegatePackageName =
|
||||
@@ -181,13 +184,7 @@ public class HandwritingInitiator {
|
||||
candidateView, delegatePackageName);
|
||||
candidateView.getHandwritingDelegatorCallback().run();
|
||||
} else {
|
||||
if (candidateView.getRevealOnFocusHint()) {
|
||||
candidateView.setRevealOnFocusHint(false);
|
||||
candidateView.requestFocus();
|
||||
candidateView.setRevealOnFocusHint(true);
|
||||
} else {
|
||||
candidateView.requestFocus();
|
||||
}
|
||||
requestFocusWithoutReveal(candidateView);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -380,6 +377,16 @@ public class HandwritingInitiator {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void requestFocusWithoutReveal(View view) {
|
||||
if (view.getRevealOnFocusHint()) {
|
||||
view.setRevealOnFocusHint(false);
|
||||
view.requestFocus();
|
||||
view.setRevealOnFocusHint(true);
|
||||
} else {
|
||||
view.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given the location of the stylus event, return the best candidate view to initialize
|
||||
* handwriting mode.
|
||||
|
||||
@@ -336,6 +336,27 @@ public class HandwritingInitiatorTest {
|
||||
verify(mTestView1, times(1)).requestFocus();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onTouchEvent_focusView_inputConnectionAlreadyBuilt_stylusMoveOnce_withinHWArea() {
|
||||
mHandwritingInitiator.onInputConnectionCreated(mTestView1);
|
||||
|
||||
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);
|
||||
|
||||
// View has input connection but not focus, so HandwritingInitiator will request focus
|
||||
// before starting handwriting.
|
||||
verify(mTestView1).requestFocus();
|
||||
verify(mHandwritingInitiator).startHandwriting(mTestView1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onTouchEvent_focusView_stylusMoveOnce_withinExtendedHWArea() {
|
||||
final int x1 = sHwArea1.left - HW_BOUNDS_OFFSETS_LEFT_PX / 2;
|
||||
|
||||
Reference in New Issue
Block a user