aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2014-01-08 05:29:32 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-01-08 05:29:32 +0000
commit9b351f75943b50df9ebf2452dfe9c3a797547f1a (patch)
tree9f9948971c368902767acd00efca3670110386cd /java/src
parentb3c51630a6b8dc09c161c7720db7bae21b0cf27e (diff)
parente7dc5302afdaedc379e3725f2a5822b630b43276 (diff)
downloadlatinime-9b351f75943b50df9ebf2452dfe9c3a797547f1a.tar.gz
latinime-9b351f75943b50df9ebf2452dfe9c3a797547f1a.tar.xz
latinime-9b351f75943b50df9ebf2452dfe9c3a797547f1a.zip
Merge "Fix InputPointersTests"
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/InputPointers.java49
1 files changed, 27 insertions, 22 deletions
diff --git a/java/src/com/android/inputmethod/latin/InputPointers.java b/java/src/com/android/inputmethod/latin/InputPointers.java
index 2e638aaf3..6b489da30 100644
--- a/java/src/com/android/inputmethod/latin/InputPointers.java
+++ b/java/src/com/android/inputmethod/latin/InputPointers.java
@@ -16,14 +16,16 @@
package com.android.inputmethod.latin;
+import android.util.Log;
+
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.utils.ResizableIntArray;
-import android.util.Log;
-
// TODO: This class is not thread-safe.
public final class InputPointers {
private static final String TAG = InputPointers.class.getSimpleName();
+ private static final boolean DEBUG_TIME = false;
+
private final int mDefaultCapacity;
private final ResizableIntArray mXCoordinates;
private final ResizableIntArray mYCoordinates;
@@ -38,10 +40,29 @@ public final class InputPointers {
mTimes = new ResizableIntArray(defaultCapacity);
}
+ private void fillWithLastTimeUntil(final int index) {
+ final int fromIndex = mTimes.getLength();
+ // Fill the gap with the latest time.
+ // See {@link #getTime(int)} and {@link #isValidTimeStamps()}.
+ if (fromIndex <= 0) {
+ return;
+ }
+ final int fillLength = index - fromIndex + 1;
+ if (fillLength <= 0) {
+ return;
+ }
+ final int lastTime = mTimes.get(fromIndex - 1);
+ mTimes.fill(lastTime, fromIndex, fillLength);
+ }
+
+ // TODO: Rename this method to addPointerAt
public void addPointer(int index, int x, int y, int pointerId, int time) {
mXCoordinates.add(index, x);
mYCoordinates.add(index, y);
mPointerIds.add(index, pointerId);
+ if (LatinImeLogger.sDBG || DEBUG_TIME) {
+ fillWithLastTimeUntil(index);
+ }
mTimes.add(index, time);
}
@@ -68,23 +89,6 @@ public final class InputPointers {
}
/**
- * Append the pointers in the specified {@link InputPointers} to the end of this.
- * @param src the source {@link InputPointers} to read the data from.
- * @param startPos the starting index of the pointers in {@code src}.
- * @param length the number of pointers to be appended.
- */
- @UsedForTesting
- void append(InputPointers src, int startPos, int length) {
- if (length == 0) {
- return;
- }
- mXCoordinates.append(src.mXCoordinates, startPos, length);
- mYCoordinates.append(src.mYCoordinates, startPos, length);
- mPointerIds.append(src.mPointerIds, startPos, length);
- mTimes.append(src.mTimes, startPos, length);
- }
-
- /**
* Append the times, x-coordinates and y-coordinates in the specified {@link ResizableIntArray}
* to the end of this.
* @param pointerId the pointer id of the source.
@@ -141,7 +145,7 @@ public final class InputPointers {
}
public int[] getTimes() {
- if (LatinImeLogger.sDBG) {
+ if (LatinImeLogger.sDBG || DEBUG_TIME) {
if (!isValidTimeStamps()) {
throw new RuntimeException("Time stamps are invalid.");
}
@@ -157,10 +161,11 @@ public final class InputPointers {
private boolean isValidTimeStamps() {
final int[] times = mTimes.getPrimitiveArray();
- for (int i = 1; i < getPointerSize(); ++i) {
+ final int size = getPointerSize();
+ for (int i = 1; i < size; ++i) {
if (times[i] < times[i - 1]) {
// dump
- for (int j = 0; j < times.length; ++j) {
+ for (int j = 0; j < size; ++j) {
Log.d(TAG, "--- (" + j + ") " + times[j]);
}
return false;