aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod')
-rw-r--r--java/src/com/android/inputmethod/keyboard/ProximityInfo.java32
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/TouchPositionCorrection.java6
2 files changed, 21 insertions, 17 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
index 6e138946f..06a9e9252 100644
--- a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
+++ b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
@@ -25,15 +25,15 @@ import com.android.inputmethod.latin.JniUtils;
import java.util.Arrays;
-public class ProximityInfo {
+public final class ProximityInfo {
/** MAX_PROXIMITY_CHARS_SIZE must be the same as MAX_PROXIMITY_CHARS_SIZE_INTERNAL
* in defines.h */
public static final int MAX_PROXIMITY_CHARS_SIZE = 16;
/** Number of key widths from current touch point to search for nearest keys. */
private static float SEARCH_DISTANCE = 1.2f;
private static final Key[] EMPTY_KEY_ARRAY = new Key[0];
+ private static final float DEFAULT_TOUCH_POSITION_CORRECTION_RADIUS = 0.15f;
- private final int mKeyHeight;
private final int mGridWidth;
private final int mGridHeight;
private final int mGridSize;
@@ -43,6 +43,7 @@ public class ProximityInfo {
private final int mKeyboardMinWidth;
private final int mKeyboardHeight;
private final int mMostCommonKeyWidth;
+ private final int mMostCommonKeyHeight;
private final Key[] mKeys;
private final Key[][] mGridNeighbors;
private final String mLocaleStr;
@@ -63,7 +64,7 @@ public class ProximityInfo {
mCellHeight = (height + mGridHeight - 1) / mGridHeight;
mKeyboardMinWidth = minWidth;
mKeyboardHeight = height;
- mKeyHeight = mostCommonKeyHeight;
+ mMostCommonKeyHeight = mostCommonKeyHeight;
mMostCommonKeyWidth = mostCommonKeyWidth;
mKeys = keys;
mGridNeighbors = new Key[mGridSize][];
@@ -142,22 +143,22 @@ public class ProximityInfo {
sweetSpotCenterXs = new float[keyCount];
sweetSpotCenterYs = new float[keyCount];
sweetSpotRadii = new float[keyCount];
+ final float defaultRadius = DEFAULT_TOUCH_POSITION_CORRECTION_RADIUS
+ * (float)Math.hypot(mMostCommonKeyWidth, mMostCommonKeyHeight);
for (int i = 0; i < keyCount; i++) {
final Key key = keys[i];
final Rect hitBox = key.mHitBox;
- final int row = hitBox.top / mKeyHeight;
+ sweetSpotCenterXs[i] = hitBox.exactCenterX();
+ sweetSpotCenterYs[i] = hitBox.exactCenterY();
+ sweetSpotRadii[i] = defaultRadius;
+ final int row = hitBox.top / mMostCommonKeyHeight;
if (row < touchPositionCorrection.getRows()) {
final int hitBoxWidth = hitBox.width();
final int hitBoxHeight = hitBox.height();
- final float x = touchPositionCorrection.getX(row);
- final float y = touchPositionCorrection.getY(row);
- final float radius = touchPositionCorrection.getRadius(row);
- sweetSpotCenterXs[i] = hitBox.exactCenterX() + x * hitBoxWidth;
- sweetSpotCenterYs[i] = hitBox.exactCenterY() + y * hitBoxHeight;
- // 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);
+ final float hitBoxDiagonal = (float)Math.hypot(hitBoxWidth, hitBoxHeight);
+ sweetSpotCenterXs[i] += touchPositionCorrection.getX(row) * hitBoxWidth;
+ sweetSpotCenterYs[i] += touchPositionCorrection.getY(row) * hitBoxHeight;
+ sweetSpotRadii[i] = touchPositionCorrection.getRadius(row) * hitBoxDiagonal;
}
}
} else {
@@ -213,7 +214,8 @@ public class ProximityInfo {
}
}
- public void fillArrayWithNearestKeyCodes(int x, int y, int primaryKeyCode, int[] dest) {
+ public void fillArrayWithNearestKeyCodes(final int x, final int y, final int primaryKeyCode,
+ final int[] dest) {
final int destLength = dest.length;
if (destLength < 1) {
return;
@@ -238,7 +240,7 @@ public class ProximityInfo {
}
}
- public Key[] getNearestKeys(int x, int y) {
+ public Key[] getNearestKeys(final int x, final int y) {
if (mGridNeighbors == null) {
return EMPTY_KEY_ARRAY;
}
diff --git a/java/src/com/android/inputmethod/keyboard/internal/TouchPositionCorrection.java b/java/src/com/android/inputmethod/keyboard/internal/TouchPositionCorrection.java
index 811a620b3..d8950a713 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/TouchPositionCorrection.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/TouchPositionCorrection.java
@@ -18,7 +18,7 @@ package com.android.inputmethod.keyboard.internal;
import com.android.inputmethod.latin.LatinImeLogger;
-public class TouchPositionCorrection {
+public final class TouchPositionCorrection {
private static final int TOUCH_POSITION_CORRECTION_RECORD_SIZE = 3;
private boolean mEnabled;
@@ -80,7 +80,9 @@ public class TouchPositionCorrection {
}
public float getX(final int row) {
- return mXs[row];
+ return 0.0f;
+ // Touch position correction data for X coordinate is obsolete.
+ // return mXs[row];
}
public float getY(final int row) {