am b2c4c730: Add debug facilities for gesture

* commit 'b2c4c73064943577496e3177413a0550d67e553f':
  Add debug facilities for gesture
main
Satoshi Kataoka 2013-05-09 03:22:44 -07:00 committed by Android Git Automerger
commit 7f9b3e6286
2 changed files with 29 additions and 2 deletions

View File

@ -18,6 +18,7 @@ package com.android.inputmethod.keyboard.internal;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Path; import android.graphics.Path;
import android.graphics.Rect; import android.graphics.Rect;
@ -35,12 +36,19 @@ import com.android.inputmethod.latin.ResizableIntArray;
* @attr ref R.styleable#MainKeyboardView_gesturePreviewTrailWidth * @attr ref R.styleable#MainKeyboardView_gesturePreviewTrailWidth
*/ */
final class GesturePreviewTrail { final class GesturePreviewTrail {
public static final boolean DBG_SHOW_POINTS = false;
public static final int POINT_TYPE_SAMPLED = 0;
public static final int POINT_TYPE_INTERPOLATED = 1;
public static final int POINT_TYPE_COMPROMISED = 2;
private static final int DEFAULT_CAPACITY = GestureStrokeWithPreviewPoints.PREVIEW_CAPACITY; private static final int DEFAULT_CAPACITY = GestureStrokeWithPreviewPoints.PREVIEW_CAPACITY;
// These three {@link ResizableIntArray}s should be synchronized by {@link #mEventTimes}. // These three {@link ResizableIntArray}s should be synchronized by {@link #mEventTimes}.
private final ResizableIntArray mXCoordinates = new ResizableIntArray(DEFAULT_CAPACITY); private final ResizableIntArray mXCoordinates = new ResizableIntArray(DEFAULT_CAPACITY);
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 final ResizableIntArray mPointTypes = new ResizableIntArray(
DBG_SHOW_POINTS ? DEFAULT_CAPACITY : 0);
private int mCurrentStrokeId = -1; private int mCurrentStrokeId = -1;
// The wall time of the zero value in {@link #mEventTimes} // The wall time of the zero value in {@link #mEventTimes}
private long mCurrentTimeBase; private long mCurrentTimeBase;
@ -125,7 +133,7 @@ final class GesturePreviewTrail {
final int lastInterpolatedIndex = (strokeId == mCurrentStrokeId) final int lastInterpolatedIndex = (strokeId == mCurrentStrokeId)
? mLastInterpolatedDrawIndex : trailSize; ? mLastInterpolatedDrawIndex : trailSize;
mLastInterpolatedDrawIndex = stroke.interpolateStrokeAndReturnStartIndexOfLastSegment( mLastInterpolatedDrawIndex = stroke.interpolateStrokeAndReturnStartIndexOfLastSegment(
lastInterpolatedIndex, mEventTimes, mXCoordinates, mYCoordinates); lastInterpolatedIndex, mEventTimes, mXCoordinates, mYCoordinates, mPointTypes);
if (strokeId != mCurrentStrokeId) { if (strokeId != mCurrentStrokeId) {
final int elapsedTime = (int)(downTime - mCurrentTimeBase); final int elapsedTime = (int)(downTime - mCurrentTimeBase);
for (int i = mTrailStartIndex; i < trailSize; i++) { for (int i = mTrailStartIndex; i < trailSize; i++) {
@ -204,6 +212,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[] pointTypes = mPointTypes.getPrimitiveArray();
final int sinceDown = (int)(SystemClock.uptimeMillis() - mCurrentTimeBase); final int sinceDown = (int)(SystemClock.uptimeMillis() - mCurrentTimeBase);
int startIndex; int startIndex;
for (startIndex = mTrailStartIndex; startIndex < trailSize; startIndex++) { for (startIndex = mTrailStartIndex; startIndex < trailSize; startIndex++) {
@ -246,6 +255,17 @@ final class GesturePreviewTrail {
final int alpha = getAlpha(elapsedTime, params); final int alpha = getAlpha(elapsedTime, params);
paint.setAlpha(alpha); paint.setAlpha(alpha);
canvas.drawPath(path, paint); canvas.drawPath(path, paint);
if (DBG_SHOW_POINTS) {
if (pointTypes[i] == POINT_TYPE_INTERPOLATED) {
paint.setColor(Color.RED);
} else if (pointTypes[i] == POINT_TYPE_SAMPLED) {
paint.setColor(Color.BLUE);
} else {
paint.setColor(Color.GREEN);
}
canvas.drawCircle(p1x - 1, p1y - 1, 2, paint);
paint.setColor(params.mTrailColor);
}
} }
} }
p1x = p2x; p1x = p2x;
@ -265,6 +285,7 @@ final class GesturePreviewTrail {
mEventTimes.setLength(newSize); mEventTimes.setLength(newSize);
mXCoordinates.setLength(newSize); mXCoordinates.setLength(newSize);
mYCoordinates.setLength(newSize); mYCoordinates.setLength(newSize);
mPointTypes.setLength(newSize);
// The start index of the last segment of the stroke // The start index of the last segment of the stroke
// {@link mLastInterpolatedDrawIndex} should also be updated because all array // {@link mLastInterpolatedDrawIndex} should also be updated because all array
// elements have just been shifted for compaction or been zeroed. // elements have just been shifted for compaction or been zeroed.

View File

@ -152,7 +152,7 @@ public final class GestureStrokeWithPreviewPoints extends GestureStroke {
*/ */
public int interpolateStrokeAndReturnStartIndexOfLastSegment(final int lastInterpolatedIndex, public int interpolateStrokeAndReturnStartIndexOfLastSegment(final int lastInterpolatedIndex,
final ResizableIntArray eventTimes, final ResizableIntArray xCoords, final ResizableIntArray eventTimes, final ResizableIntArray xCoords,
final ResizableIntArray yCoords) { final ResizableIntArray yCoords, final ResizableIntArray types) {
final int size = mPreviewEventTimes.getLength(); final int size = mPreviewEventTimes.getLength();
final int[] pt = mPreviewEventTimes.getPrimitiveArray(); final int[] pt = mPreviewEventTimes.getPrimitiveArray();
final int[] px = mPreviewXCoordinates.getPrimitiveArray(); final int[] px = mPreviewXCoordinates.getPrimitiveArray();
@ -189,11 +189,17 @@ public final class GestureStrokeWithPreviewPoints extends GestureStroke {
eventTimes.add(d1, (int)(dt * t) + t1); eventTimes.add(d1, (int)(dt * t) + t1);
xCoords.add(d1, (int)mInterpolator.mInterpolatedX); xCoords.add(d1, (int)mInterpolator.mInterpolatedX);
yCoords.add(d1, (int)mInterpolator.mInterpolatedY); yCoords.add(d1, (int)mInterpolator.mInterpolatedY);
if (GesturePreviewTrail.DBG_SHOW_POINTS) {
types.add(d1, GesturePreviewTrail.POINT_TYPE_INTERPOLATED);
}
d1++; d1++;
} }
eventTimes.add(d1, pt[p2]); eventTimes.add(d1, pt[p2]);
xCoords.add(d1, px[p2]); xCoords.add(d1, px[p2]);
yCoords.add(d1, py[p2]); yCoords.add(d1, py[p2]);
if (GesturePreviewTrail.DBG_SHOW_POINTS) {
types.add(d1, GesturePreviewTrail.POINT_TYPE_SAMPLED);
}
} }
return lastInterpolatedDrawIndex; return lastInterpolatedDrawIndex;
} }