2012-06-29 09:42:15 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 The Android Open Source Project
|
|
|
|
*
|
2013-01-21 12:52:57 +00:00
|
|
|
* 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
|
2012-06-29 09:42:15 +00:00
|
|
|
*
|
2013-01-21 12:52:57 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-06-29 09:42:15 +00:00
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
2013-01-21 12:52:57 +00:00
|
|
|
* 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.
|
2012-06-29 09:42:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.latin;
|
|
|
|
|
2012-10-03 08:36:45 +00:00
|
|
|
import com.android.inputmethod.annotations.UsedForTesting;
|
2013-06-23 16:11:32 +00:00
|
|
|
import com.android.inputmethod.latin.utils.ResizableIntArray;
|
2012-10-03 08:36:45 +00:00
|
|
|
|
2013-01-23 06:13:52 +00:00
|
|
|
import android.util.Log;
|
|
|
|
|
2012-07-13 02:17:25 +00:00
|
|
|
// TODO: This class is not thread-safe.
|
2012-09-27 09:16:16 +00:00
|
|
|
public final class InputPointers {
|
2013-01-23 06:13:52 +00:00
|
|
|
private static final String TAG = InputPointers.class.getSimpleName();
|
2012-07-18 11:31:09 +00:00
|
|
|
private final int mDefaultCapacity;
|
2012-07-19 10:45:20 +00:00
|
|
|
private final ResizableIntArray mXCoordinates;
|
|
|
|
private final ResizableIntArray mYCoordinates;
|
|
|
|
private final ResizableIntArray mPointerIds;
|
|
|
|
private final ResizableIntArray mTimes;
|
2012-07-18 11:31:09 +00:00
|
|
|
|
|
|
|
public InputPointers(int defaultCapacity) {
|
|
|
|
mDefaultCapacity = defaultCapacity;
|
2012-07-19 10:45:20 +00:00
|
|
|
mXCoordinates = new ResizableIntArray(defaultCapacity);
|
|
|
|
mYCoordinates = new ResizableIntArray(defaultCapacity);
|
|
|
|
mPointerIds = new ResizableIntArray(defaultCapacity);
|
|
|
|
mTimes = new ResizableIntArray(defaultCapacity);
|
2012-07-18 11:31:09 +00:00
|
|
|
}
|
2012-06-29 09:42:15 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
mTimes.add(index, time);
|
|
|
|
}
|
|
|
|
|
2012-10-03 08:36:45 +00:00
|
|
|
@UsedForTesting
|
|
|
|
void addPointer(int x, int y, int pointerId, int time) {
|
2012-06-29 09:42:15 +00:00
|
|
|
mXCoordinates.add(x);
|
|
|
|
mYCoordinates.add(y);
|
|
|
|
mPointerIds.add(pointerId);
|
|
|
|
mTimes.add(time);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void set(InputPointers ip) {
|
|
|
|
mXCoordinates.set(ip.mXCoordinates);
|
|
|
|
mYCoordinates.set(ip.mYCoordinates);
|
|
|
|
mPointerIds.set(ip.mPointerIds);
|
|
|
|
mTimes.set(ip.mTimes);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void copy(InputPointers ip) {
|
|
|
|
mXCoordinates.copy(ip.mXCoordinates);
|
|
|
|
mYCoordinates.copy(ip.mYCoordinates);
|
|
|
|
mPointerIds.copy(ip.mPointerIds);
|
|
|
|
mTimes.copy(ip.mTimes);
|
|
|
|
}
|
|
|
|
|
2012-07-09 07:40:13 +00:00
|
|
|
/**
|
|
|
|
* Append the pointers in the specified {@link InputPointers} to the end of this.
|
2012-07-13 02:17:25 +00:00
|
|
|
* @param src the source {@link InputPointers} to read the data from.
|
2012-07-09 07:40:13 +00:00
|
|
|
* @param startPos the starting index of the pointers in {@code src}.
|
|
|
|
* @param length the number of pointers to be appended.
|
|
|
|
*/
|
2012-10-03 08:36:45 +00:00
|
|
|
@UsedForTesting
|
|
|
|
void append(InputPointers src, int startPos, int length) {
|
2012-07-18 08:56:30 +00:00
|
|
|
if (length == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2012-07-13 02:17:25 +00:00
|
|
|
mXCoordinates.append(src.mXCoordinates, startPos, length);
|
|
|
|
mYCoordinates.append(src.mYCoordinates, startPos, length);
|
|
|
|
mPointerIds.append(src.mPointerIds, startPos, length);
|
|
|
|
mTimes.append(src.mTimes, startPos, length);
|
2012-07-09 07:40:13 +00:00
|
|
|
}
|
|
|
|
|
2012-07-20 07:24:54 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
* @param times the source {@link ResizableIntArray} to read the event times from.
|
|
|
|
* @param xCoordinates the source {@link ResizableIntArray} to read the x-coordinates from.
|
|
|
|
* @param yCoordinates the source {@link ResizableIntArray} to read the y-coordinates from.
|
|
|
|
* @param startPos the starting index of the data in {@code times} and etc.
|
|
|
|
* @param length the number of data to be appended.
|
|
|
|
*/
|
|
|
|
public void append(int pointerId, ResizableIntArray times, ResizableIntArray xCoordinates,
|
|
|
|
ResizableIntArray yCoordinates, int startPos, int length) {
|
|
|
|
if (length == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mXCoordinates.append(xCoordinates, startPos, length);
|
|
|
|
mYCoordinates.append(yCoordinates, startPos, length);
|
2012-08-23 08:47:13 +00:00
|
|
|
mPointerIds.fill(pointerId, mPointerIds.getLength(), length);
|
2012-07-20 07:24:54 +00:00
|
|
|
mTimes.append(times, startPos, length);
|
|
|
|
}
|
|
|
|
|
2012-06-29 09:42:15 +00:00
|
|
|
public void reset() {
|
2012-07-18 11:31:09 +00:00
|
|
|
final int defaultCapacity = mDefaultCapacity;
|
|
|
|
mXCoordinates.reset(defaultCapacity);
|
|
|
|
mYCoordinates.reset(defaultCapacity);
|
|
|
|
mPointerIds.reset(defaultCapacity);
|
|
|
|
mTimes.reset(defaultCapacity);
|
2012-06-29 09:42:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getPointerSize() {
|
|
|
|
return mXCoordinates.getLength();
|
|
|
|
}
|
|
|
|
|
|
|
|
public int[] getXCoordinates() {
|
2012-07-09 07:40:13 +00:00
|
|
|
return mXCoordinates.getPrimitiveArray();
|
2012-06-29 09:42:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int[] getYCoordinates() {
|
2012-07-09 07:40:13 +00:00
|
|
|
return mYCoordinates.getPrimitiveArray();
|
2012-06-29 09:42:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int[] getPointerIds() {
|
2012-07-09 07:40:13 +00:00
|
|
|
return mPointerIds.getPrimitiveArray();
|
2012-06-29 09:42:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int[] getTimes() {
|
2013-01-23 06:13:52 +00:00
|
|
|
if (LatinImeLogger.sDBG) {
|
|
|
|
if (!isValidTimeStamps()) {
|
|
|
|
throw new RuntimeException("Time stamps are invalid.");
|
|
|
|
}
|
|
|
|
}
|
2012-07-09 07:40:13 +00:00
|
|
|
return mTimes.getPrimitiveArray();
|
2012-06-29 09:42:15 +00:00
|
|
|
}
|
2012-08-23 08:29:36 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "size=" + getPointerSize() + " id=" + mPointerIds + " time=" + mTimes
|
|
|
|
+ " x=" + mXCoordinates + " y=" + mYCoordinates;
|
|
|
|
}
|
2013-01-23 06:13:52 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2012-06-29 09:42:15 +00:00
|
|
|
}
|