aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/InputPointers.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/InputPointers.java')
-rw-r--r--java/src/com/android/inputmethod/latin/InputPointers.java46
1 files changed, 36 insertions, 10 deletions
diff --git a/java/src/com/android/inputmethod/latin/InputPointers.java b/java/src/com/android/inputmethod/latin/InputPointers.java
index 6b48aabb3..81c833000 100644
--- a/java/src/com/android/inputmethod/latin/InputPointers.java
+++ b/java/src/com/android/inputmethod/latin/InputPointers.java
@@ -1,23 +1,28 @@
/*
* Copyright (C) 2012 The Android Open Source Project
*
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package com.android.inputmethod.latin;
+import com.android.inputmethod.annotations.UsedForTesting;
+
+import android.util.Log;
+
// TODO: This class is not thread-safe.
public final class InputPointers {
+ private static final String TAG = InputPointers.class.getSimpleName();
private final int mDefaultCapacity;
private final ResizableIntArray mXCoordinates;
private final ResizableIntArray mYCoordinates;
@@ -39,7 +44,8 @@ public final class InputPointers {
mTimes.add(index, time);
}
- public void addPointer(int x, int y, int pointerId, int time) {
+ @UsedForTesting
+ void addPointer(int x, int y, int pointerId, int time) {
mXCoordinates.add(x);
mYCoordinates.add(y);
mPointerIds.add(pointerId);
@@ -66,7 +72,8 @@ public final class InputPointers {
* @param startPos the starting index of the pointers in {@code src}.
* @param length the number of pointers to be appended.
*/
- public void append(InputPointers src, int startPos, int length) {
+ @UsedForTesting
+ void append(InputPointers src, int startPos, int length) {
if (length == 0) {
return;
}
@@ -122,6 +129,11 @@ public final class InputPointers {
}
public int[] getTimes() {
+ if (LatinImeLogger.sDBG) {
+ if (!isValidTimeStamps()) {
+ throw new RuntimeException("Time stamps are invalid.");
+ }
+ }
return mTimes.getPrimitiveArray();
}
@@ -130,4 +142,18 @@ public final class InputPointers {
return "size=" + getPointerSize() + " id=" + mPointerIds + " time=" + mTimes
+ " x=" + mXCoordinates + " y=" + mYCoordinates;
}
+
+ private boolean isValidTimeStamps() {
+ final int[] times = mTimes.getPrimitiveArray();
+ for (int i = 1; i < getPointerSize(); ++i) {
+ if (times[i] < times[i - 1]) {
+ // dump
+ for (int j = 0; j < times.length; ++j) {
+ Log.d(TAG, "--- (" + j + ") " + times[j]);
+ }
+ return false;
+ }
+ }
+ return true;
+ }
}