aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/PointerTracker.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/BatchInputArbiter.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/GestureStrokeDrawingPoints.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/GestureStrokeRecognitionPoints.java4
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/GestureTrailDrawingPoints.java2
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionary.java1
-rw-r--r--java/src/com/android/inputmethod/latin/InputPointers.java189
-rw-r--r--java/src/com/android/inputmethod/latin/LastComposedWord.java1
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java1
-rw-r--r--java/src/com/android/inputmethod/latin/WordComposer.java1
-rw-r--r--java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java2
-rw-r--r--java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java2
-rw-r--r--java/src/com/android/inputmethod/latin/utils/ResizableIntArray.java155
14 files changed, 13 insertions, 353 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java b/java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java
index ac66f7c6a..cdd632bc8 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java
@@ -16,8 +16,8 @@
package com.android.inputmethod.keyboard;
-import com.android.inputmethod.latin.InputPointers;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.InputPointers;
public interface KeyboardActionListener {
/**
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index fe6270fb5..5a540ff17 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -31,9 +31,9 @@ import com.android.inputmethod.keyboard.internal.GestureStrokeDrawingPoints;
import com.android.inputmethod.keyboard.internal.GestureStrokeRecognitionParams;
import com.android.inputmethod.keyboard.internal.PointerTrackerQueue;
import com.android.inputmethod.keyboard.internal.TypingTimeRecorder;
-import com.android.inputmethod.latin.InputPointers;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.InputPointers;
import com.android.inputmethod.latin.define.DebugFlags;
import com.android.inputmethod.latin.settings.Settings;
import com.android.inputmethod.latin.utils.CoordinateUtils;
diff --git a/java/src/com/android/inputmethod/keyboard/internal/BatchInputArbiter.java b/java/src/com/android/inputmethod/keyboard/internal/BatchInputArbiter.java
index efb365e42..77d0e7a90 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/BatchInputArbiter.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/BatchInputArbiter.java
@@ -16,8 +16,8 @@
package com.android.inputmethod.keyboard.internal;
-import com.android.inputmethod.latin.InputPointers;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.InputPointers;
/**
* This class arbitrates batch input.
diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureStrokeDrawingPoints.java b/java/src/com/android/inputmethod/keyboard/internal/GestureStrokeDrawingPoints.java
index 7d09e9d2f..07ef00924 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/GestureStrokeDrawingPoints.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/GestureStrokeDrawingPoints.java
@@ -16,7 +16,7 @@
package com.android.inputmethod.keyboard.internal;
-import com.android.inputmethod.latin.utils.ResizableIntArray;
+import com.android.inputmethod.latin.common.ResizableIntArray;
/**
* This class holds drawing points to represent a gesture stroke on the screen.
diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureStrokeRecognitionPoints.java b/java/src/com/android/inputmethod/keyboard/internal/GestureStrokeRecognitionPoints.java
index 99ec18f4d..3e901114a 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/GestureStrokeRecognitionPoints.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/GestureStrokeRecognitionPoints.java
@@ -18,9 +18,9 @@ package com.android.inputmethod.keyboard.internal;
import android.util.Log;
-import com.android.inputmethod.latin.InputPointers;
import com.android.inputmethod.latin.common.Constants;
-import com.android.inputmethod.latin.utils.ResizableIntArray;
+import com.android.inputmethod.latin.common.InputPointers;
+import com.android.inputmethod.latin.common.ResizableIntArray;
/**
* This class holds event points to recognize a gesture stroke.
diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureTrailDrawingPoints.java b/java/src/com/android/inputmethod/keyboard/internal/GestureTrailDrawingPoints.java
index 67683e247..4d998e443 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/GestureTrailDrawingPoints.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/GestureTrailDrawingPoints.java
@@ -24,7 +24,7 @@ import android.graphics.Rect;
import android.os.SystemClock;
import com.android.inputmethod.latin.common.Constants;
-import com.android.inputmethod.latin.utils.ResizableIntArray;
+import com.android.inputmethod.latin.common.ResizableIntArray;
/**
* This class holds drawing points to represent a gesture trail. The gesture trail may contain
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
index 1c4ff9659..8e9b5c6f6 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
@@ -24,6 +24,7 @@ import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.keyboard.ProximityInfo;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.InputPointers;
import com.android.inputmethod.latin.common.StringUtils;
import com.android.inputmethod.latin.makedict.DictionaryHeader;
import com.android.inputmethod.latin.makedict.FormatSpec;
diff --git a/java/src/com/android/inputmethod/latin/InputPointers.java b/java/src/com/android/inputmethod/latin/InputPointers.java
deleted file mode 100644
index d57a881c0..000000000
--- a/java/src/com/android/inputmethod/latin/InputPointers.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * 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;
-
-import android.util.Log;
-import android.util.SparseIntArray;
-
-import com.android.inputmethod.annotations.UsedForTesting;
-import com.android.inputmethod.latin.define.DebugFlags;
-import com.android.inputmethod.latin.utils.ResizableIntArray;
-
-// 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;
- private final ResizableIntArray mPointerIds;
- private final ResizableIntArray mTimes;
-
- public InputPointers(int defaultCapacity) {
- mDefaultCapacity = defaultCapacity;
- mXCoordinates = new ResizableIntArray(defaultCapacity);
- mYCoordinates = new ResizableIntArray(defaultCapacity);
- mPointerIds = new ResizableIntArray(defaultCapacity);
- 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);
- }
-
- public void addPointerAt(int index, int x, int y, int pointerId, int time) {
- mXCoordinates.addAt(index, x);
- mYCoordinates.addAt(index, y);
- mPointerIds.addAt(index, pointerId);
- if (DebugFlags.DEBUG_ENABLED || DEBUG_TIME) {
- fillWithLastTimeUntil(index);
- }
- mTimes.addAt(index, time);
- }
-
- @UsedForTesting
- 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);
- }
-
- /**
- * 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);
- mPointerIds.fill(pointerId, mPointerIds.getLength(), length);
- mTimes.append(times, startPos, length);
- }
-
- /**
- * Shift to the left by elementCount, discarding elementCount pointers at the start.
- * @param elementCount how many elements to shift.
- */
- public void shift(final int elementCount) {
- mXCoordinates.shift(elementCount);
- mYCoordinates.shift(elementCount);
- mPointerIds.shift(elementCount);
- mTimes.shift(elementCount);
- }
-
- public void reset() {
- final int defaultCapacity = mDefaultCapacity;
- mXCoordinates.reset(defaultCapacity);
- mYCoordinates.reset(defaultCapacity);
- mPointerIds.reset(defaultCapacity);
- mTimes.reset(defaultCapacity);
- }
-
- public int getPointerSize() {
- return mXCoordinates.getLength();
- }
-
- public int[] getXCoordinates() {
- return mXCoordinates.getPrimitiveArray();
- }
-
- public int[] getYCoordinates() {
- return mYCoordinates.getPrimitiveArray();
- }
-
- public int[] getPointerIds() {
- return mPointerIds.getPrimitiveArray();
- }
-
- /**
- * Gets the time each point was registered, in milliseconds, relative to the first event in the
- * sequence.
- * @return The time each point was registered, in milliseconds, relative to the first event in
- * the sequence.
- */
- public int[] getTimes() {
- if (DebugFlags.DEBUG_ENABLED || DEBUG_TIME) {
- if (!isValidTimeStamps()) {
- throw new RuntimeException("Time stamps are invalid.");
- }
- }
- return mTimes.getPrimitiveArray();
- }
-
- @Override
- public String toString() {
- return "size=" + getPointerSize() + " id=" + mPointerIds + " time=" + mTimes
- + " x=" + mXCoordinates + " y=" + mYCoordinates;
- }
-
- private boolean isValidTimeStamps() {
- final int[] times = mTimes.getPrimitiveArray();
- final int[] pointerIds = mPointerIds.getPrimitiveArray();
- final SparseIntArray lastTimeOfPointers = new SparseIntArray();
- final int size = getPointerSize();
- for (int i = 0; i < size; ++i) {
- final int pointerId = pointerIds[i];
- final int time = times[i];
- final int lastTime = lastTimeOfPointers.get(pointerId, time);
- if (time < lastTime) {
- // dump
- for (int j = 0; j < size; ++j) {
- Log.d(TAG, "--- (" + j + ") " + times[j]);
- }
- return false;
- }
- lastTimeOfPointers.put(pointerId, time);
- }
- return true;
- }
-}
diff --git a/java/src/com/android/inputmethod/latin/LastComposedWord.java b/java/src/com/android/inputmethod/latin/LastComposedWord.java
index c4c389411..9fcdb2229 100644
--- a/java/src/com/android/inputmethod/latin/LastComposedWord.java
+++ b/java/src/com/android/inputmethod/latin/LastComposedWord.java
@@ -20,6 +20,7 @@ import android.text.TextUtils;
import com.android.inputmethod.event.Event;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.InputPointers;
import java.util.ArrayList;
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index ff82087ae..5fa28d571 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -77,6 +77,7 @@ import com.android.inputmethod.keyboard.TextDecoratorUi;
import com.android.inputmethod.latin.Suggest.OnGetSuggestedWordsCallback;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.InputPointers;
import com.android.inputmethod.latin.define.DebugFlags;
import com.android.inputmethod.latin.define.ProductionFlags;
import com.android.inputmethod.latin.inputlogic.InputLogic;
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java
index 35436f59c..0b77f2ce3 100644
--- a/java/src/com/android/inputmethod/latin/WordComposer.java
+++ b/java/src/com/android/inputmethod/latin/WordComposer.java
@@ -20,6 +20,7 @@ import com.android.inputmethod.event.CombinerChain;
import com.android.inputmethod.event.Event;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.InputPointers;
import com.android.inputmethod.latin.common.StringUtils;
import com.android.inputmethod.latin.define.DebugFlags;
import com.android.inputmethod.latin.utils.CoordinateUtils;
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index f3a287320..bafea178e 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -41,7 +41,6 @@ import com.android.inputmethod.keyboard.TextDecorator;
import com.android.inputmethod.keyboard.TextDecoratorUiOperator;
import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.DictionaryFacilitator;
-import com.android.inputmethod.latin.InputPointers;
import com.android.inputmethod.latin.LastComposedWord;
import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.NgramContext;
@@ -52,6 +51,7 @@ import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.WordComposer;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.InputPointers;
import com.android.inputmethod.latin.common.StringUtils;
import com.android.inputmethod.latin.define.DebugFlags;
import com.android.inputmethod.latin.settings.SettingsValues;
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java
index 5f391dd9b..ddc4ad99c 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java
@@ -21,10 +21,10 @@ import android.os.HandlerThread;
import android.os.Message;
import com.android.inputmethod.compat.LooperCompatUtils;
-import com.android.inputmethod.latin.InputPointers;
import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.Suggest.OnGetSuggestedWordsCallback;
+import com.android.inputmethod.latin.common.InputPointers;
/**
* A helper to manage deferred tasks for the input logic.
diff --git a/java/src/com/android/inputmethod/latin/utils/ResizableIntArray.java b/java/src/com/android/inputmethod/latin/utils/ResizableIntArray.java
deleted file mode 100644
index 64c9e2cff..000000000
--- a/java/src/com/android/inputmethod/latin/utils/ResizableIntArray.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * 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.utils;
-
-import java.util.Arrays;
-
-// TODO: This class is not thread-safe.
-public final class ResizableIntArray {
- private int[] mArray;
- private int mLength;
-
- public ResizableIntArray(final int capacity) {
- reset(capacity);
- }
-
- public int get(final int index) {
- if (index < mLength) {
- return mArray[index];
- }
- throw new ArrayIndexOutOfBoundsException("length=" + mLength + "; index=" + index);
- }
-
- public void addAt(final int index, final int val) {
- if (index < mLength) {
- mArray[index] = val;
- } else {
- mLength = index;
- add(val);
- }
- }
-
- public void add(final int val) {
- final int currentLength = mLength;
- ensureCapacity(currentLength + 1);
- mArray[currentLength] = val;
- mLength = currentLength + 1;
- }
-
- /**
- * Calculate the new capacity of {@code mArray}.
- * @param minimumCapacity the minimum capacity that the {@code mArray} should have.
- * @return the new capacity that the {@code mArray} should have. Returns zero when there is no
- * need to expand {@code mArray}.
- */
- private int calculateCapacity(final int minimumCapacity) {
- final int currentCapcity = mArray.length;
- if (currentCapcity < minimumCapacity) {
- final int nextCapacity = currentCapcity * 2;
- // The following is the same as return Math.max(minimumCapacity, nextCapacity);
- return minimumCapacity > nextCapacity ? minimumCapacity : nextCapacity;
- }
- return 0;
- }
-
- private void ensureCapacity(final int minimumCapacity) {
- final int newCapacity = calculateCapacity(minimumCapacity);
- if (newCapacity > 0) {
- // TODO: Implement primitive array pool.
- mArray = Arrays.copyOf(mArray, newCapacity);
- }
- }
-
- public int getLength() {
- return mLength;
- }
-
- public void setLength(final int newLength) {
- ensureCapacity(newLength);
- mLength = newLength;
- }
-
- public void reset(final int capacity) {
- // TODO: Implement primitive array pool.
- mArray = new int[capacity];
- mLength = 0;
- }
-
- public int[] getPrimitiveArray() {
- return mArray;
- }
-
- public void set(final ResizableIntArray ip) {
- // TODO: Implement primitive array pool.
- mArray = ip.mArray;
- mLength = ip.mLength;
- }
-
- public void copy(final ResizableIntArray ip) {
- final int newCapacity = calculateCapacity(ip.mLength);
- if (newCapacity > 0) {
- // TODO: Implement primitive array pool.
- mArray = new int[newCapacity];
- }
- System.arraycopy(ip.mArray, 0, mArray, 0, ip.mLength);
- mLength = ip.mLength;
- }
-
- public void append(final ResizableIntArray src, final int startPos, final int length) {
- if (length == 0) {
- return;
- }
- final int currentLength = mLength;
- final int newLength = currentLength + length;
- ensureCapacity(newLength);
- System.arraycopy(src.mArray, startPos, mArray, currentLength, length);
- mLength = newLength;
- }
-
- public void fill(final int value, final int startPos, final int length) {
- if (startPos < 0 || length < 0) {
- throw new IllegalArgumentException("startPos=" + startPos + "; length=" + length);
- }
- final int endPos = startPos + length;
- ensureCapacity(endPos);
- Arrays.fill(mArray, startPos, endPos, value);
- if (mLength < endPos) {
- mLength = endPos;
- }
- }
-
- /**
- * Shift to the left by elementCount, discarding elementCount pointers at the start.
- * @param elementCount how many elements to shift.
- */
- public void shift(final int elementCount) {
- System.arraycopy(mArray, elementCount, mArray, 0, mLength - elementCount);
- mLength -= elementCount;
- }
-
- @Override
- public String toString() {
- final StringBuilder sb = new StringBuilder();
- for (int i = 0; i < mLength; i++) {
- if (i != 0) {
- sb.append(",");
- }
- sb.append(mArray[i]);
- }
- return "[" + sb + "]";
- }
-}