Merge "Fix bimanual gesture preview trail" into jb-mr1-dev

main
Tadashi G. Takaoka 2012-09-07 03:04:47 -07:00 committed by Android (Google) Code Review
commit b922da847c
3 changed files with 20 additions and 22 deletions

View File

@ -573,6 +573,7 @@ public class PointerTracker implements PointerTrackerQueue.Element {
private void endBatchInput() { private void endBatchInput() {
synchronized (sAggregratedPointers) { synchronized (sAggregratedPointers) {
mGestureStrokeWithPreviewTrail.appendAllBatchPoints(sAggregratedPointers); mGestureStrokeWithPreviewTrail.appendAllBatchPoints(sAggregratedPointers);
mGestureStrokeWithPreviewTrail.reset();
if (getActivePointerTrackerCount() == 1) { if (getActivePointerTrackerCount() == 1) {
if (DEBUG_LISTENER) { if (DEBUG_LISTENER) {
Log.d(TAG, "onEndBatchInput: batchPoints=" Log.d(TAG, "onEndBatchInput: batchPoints="

View File

@ -33,15 +33,10 @@ final class GesturePreviewTrail {
private final ResizableIntArray mYCoordinates = new ResizableIntArray(DEFAULT_CAPACITY); private final ResizableIntArray mYCoordinates = new ResizableIntArray(DEFAULT_CAPACITY);
private final ResizableIntArray mEventTimes = new ResizableIntArray(DEFAULT_CAPACITY); private final ResizableIntArray mEventTimes = new ResizableIntArray(DEFAULT_CAPACITY);
private int mCurrentStrokeId = -1; private int mCurrentStrokeId = -1;
private long mCurrentDownTime; // The wall time of the zero value in {@link #mEventTimes}
private long mCurrentTimeBase;
private int mTrailStartIndex; 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 { static final class Params {
public final int mTrailColor; public final int mTrailColor;
public final float mTrailStartWidth; 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) { private static int markAsDownEvent(final int xCoord) {
return DOWN_EVENT_MARKER - xCoord; return DOWN_EVENT_MARKER - xCoord;
} }
@ -83,26 +81,23 @@ final class GesturePreviewTrail {
} }
public void addStroke(final GestureStrokeWithPreviewTrail stroke, final long downTime) { public void addStroke(final GestureStrokeWithPreviewTrail stroke, final long downTime) {
final int strokeId = stroke.getGestureStrokeId();
final boolean isNewStroke = strokeId != mCurrentStrokeId;
final int trailSize = mEventTimes.getLength(); final int trailSize = mEventTimes.getLength();
stroke.appendPreviewStroke(mEventTimes, mXCoordinates, mYCoordinates); stroke.appendPreviewStroke(mEventTimes, mXCoordinates, mYCoordinates);
final int newTrailSize = mEventTimes.getLength(); if (mEventTimes.getLength() == trailSize) {
if (stroke.getGestureStrokePreviewSize() == 0) {
return; 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++) { for (int i = mTrailStartIndex; i < trailSize; i++) {
// Decay the previous strokes' event times.
eventTimes[i] -= elapsedTime; eventTimes[i] -= elapsedTime;
} }
if (newTrailSize > trailSize) {
final int[] xCoords = mXCoordinates.getPrimitiveArray(); final int[] xCoords = mXCoordinates.getPrimitiveArray();
xCoords[trailSize] = markAsDownEvent(xCoords[trailSize]); final int downIndex = trailSize;
} xCoords[downIndex] = markAsDownEvent(xCoords[downIndex]);
mCurrentDownTime = downTime; mCurrentTimeBase = downTime - eventTimes[downIndex];
mCurrentStrokeId = strokeId; mCurrentStrokeId = strokeId;
} }
} }
@ -123,6 +118,9 @@ final class GesturePreviewTrail {
/ params.mTrailLingerDuration, 0.0f); / params.mTrailLingerDuration, 0.0f);
} }
private final static Xfermode PORTER_DUFF_MODE_SRC =
new PorterDuffXfermode(PorterDuff.Mode.SRC);
/** /**
* Draw gesture preview trail * Draw gesture preview trail
* @param canvas The canvas to draw the 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[] eventTimes = mEventTimes.getPrimitiveArray();
final int[] xCoords = mXCoordinates.getPrimitiveArray(); final int[] xCoords = mXCoordinates.getPrimitiveArray();
final int[] yCoords = mYCoordinates.getPrimitiveArray(); final int[] yCoords = mYCoordinates.getPrimitiveArray();
final int sinceDown = (int)(SystemClock.uptimeMillis() - mCurrentDownTime); final int sinceDown = (int)(SystemClock.uptimeMillis() - mCurrentTimeBase);
int startIndex; int startIndex;
for (startIndex = mTrailStartIndex; startIndex < trailSize; startIndex++) { for (startIndex = mTrailStartIndex; startIndex < trailSize; startIndex++) {
final int elapsedTime = sinceDown - eventTimes[startIndex]; final int elapsedTime = sinceDown - eventTimes[startIndex];

View File

@ -158,7 +158,6 @@ public class PreviewPlacerView extends RelativeLayout {
final Paint textPaint = new Paint(); final Paint textPaint = new Paint();
textPaint.setAntiAlias(true); textPaint.setAntiAlias(true);
textPaint.setStyle(Paint.Style.FILL);
textPaint.setTextAlign(Align.CENTER); textPaint.setTextAlign(Align.CENTER);
textPaint.setTextSize(gestureFloatingPreviewTextSize); textPaint.setTextSize(gestureFloatingPreviewTextSize);
mTextPaint = textPaint; mTextPaint = textPaint;