2012-06-29 09:42:15 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.latin;
|
|
|
|
|
2012-07-13 02:17:25 +00:00
|
|
|
// TODO: This class is not thread-safe.
|
2012-06-29 09:42:15 +00:00
|
|
|
public class InputPointers {
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addPointer(int x, int y, int pointerId, int time) {
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
public 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() {
|
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;
|
|
|
|
}
|
2012-06-29 09:42:15 +00:00
|
|
|
}
|