diff options
| author | 2022-09-30 19:15:30 +0000 | |
|---|---|---|
| committer | 2022-09-30 19:15:30 +0000 | |
| commit | 87f075c6c3bffc27c7d419fe932364ddc1f5af57 (patch) | |
| tree | 0fd7434da89aa3657d96a15335f3ac771b4c8dc7 | |
| parent | 9d626793811759fdbd08ee921a1cb9ca16f053b7 (diff) | |
| parent | def9417110eda3c8f49a0f202a575b497d5bb8c4 (diff) | |
Merge "Update HandwritingIme with sanitized RectF(s)"
| -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"); |