aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2013-04-01 10:23:26 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-04-01 10:23:27 +0000
commit9413e957fafcf4660f2f620f8fe716d9ba448d92 (patch)
treeb41a5fd67d3c20a4dcf63ad510773111f696b85c /java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java
parent54c091d284b15e14cbcbce983354f679526672ec (diff)
parent75028af28cc657d3b314e7761b3a145af4696f5c (diff)
downloadlatinime-9413e957fafcf4660f2f620f8fe716d9ba448d92.tar.gz
latinime-9413e957fafcf4660f2f620f8fe716d9ba448d92.tar.xz
latinime-9413e957fafcf4660f2f620f8fe716d9ba448d92.zip
Merge "Interpolate gesture preview trails"
Diffstat (limited to 'java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java')
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java16
1 files changed, 16 insertions, 0 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java b/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java
index b047fe038..e3e6d39e4 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java
@@ -44,6 +44,7 @@ final class GesturePreviewTrail {
// The wall time of the zero value in {@link #mEventTimes}
private long mCurrentTimeBase;
private int mTrailStartIndex;
+ private int mLastInterpolatedDrawIndex;
static final class Params {
public final int mTrailColor;
@@ -96,6 +97,17 @@ final class GesturePreviewTrail {
}
final int[] eventTimes = mEventTimes.getPrimitiveArray();
final int strokeId = stroke.getGestureStrokeId();
+ // Because interpolation algorithm in {@link GestureStrokeWithPreviewPoints} can't determine
+ // the interpolated points in the last segment of gesture stroke, it may need recalculation
+ // of interpolation when new segments are added to the stroke.
+ // {@link #mLastInterpolatedDrawIndex} holds the start index of the last segment. It may
+ // be updated by the interpolation
+ // {@link GestureStrokeWithPreviewPoints#interpolatePreviewStroke}
+ // or by animation {@link #drawGestureTrail(Canvas,Paint,Rect,Params)} below.
+ final int lastInterpolatedIndex = (strokeId == mCurrentStrokeId)
+ ? mLastInterpolatedDrawIndex : trailSize;
+ mLastInterpolatedDrawIndex = stroke.interpolateStrokeAndReturnStartIndexOfLastSegment(
+ lastInterpolatedIndex, mEventTimes, mXCoordinates, mYCoordinates);
if (strokeId != mCurrentStrokeId) {
final int elapsedTime = (int)(downTime - mCurrentTimeBase);
for (int i = mTrailStartIndex; i < trailSize; i++) {
@@ -216,6 +228,10 @@ final class GesturePreviewTrail {
System.arraycopy(eventTimes, startIndex, eventTimes, 0, newSize);
System.arraycopy(xCoords, startIndex, xCoords, 0, newSize);
System.arraycopy(yCoords, startIndex, yCoords, 0, newSize);
+ // The start index of the last segment of the stroke
+ // {@link mLastInterpolatedDrawIndex} should also be updated because all array
+ // elements have just been shifted for compaction.
+ mLastInterpolatedDrawIndex = Math.max(mLastInterpolatedDrawIndex - startIndex, 0);
}
mEventTimes.setLength(newSize);
mXCoordinates.setLength(newSize);