diff options
author | 2012-08-27 00:29:47 -0700 | |
---|---|---|
committer | 2012-08-27 00:29:48 -0700 | |
commit | 1451a0fb1fbe7b86fe12742a28c759d5cbade5dd (patch) | |
tree | 4894883ec314748a0df52635fc8f4575be5a7fed /java/src/com/android/inputmethod | |
parent | 76951d8e5a573233aba855a0fa5ba501217a3371 (diff) | |
parent | 1c2f33223995d8a6c069a85655f790388cd4e581 (diff) | |
download | latinime-1451a0fb1fbe7b86fe12742a28c759d5cbade5dd.tar.gz latinime-1451a0fb1fbe7b86fe12742a28c759d5cbade5dd.tar.xz latinime-1451a0fb1fbe7b86fe12742a28c759d5cbade5dd.zip |
Merge "Optimize gesture preview trail drawing a bit" into jb-mr1-dev
Diffstat (limited to 'java/src/com/android/inputmethod')
-rw-r--r-- | java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java b/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java index 747627b7d..e814d8009 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java +++ b/java/src/com/android/inputmethod/keyboard/internal/GesturePreviewTrail.java @@ -32,6 +32,7 @@ class GesturePreviewTrail { private final ResizableIntArray mEventTimes = new ResizableIntArray(DEFAULT_CAPACITY); private int mCurrentStrokeId = -1; private long mCurrentDownTime; + private int mTrailStartIndex; // Use this value as imaginary zero because x-coordinates may be zero. private static final int DOWN_EVENT_MARKER = -128; @@ -80,7 +81,7 @@ class GesturePreviewTrail { if (isNewStroke) { final int elapsedTime = (int)(downTime - mCurrentDownTime); final int[] eventTimes = mEventTimes.getPrimitiveArray(); - for (int i = 0; i < trailSize; i++) { + for (int i = mTrailStartIndex; i < trailSize; i++) { eventTimes[i] -= elapsedTime; } @@ -122,13 +123,14 @@ class GesturePreviewTrail { final int lingeringDuration = mPreviewParams.mFadeoutStartDelay + mPreviewParams.mFadeoutDuration; int startIndex; - for (startIndex = 0; startIndex < trailSize; startIndex++) { + for (startIndex = mTrailStartIndex; startIndex < trailSize; startIndex++) { final int elapsedTime = sinceDown - eventTimes[startIndex]; // Skip too old trail points. if (elapsedTime < lingeringDuration) { break; } } + mTrailStartIndex = startIndex; if (startIndex < trailSize) { int lastX = getXCoordValue(xCoords[startIndex]); @@ -147,15 +149,18 @@ class GesturePreviewTrail { } } - // TODO: Implement ring buffer to avoid moving points. - // Discard faded out points. final int newSize = trailSize - startIndex; - System.arraycopy(eventTimes, startIndex, eventTimes, 0, newSize); - System.arraycopy(xCoords, startIndex, xCoords, 0, newSize); - System.arraycopy(yCoords, startIndex, yCoords, 0, newSize); - mEventTimes.setLength(newSize); - mXCoordinates.setLength(newSize); - mYCoordinates.setLength(newSize); + if (newSize < startIndex) { + mTrailStartIndex = 0; + if (newSize > 0) { + System.arraycopy(eventTimes, startIndex, eventTimes, 0, newSize); + System.arraycopy(xCoords, startIndex, xCoords, 0, newSize); + System.arraycopy(yCoords, startIndex, yCoords, 0, newSize); + } + mEventTimes.setLength(newSize); + mXCoordinates.setLength(newSize); + mYCoordinates.setLength(newSize); + } return newSize > 0; } } |