aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/keyboard/PointerTracker.java14
-rw-r--r--java/src/com/android/inputmethod/keyboard/ProximityInfo.java5
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java59
-rw-r--r--java/src/com/android/inputmethod/latin/NativeUtils.java32
-rw-r--r--java/src/com/android/inputmethod/latin/UserHistoryForgettingCurveUtils.java2
5 files changed, 31 insertions, 81 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index 85360c410..7d565a64f 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -29,7 +29,6 @@ import com.android.inputmethod.keyboard.internal.GestureStroke;
import com.android.inputmethod.keyboard.internal.PointerTrackerQueue;
import com.android.inputmethod.latin.InputPointers;
import com.android.inputmethod.latin.LatinImeLogger;
-import com.android.inputmethod.latin.Utils;
import com.android.inputmethod.latin.define.ProductionFlag;
import com.android.inputmethod.research.ResearchLogger;
@@ -130,10 +129,6 @@ public class PointerTracker implements PointerTrackerQueue.Element {
private static final InputPointers sAggregratedPointers = new InputPointers(
GestureStroke.DEFAULT_CAPACITY);
private static PointerTrackerQueue sPointerTrackerQueue;
- // HACK: Change gesture detection criteria depending on this variable.
- // TODO: Find more comprehensive ways to detect a gesture start.
- // True when the previous user input was a gesture input, not a typing input.
- private static boolean sWasInGesture;
public final int mPointerId;
@@ -413,8 +408,7 @@ public class PointerTracker implements PointerTrackerQueue.Element {
mKeyDetector = keyDetector;
mKeyboard = keyDetector.getKeyboard();
mIsAlphabetKeyboard = mKeyboard.mId.isAlphabetKeyboard();
- mGestureStroke.setGestureSampleLength(
- mKeyboard.mMostCommonKeyWidth, mKeyboard.mMostCommonKeyHeight);
+ mGestureStroke.setGestureSampleLength(mKeyboard.mMostCommonKeyWidth);
final Key newKey = mKeyDetector.detectHitKey(mKeyX, mKeyY);
if (newKey != mCurrentKey) {
if (mDrawingProxy != null) {
@@ -526,7 +520,7 @@ public class PointerTracker implements PointerTrackerQueue.Element {
public void drawGestureTrail(Canvas canvas, Paint paint) {
if (mInGesture) {
- mGestureStroke.drawGestureTrail(canvas, paint, mLastX, mLastY);
+ mGestureStroke.drawGestureTrail(canvas, paint);
}
}
@@ -586,7 +580,6 @@ public class PointerTracker implements PointerTrackerQueue.Element {
mListener.onEndBatchInput(batchPoints);
clearBatchInputRecognitionStateOfThisPointerTracker();
clearBatchInputPointsOfAllPointerTrackers();
- sWasInGesture = true;
}
private void abortBatchInput() {
@@ -719,7 +712,7 @@ public class PointerTracker implements PointerTrackerQueue.Element {
if (sShouldHandleGesture && mIsPossibleGesture) {
final GestureStroke stroke = mGestureStroke;
stroke.addPoint(x, y, gestureTime, isHistorical);
- if (!mInGesture && stroke.isStartOfAGesture(gestureTime, sWasInGesture)) {
+ if (!mInGesture && stroke.isStartOfAGesture()) {
startBatchInput();
}
}
@@ -1002,7 +995,6 @@ public class PointerTracker implements PointerTrackerQueue.Element {
int code = key.mCode;
callListenerOnCodeInput(key, code, x, y);
callListenerOnRelease(key, code, false);
- sWasInGesture = false;
}
private void printTouchEvent(String title, int x, int y, long eventTime) {
diff --git a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
index ae123e29a..ac0a56ba3 100644
--- a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
+++ b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
@@ -18,7 +18,6 @@ package com.android.inputmethod.keyboard;
import android.graphics.Rect;
import android.text.TextUtils;
-import android.util.FloatMath;
import com.android.inputmethod.keyboard.Keyboard.Params.TouchPositionCorrection;
import com.android.inputmethod.latin.JniUtils;
@@ -155,7 +154,9 @@ public class ProximityInfo {
final float radius = touchPositionCorrection.mRadii[row];
sweetSpotCenterXs[i] = hitBox.exactCenterX() + x * hitBoxWidth;
sweetSpotCenterYs[i] = hitBox.exactCenterY() + y * hitBoxHeight;
- sweetSpotRadii[i] = radius * FloatMath.sqrt(
+ // Note that, in recent versions of Android, FloatMath is actually slower than
+ // java.lang.Math due to the way the JIT optimizes java.lang.Math.
+ sweetSpotRadii[i] = radius * (float)Math.sqrt(
hitBoxWidth * hitBoxWidth + hitBoxHeight * hitBoxHeight);
}
}
diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java b/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java
index 28d6c1d07..79e977a40 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/GestureStroke.java
@@ -16,7 +16,6 @@ package com.android.inputmethod.keyboard.internal;
import android.graphics.Canvas;
import android.graphics.Paint;
-import android.util.FloatMath;
import com.android.inputmethod.latin.Constants;
import com.android.inputmethod.latin.InputPointers;
@@ -38,19 +37,16 @@ public class GestureStroke {
private int mLastPointY;
private int mMinGestureLength;
- private int mMinGestureLengthWhileInGesture;
private int mMinGestureSampleLength;
// TODO: Move some of these to resource.
- private static final float MIN_GESTURE_LENGTH_RATIO_TO_KEY_WIDTH = 1.0f;
- private static final float MIN_GESTURE_LENGTH_RATIO_TO_KEY_WIDTH_WHILE_IN_GESTURE = 0.5f;
- private static final int MIN_GESTURE_DURATION = 150; // msec
- private static final int MIN_GESTURE_DURATION_WHILE_IN_GESTURE = 75; // msec
- private static final float MIN_GESTURE_SAMPLING_RATIO_TO_KEY_HEIGHT = 1.0f / 6.0f;
+ private static final float MIN_GESTURE_LENGTH_RATIO_TO_KEY_WIDTH = 0.75f;
+ private static final int MIN_GESTURE_DURATION = 100; // msec
+ private static final float MIN_GESTURE_SAMPLING_RATIO_TO_KEY_WIDTH = 1.0f / 6.0f;
private static final float GESTURE_RECOG_SPEED_THRESHOLD = 0.4f; // dip/msec
private static final float GESTURE_RECOG_CURVATURE_THRESHOLD = (float)(Math.PI / 4.0f);
- private static final float DOUBLE_PI = (float)(2 * Math.PI);
+ private static final float DOUBLE_PI = (float)(2.0f * Math.PI);
// Fade based on number of gesture samples, see MIN_GESTURE_SAMPLING_RATIO_TO_KEY_HEIGHT
private static final int DRAWING_GESTURE_FADE_START = 10;
@@ -61,21 +57,15 @@ public class GestureStroke {
reset();
}
- public void setGestureSampleLength(final int keyWidth, final int keyHeight) {
+ public void setGestureSampleLength(final int keyWidth) {
// TODO: Find an appropriate base metric for these length. Maybe diagonal length of the key?
mMinGestureLength = (int)(keyWidth * MIN_GESTURE_LENGTH_RATIO_TO_KEY_WIDTH);
- mMinGestureLengthWhileInGesture = (int)(
- keyWidth * MIN_GESTURE_LENGTH_RATIO_TO_KEY_WIDTH_WHILE_IN_GESTURE);
- mMinGestureSampleLength = (int)(keyHeight * MIN_GESTURE_SAMPLING_RATIO_TO_KEY_HEIGHT);
+ mMinGestureSampleLength = (int)(keyWidth * MIN_GESTURE_SAMPLING_RATIO_TO_KEY_WIDTH);
}
- public boolean isStartOfAGesture(final int downDuration, final boolean wasInGesture) {
- // The tolerance of the time duration and the stroke length to detect the start of a
- // gesture stroke should be eased when the previous input was a gesture input.
- if (wasInGesture) {
- return downDuration > MIN_GESTURE_DURATION_WHILE_IN_GESTURE
- && mLength > mMinGestureLengthWhileInGesture;
- }
+ public boolean isStartOfAGesture() {
+ final int size = mEventTimes.getLength();
+ final int downDuration = (size > 0) ? mEventTimes.get(size - 1) : 0;
return downDuration > MIN_GESTURE_DURATION && mLength > mMinGestureLength;
}
@@ -154,19 +144,21 @@ public class GestureStroke {
mLastIncrementalBatchSize = size;
}
- private static float getDistance(final int p1x, final int p1y,
- final int p2x, final int p2y) {
- final float dx = p1x - p2x;
- final float dy = p1y - p2y;
- // TODO: Optimize out this {@link FloatMath#sqrt(float)} call.
- return FloatMath.sqrt(dx * dx + dy * dy);
+ private static float getDistance(final int x1, final int y1, final int x2, final int y2) {
+ final float dx = x1 - x2;
+ final float dy = y1 - y2;
+ // Note that, in recent versions of Android, FloatMath is actually slower than
+ // java.lang.Math due to the way the JIT optimizes java.lang.Math.
+ return (float)Math.sqrt(dx * dx + dy * dy);
}
- private static float getAngle(final int p1x, final int p1y, final int p2x, final int p2y) {
- final int dx = p1x - p2x;
- final int dy = p1y - p2y;
+ private static float getAngle(final int x1, final int y1, final int x2, final int y2) {
+ final int dx = x1 - x2;
+ final int dy = y1 - y2;
if (dx == 0 && dy == 0) return 0;
- return (float)Math.atan2(dy, dx);
+ // Would it be faster to call atan2f() directly via JNI? Not sure about what the JIT
+ // does with Math.atan2().
+ return (float)Math.atan2((double)dy, (double)dx);
}
private static float getAngleDiff(final float a1, final float a2) {
@@ -177,12 +169,12 @@ public class GestureStroke {
return diff;
}
- public void drawGestureTrail(Canvas canvas, Paint paint, int lastX, int lastY) {
+ public void drawGestureTrail(final Canvas canvas, final Paint paint) {
// TODO: These paint parameter interpolation should be tunable, possibly introduce an object
// that implements an interface such as Paint getPaint(int step, int strokePoints)
final int size = mXCoordinates.getLength();
- int[] xCoords = mXCoordinates.getPrimitiveArray();
- int[] yCoords = mYCoordinates.getPrimitiveArray();
+ final int[] xCoords = mXCoordinates.getPrimitiveArray();
+ final int[] yCoords = mYCoordinates.getPrimitiveArray();
int alpha = Constants.Color.ALPHA_OPAQUE;
for (int i = size - 1; i > 0 && alpha > 0; i--) {
paint.setAlpha(alpha);
@@ -190,9 +182,6 @@ public class GestureStroke {
alpha -= DRAWING_GESTURE_FADE_RATE;
}
canvas.drawLine(xCoords[i - 1], yCoords[i - 1], xCoords[i], yCoords[i], paint);
- if (i == size - 1) {
- canvas.drawLine(lastX, lastY, xCoords[i], yCoords[i], paint);
- }
}
}
}
diff --git a/java/src/com/android/inputmethod/latin/NativeUtils.java b/java/src/com/android/inputmethod/latin/NativeUtils.java
deleted file mode 100644
index 9cc2bc02e..000000000
--- a/java/src/com/android/inputmethod/latin/NativeUtils.java
+++ /dev/null
@@ -1,32 +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;
-
-public class NativeUtils {
- static {
- JniUtils.loadNativeLibrary();
- }
-
- private NativeUtils() {
- // This utility class is not publicly instantiable.
- }
-
- /**
- * This method just calls up libm's powf() directly.
- */
- public static native float powf(float x, float y);
-}
diff --git a/java/src/com/android/inputmethod/latin/UserHistoryForgettingCurveUtils.java b/java/src/com/android/inputmethod/latin/UserHistoryForgettingCurveUtils.java
index 1de95d7b8..5a2fdf48e 100644
--- a/java/src/com/android/inputmethod/latin/UserHistoryForgettingCurveUtils.java
+++ b/java/src/com/android/inputmethod/latin/UserHistoryForgettingCurveUtils.java
@@ -212,7 +212,7 @@ public class UserHistoryForgettingCurveUtils {
for (int j = 0; j < ELAPSED_TIME_MAX; ++j) {
final float elapsedHours = j * ELAPSED_TIME_INTERVAL_HOURS;
final float freq = initialFreq
- * NativeUtils.powf(initialFreq, elapsedHours / HALF_LIFE_HOURS);
+ * (float)Math.pow(initialFreq, elapsedHours / HALF_LIFE_HOURS);
final int intFreq = Math.min(FC_FREQ_MAX, Math.max(0, (int)freq));
SCORE_TABLE[i][j] = intFreq;
}