Fix drawing debug points of gesture trails

Bug: 7167303
Change-Id: I9a75b1b9b9127c5364da49b2a04b22c16a7ad535
main
Tadashi G. Takaoka 2013-05-21 07:24:58 +09:00
parent ea88e2ffe8
commit 9764397274
2 changed files with 61 additions and 26 deletions

View File

@ -58,7 +58,7 @@ public final class GestureStrokeWithPreviewPoints extends GestureStroke {
} }
private static double degreeToRadian(final int degree) { private static double degreeToRadian(final int degree) {
return (double)degree / 180.0d * Math.PI; return degree / 180.0d * Math.PI;
} }
public GestureStrokePreviewParams(final TypedArray mainKeyboardViewAttr) { public GestureStrokePreviewParams(final TypedArray mainKeyboardViewAttr) {
@ -125,8 +125,18 @@ public final class GestureStrokeWithPreviewPoints extends GestureStroke {
} }
/**
* Append sampled preview points.
*
* @param eventTimes the event time array of gesture trail to be drawn.
* @param xCoords the x-coordinates array of gesture trail to be drawn.
* @param yCoords the y-coordinates array of gesture trail to be drawn.
* @param types the point types array of gesture trail. This is valid only when
* {@link GestureTrail#DEBUG_SHOW_POINTS} is true.
*/
public void appendPreviewStroke(final ResizableIntArray eventTimes, public void appendPreviewStroke(final ResizableIntArray eventTimes,
final ResizableIntArray xCoords, final ResizableIntArray yCoords) { final ResizableIntArray xCoords, final ResizableIntArray yCoords,
final ResizableIntArray types) {
final int length = mPreviewEventTimes.getLength() - mLastPreviewSize; final int length = mPreviewEventTimes.getLength() - mLastPreviewSize;
if (length <= 0) { if (length <= 0) {
return; return;
@ -134,6 +144,9 @@ public final class GestureStrokeWithPreviewPoints extends GestureStroke {
eventTimes.append(mPreviewEventTimes, mLastPreviewSize, length); eventTimes.append(mPreviewEventTimes, mLastPreviewSize, length);
xCoords.append(mPreviewXCoordinates, mLastPreviewSize, length); xCoords.append(mPreviewXCoordinates, mLastPreviewSize, length);
yCoords.append(mPreviewYCoordinates, mLastPreviewSize, length); yCoords.append(mPreviewYCoordinates, mLastPreviewSize, length);
if (GestureTrail.DEBUG_SHOW_POINTS) {
types.fill(GestureTrail.POINT_TYPE_SAMPLED, types.getLength(), length);
}
mLastPreviewSize = mPreviewEventTimes.getLength(); mLastPreviewSize = mPreviewEventTimes.getLength();
} }
@ -148,6 +161,8 @@ public final class GestureStrokeWithPreviewPoints extends GestureStroke {
* @param eventTimes the event time array of gesture trail to be drawn. * @param eventTimes the event time array of gesture trail to be drawn.
* @param xCoords the x-coordinates array of gesture trail to be drawn. * @param xCoords the x-coordinates array of gesture trail to be drawn.
* @param yCoords the y-coordinates array of gesture trail to be drawn. * @param yCoords the y-coordinates array of gesture trail to be drawn.
* @param types the point types array of gesture trail. This is valid only when
* {@link GestureTrail#DEBUG_SHOW_POINTS} is true.
* @return the start index of the last interpolated segment of input arrays. * @return the start index of the last interpolated segment of input arrays.
*/ */
public int interpolateStrokeAndReturnStartIndexOfLastSegment(final int lastInterpolatedIndex, public int interpolateStrokeAndReturnStartIndexOfLastSegment(final int lastInterpolatedIndex,
@ -189,7 +204,7 @@ 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 (GestureTrail.DBG_SHOW_POINTS) { if (GestureTrail.DEBUG_SHOW_POINTS) {
types.add(d1, GestureTrail.POINT_TYPE_INTERPOLATED); types.add(d1, GestureTrail.POINT_TYPE_INTERPOLATED);
} }
d1++; d1++;
@ -197,7 +212,7 @@ public final class GestureStrokeWithPreviewPoints extends GestureStroke {
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 (GestureTrail.DBG_SHOW_POINTS) { if (GestureTrail.DEBUG_SHOW_POINTS) {
types.add(d1, GestureTrail.POINT_TYPE_SAMPLED); types.add(d1, GestureTrail.POINT_TYPE_SAMPLED);
} }
} }

View File

@ -36,10 +36,11 @@ import com.android.inputmethod.latin.ResizableIntArray;
* @attr ref R.styleable#MainKeyboardView_gestureTrailWidth * @attr ref R.styleable#MainKeyboardView_gestureTrailWidth
*/ */
final class GestureTrail { final class GestureTrail {
public static final boolean DBG_SHOW_POINTS = false; public static final boolean DEBUG_SHOW_POINTS = false;
public static final int POINT_TYPE_SAMPLED = 0; public static final int POINT_TYPE_SAMPLED = 1;
public static final int POINT_TYPE_INTERPOLATED = 1; public static final int POINT_TYPE_INTERPOLATED = 2;
public static final int POINT_TYPE_COMPROMISED = 2; private static final int FADEOUT_START_DELAY_FOR_DEBUG = 2000; // millisecond
private static final int FADEOUT_DURATION_FOR_DEBUG = 200; // millisecond
private static final int DEFAULT_CAPACITY = GestureStrokeWithPreviewPoints.PREVIEW_CAPACITY; private static final int DEFAULT_CAPACITY = GestureStrokeWithPreviewPoints.PREVIEW_CAPACITY;
@ -48,7 +49,7 @@ final class GestureTrail {
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( private final ResizableIntArray mPointTypes = new ResizableIntArray(
DBG_SHOW_POINTS ? DEFAULT_CAPACITY : 0); DEBUG_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;
@ -83,10 +84,12 @@ final class GestureTrail {
R.styleable.MainKeyboardView_gestureTrailShadowRatio, 0); R.styleable.MainKeyboardView_gestureTrailShadowRatio, 0);
mTrailShadowEnabled = (trailShadowRatioInt > 0); mTrailShadowEnabled = (trailShadowRatioInt > 0);
mTrailShadowRatio = (float)trailShadowRatioInt / (float)PERCENTAGE_INT; mTrailShadowRatio = (float)trailShadowRatioInt / (float)PERCENTAGE_INT;
mFadeoutStartDelay = DBG_SHOW_POINTS ? 2000 : mainKeyboardViewAttr.getInt( mFadeoutStartDelay = DEBUG_SHOW_POINTS ? FADEOUT_START_DELAY_FOR_DEBUG
R.styleable.MainKeyboardView_gestureTrailFadeoutStartDelay, 0); : mainKeyboardViewAttr.getInt(
mFadeoutDuration = DBG_SHOW_POINTS ? 200 : mainKeyboardViewAttr.getInt( R.styleable.MainKeyboardView_gestureTrailFadeoutStartDelay, 0);
R.styleable.MainKeyboardView_gestureTrailFadeoutDuration, 0); mFadeoutDuration = DEBUG_SHOW_POINTS ? FADEOUT_DURATION_FOR_DEBUG
: mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_gestureTrailFadeoutDuration, 0);
mTrailLingerDuration = mFadeoutStartDelay + mFadeoutDuration; mTrailLingerDuration = mFadeoutStartDelay + mFadeoutDuration;
mUpdateInterval = mainKeyboardViewAttr.getInt( mUpdateInterval = mainKeyboardViewAttr.getInt(
R.styleable.MainKeyboardView_gestureTrailUpdateInterval, 0); R.styleable.MainKeyboardView_gestureTrailUpdateInterval, 0);
@ -117,7 +120,7 @@ final class GestureTrail {
private void addStrokeLocked(final GestureStrokeWithPreviewPoints stroke, final long downTime) { private void addStrokeLocked(final GestureStrokeWithPreviewPoints stroke, final long downTime) {
final int trailSize = mEventTimes.getLength(); final int trailSize = mEventTimes.getLength();
stroke.appendPreviewStroke(mEventTimes, mXCoordinates, mYCoordinates); stroke.appendPreviewStroke(mEventTimes, mXCoordinates, mYCoordinates, mPointTypes);
if (mEventTimes.getLength() == trailSize) { if (mEventTimes.getLength() == trailSize) {
return; return;
} }
@ -255,23 +258,15 @@ final class GestureTrail {
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(0xFFA000FF);
} else {
paint.setColor(Color.GREEN);
}
canvas.drawCircle(p1x - 1, p1y - 1, 2, paint);
paint.setColor(params.mTrailColor);
}
} }
} }
p1x = p2x; p1x = p2x;
p1y = p2y; p1y = p2y;
r1 = r2; r1 = r2;
} }
if (DEBUG_SHOW_POINTS) {
debugDrawPoints(canvas, startIndex, trailSize, paint);
}
} }
final int newSize = trailSize - startIndex; final int newSize = trailSize - startIndex;
@ -281,11 +276,14 @@ final class GestureTrail {
System.arraycopy(eventTimes, startIndex, eventTimes, 0, newSize); System.arraycopy(eventTimes, startIndex, eventTimes, 0, newSize);
System.arraycopy(xCoords, startIndex, xCoords, 0, newSize); System.arraycopy(xCoords, startIndex, xCoords, 0, newSize);
System.arraycopy(yCoords, startIndex, yCoords, 0, newSize); System.arraycopy(yCoords, startIndex, yCoords, 0, newSize);
if (DEBUG_SHOW_POINTS) {
System.arraycopy(pointTypes, startIndex, pointTypes, 0, newSize);
}
} }
mEventTimes.setLength(newSize); mEventTimes.setLength(newSize);
mXCoordinates.setLength(newSize); mXCoordinates.setLength(newSize);
mYCoordinates.setLength(newSize); mYCoordinates.setLength(newSize);
if (DBG_SHOW_POINTS) { if (DEBUG_SHOW_POINTS) {
mPointTypes.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
@ -295,4 +293,26 @@ final class GestureTrail {
} }
return newSize > 0; return newSize > 0;
} }
private void debugDrawPoints(final Canvas canvas, final int startIndex, final int endIndex,
final Paint paint) {
final int[] xCoords = mXCoordinates.getPrimitiveArray();
final int[] yCoords = mYCoordinates.getPrimitiveArray();
final int[] pointTypes = mPointTypes.getPrimitiveArray();
// {@link Paint} that is zero width stroke and anti alias off draws exactly 1 pixel.
paint.setAntiAlias(false);
paint.setStrokeWidth(0);
for (int i = startIndex; i < endIndex; i++) {
final int pointType = pointTypes[i];
if (pointType == POINT_TYPE_INTERPOLATED) {
paint.setColor(Color.RED);
} else if (pointType == POINT_TYPE_SAMPLED) {
paint.setColor(0xFFA000FF);
} else {
paint.setColor(Color.GREEN);
}
canvas.drawPoint(getXCoordValue(xCoords[i]), yCoords[i], paint);
}
paint.setAntiAlias(true);
}
} }