diff options
author | 2022-09-29 23:25:45 +0000 | |
---|---|---|
committer | 2022-09-29 23:34:12 +0000 | |
commit | def9417110eda3c8f49a0f202a575b497d5bb8c4 (patch) | |
tree | aad0b33af88ffef31fc5fe908b0fda4e5dd066cc | |
parent | 677d18848ecbfe6301ab1661de695ac3737fa14d (diff) |
Update HandwritingIme with sanitized RectF(s)
Sanitize RectF so selection and deletion rich gestures always work i.e.
right to left and bottom to top
Bug: 236765468
Test: Manually build and install
Change-Id: I03e170773c9687aa2322f9e50ef7cc2bd92493ec
-rw-r--r-- | tests/HandwritingIme/src/com/google/android/test/handwritingime/HandwritingIme.java | 56 |
1 files changed, 42 insertions, 14 deletions
diff --git a/tests/HandwritingIme/src/com/google/android/test/handwritingime/HandwritingIme.java b/tests/HandwritingIme/src/com/google/android/test/handwritingime/HandwritingIme.java index 39fe84bb8d4c..2fd236895467 100644 --- a/tests/HandwritingIme/src/com/google/android/test/handwritingime/HandwritingIme.java +++ b/tests/HandwritingIme/src/com/google/android/test/handwritingime/HandwritingIme.java @@ -96,11 +96,11 @@ public class HandwritingIme extends InputMethodService { case MotionEvent.ACTION_UP: { if (areRichGesturesEnabled()) { HandwritingGesture gesture = null; - switch(mRichGestureMode) { + switch (mRichGestureMode) { case OP_SELECT: gesture = new SelectGesture.Builder() .setGranularity(mRichGestureGranularity) - .setSelectionArea(new RectF(mRichGestureStartPoint.x, + .setSelectionArea(getSanitizedRectF(mRichGestureStartPoint.x, mRichGestureStartPoint.y, event.getX(), event.getY())) .setFallbackText("fallback text") .build(); @@ -108,7 +108,7 @@ public class HandwritingIme extends InputMethodService { case OP_DELETE: gesture = new DeleteGesture.Builder() .setGranularity(mRichGestureGranularity) - .setDeletionArea(new RectF(mRichGestureStartPoint.x, + .setDeletionArea(getSanitizedRectF(mRichGestureStartPoint.x, mRichGestureStartPoint.y, event.getX(), event.getY())) .setFallbackText("fallback text") .build(); @@ -143,17 +143,7 @@ public class HandwritingIme extends InputMethodService { Log.e(TAG, "Unrecognized gesture mode: " + mRichGestureMode); return; } - InputConnection ic = getCurrentInputConnection(); - if (getCurrentInputStarted() && ic != null) { - ic.performHandwritingGesture(gesture, Runnable::run, mResultConsumer); - } else { - // This shouldn't happen - Log.e(TAG, "No active InputConnection"); - } - - Log.d(TAG, "Sending RichGesture " + mRichGestureMode + " (Screen) Left: " - + mRichGestureStartPoint.x + ", Top: " + mRichGestureStartPoint.y - + ", Right: " + event.getX() + ", Bottom: " + event.getY()); + performGesture(gesture); } else { // insert random ASCII char sendKeyChar((char) (56 + new Random().nextInt(66))); @@ -169,6 +159,44 @@ public class HandwritingIme extends InputMethodService { } } + /** + * sanitize values to support rectangles in all cases. + */ + private RectF getSanitizedRectF(float left, float top, float right, float bottom) { + // swap values when left > right OR top > bottom. + if (left > right) { + float temp = left; + left = right; + right = temp; + } + if (top > bottom) { + float temp = top; + top = bottom; + bottom = temp; + } + // increment by a pixel so that RectF.isEmpty() isn't true. + if (left == right) { + right++; + } + if (top == bottom) { + bottom++; + } + + RectF rectF = new RectF(left, top, right, bottom); + Log.d(TAG, "Sending RichGesture " + rectF.toShortString()); + return rectF; + } + + private void performGesture(HandwritingGesture gesture) { + InputConnection ic = getCurrentInputConnection(); + if (getCurrentInputStarted() && ic != null) { + ic.performHandwritingGesture(gesture, Runnable::run, mResultConsumer); + } else { + // This shouldn't happen + Log.e(TAG, "No active InputConnection"); + } + } + @Override public View onCreateInputView() { Log.d(TAG, "onCreateInputView"); |