From f117f77766689219c3a32dafb8b7446bdf4e4ebc Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Fri, 7 Sep 2012 13:25:34 +0900 Subject: [PATCH] Fix bimanual gesture preview trail Bug: 7122288 Change-Id: I9f0aabe08628880a8439bfda98844ae60206b8de --- .../inputmethod/keyboard/PointerTracker.java | 1 + .../internal/GesturePreviewTrail.java | 40 +++++++++---------- .../keyboard/internal/PreviewPlacerView.java | 1 - 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java index 5a79d508f..4887ac557 100644 --- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java +++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java @@ -573,6 +573,7 @@ public class PointerTracker implements PointerTrackerQueue.Element { private void endBatchInput() { synchronized (sAggregratedPointers) { mGestureStrokeWithPreviewTrail.appendAllBatchPoints(sAggregratedPointers); + mGestureStrokeWithPreviewTrail.reset(); if (getActivePointerTrackerCount() == 1) { if (DEBUG_LISTENER) { Log.d(TAG, "onEndBatchInput: batchPoints=" diff --git a/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java b/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java index 7442b7fad..95c9572b3 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java +++ b/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java @@ -33,15 +33,10 @@ final class GesturePreviewTrail { private final ResizableIntArray mYCoordinates = new ResizableIntArray(DEFAULT_CAPACITY); private final ResizableIntArray mEventTimes = new ResizableIntArray(DEFAULT_CAPACITY); private int mCurrentStrokeId = -1; - private long mCurrentDownTime; + // The wall time of the zero value in {@link #mEventTimes} + private long mCurrentTimeBase; private int mTrailStartIndex; - private final static Xfermode PORTER_DUFF_MODE_SRC = - new PorterDuffXfermode(PorterDuff.Mode.SRC); - - // Use this value as imaginary zero because x-coordinates may be zero. - private static final int DOWN_EVENT_MARKER = -128; - static final class Params { public final int mTrailColor; public final float mTrailStartWidth; @@ -69,6 +64,9 @@ final class GesturePreviewTrail { } } + // Use this value as imaginary zero because x-coordinates may be zero. + private static final int DOWN_EVENT_MARKER = -128; + private static int markAsDownEvent(final int xCoord) { return DOWN_EVENT_MARKER - xCoord; } @@ -83,26 +81,23 @@ final class GesturePreviewTrail { } public void addStroke(final GestureStrokeWithPreviewTrail stroke, final long downTime) { - final int strokeId = stroke.getGestureStrokeId(); - final boolean isNewStroke = strokeId != mCurrentStrokeId; final int trailSize = mEventTimes.getLength(); stroke.appendPreviewStroke(mEventTimes, mXCoordinates, mYCoordinates); - final int newTrailSize = mEventTimes.getLength(); - if (stroke.getGestureStrokePreviewSize() == 0) { + if (mEventTimes.getLength() == trailSize) { return; } - if (isNewStroke) { - final int elapsedTime = (int)(downTime - mCurrentDownTime); - final int[] eventTimes = mEventTimes.getPrimitiveArray(); + final int[] eventTimes = mEventTimes.getPrimitiveArray(); + final int strokeId = stroke.getGestureStrokeId(); + if (strokeId != mCurrentStrokeId) { + final int elapsedTime = (int)(downTime - mCurrentTimeBase); for (int i = mTrailStartIndex; i < trailSize; i++) { + // Decay the previous strokes' event times. eventTimes[i] -= elapsedTime; } - - if (newTrailSize > trailSize) { - final int[] xCoords = mXCoordinates.getPrimitiveArray(); - xCoords[trailSize] = markAsDownEvent(xCoords[trailSize]); - } - mCurrentDownTime = downTime; + final int[] xCoords = mXCoordinates.getPrimitiveArray(); + final int downIndex = trailSize; + xCoords[downIndex] = markAsDownEvent(xCoords[downIndex]); + mCurrentTimeBase = downTime - eventTimes[downIndex]; mCurrentStrokeId = strokeId; } } @@ -123,6 +118,9 @@ final class GesturePreviewTrail { / params.mTrailLingerDuration, 0.0f); } + private final static Xfermode PORTER_DUFF_MODE_SRC = + new PorterDuffXfermode(PorterDuff.Mode.SRC); + /** * Draw gesture preview trail * @param canvas The canvas to draw the gesture preview trail @@ -139,7 +137,7 @@ final class GesturePreviewTrail { final int[] eventTimes = mEventTimes.getPrimitiveArray(); final int[] xCoords = mXCoordinates.getPrimitiveArray(); final int[] yCoords = mYCoordinates.getPrimitiveArray(); - final int sinceDown = (int)(SystemClock.uptimeMillis() - mCurrentDownTime); + final int sinceDown = (int)(SystemClock.uptimeMillis() - mCurrentTimeBase); int startIndex; for (startIndex = mTrailStartIndex; startIndex < trailSize; startIndex++) { final int elapsedTime = sinceDown - eventTimes[startIndex]; diff --git a/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java b/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java index 8dde4d671..dbde4ef39 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java +++ b/java/src/com/android/inputmethod/keyboard/internal/PreviewPlacerView.java @@ -158,7 +158,6 @@ public class PreviewPlacerView extends RelativeLayout { final Paint textPaint = new Paint(); textPaint.setAntiAlias(true); - textPaint.setStyle(Paint.Style.FILL); textPaint.setTextAlign(Align.CENTER); textPaint.setTextSize(gestureFloatingPreviewTextSize); mTextPaint = textPaint;