diff --git a/java/res/values/attrs.xml b/java/res/values/attrs.xml
index 2a7632124..34ce527f1 100644
--- a/java/res/values/attrs.xml
+++ b/java/res/values/attrs.xml
@@ -34,7 +34,9 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+ - 0.0091285
+ - 0.1193203
+ - 0.1622607
+
+
+ - -0.0233128
+ - 0.1379798
+ - 0.1585229
+
+
+ - -0.0080185
+ - 0.1911477
+ - 0.1570948
+
+
+
+
+ - 0.0038756
+ - -0.0005677
+ - 0.1577026
+
+
+ - -0.0236678
+ - 0.0381731
+ - 0.1529972
+
+
+ - -0.0086827
+ - 0.0880847
+ - 0.1522819
+
+
\ No newline at end of file
diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java
index 045f0d7b2..f77155ee3 100644
--- a/java/src/com/android/inputmethod/keyboard/Keyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java
@@ -138,7 +138,8 @@ public class Keyboard {
mProximityInfo = new ProximityInfo(
params.GRID_WIDTH, params.GRID_HEIGHT, mOccupiedWidth, mOccupiedHeight,
- mMostCommonKeyWidth, mKeys);
+ mMostCommonKeyWidth, mKeys, params.mTouchPositionCorrectionXs,
+ params.mTouchPositionCorrectionYs, params.mTouchPositionCorrectionRadii);
}
public ProximityInfo getProximityInfo() {
diff --git a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
index 71b46d646..210ab48a1 100644
--- a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
+++ b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java
@@ -40,8 +40,13 @@ public class ProximityInfo {
private final int mKeyboardHeight;
private final int[][] mGridNeighbors;
- ProximityInfo(
- int gridWidth, int gridHeight, int minWidth, int height, int keyWidth, List keys) {
+ private final float[] mTouchPositionCorrectionXs;
+ private final float[] mTouchPositionCorrectionYs;
+ private final float[] mTouchPositionCorrectionRadii;
+
+ ProximityInfo(int gridWidth, int gridHeight, int minWidth, int height, int keyWidth,
+ List keys, float[] touchPositionCorrectionXs, float[] touchPositionCorrectionYs,
+ float[] touchPositionCorrectionRadii) {
mGridWidth = gridWidth;
mGridHeight = gridHeight;
mGridSize = mGridWidth * mGridHeight;
@@ -49,6 +54,9 @@ public class ProximityInfo {
mCellHeight = (height + mGridHeight - 1) / mGridHeight;
mKeyboardMinWidth = minWidth;
mKeyboardHeight = height;
+ mTouchPositionCorrectionXs = touchPositionCorrectionXs;
+ mTouchPositionCorrectionYs = touchPositionCorrectionYs;
+ mTouchPositionCorrectionRadii = touchPositionCorrectionRadii;
mGridNeighbors = new int[mGridSize][];
if (minWidth == 0 || height == 0) {
// No proximity required. Keyboard might be mini keyboard.
@@ -58,7 +66,7 @@ public class ProximityInfo {
}
public static ProximityInfo createDummyProximityInfo() {
- return new ProximityInfo(1, 1, 1, 1, 1, Collections.emptyList());
+ return new ProximityInfo(1, 1, 1, 1, 1, Collections.emptyList(), null, null, null);
}
public static ProximityInfo createSpellCheckerProximityInfo() {
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
index 187a1adcb..46836da67 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
@@ -30,6 +30,7 @@ import com.android.inputmethod.compat.EditorInfoCompatUtils;
import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardId;
+import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.R;
import org.xmlpull.v1.XmlPullParser;
@@ -126,6 +127,8 @@ public class KeyboardBuilder {
private static final int DEFAULT_KEYBOARD_COLUMNS = 10;
private static final int DEFAULT_KEYBOARD_ROWS = 4;
+ private static final int TOUCH_POSITION_CORRECTION_RECORD_SIZE = 3;
+
protected final KP mParams;
protected final Context mContext;
protected final Resources mResources;
@@ -248,10 +251,62 @@ public class KeyboardBuilder {
mParams.mThemeId = a.getInt(R.styleable.KeyboardTheme_themeId, 0);
a.recycle();
+ if (!setTouchPositionCorrectionData(context)) {
+ // In the regression test, setTouchPositionCorrectionData() fails
+ mParams.mTouchPositionCorrectionXs = null;
+ mParams.mTouchPositionCorrectionYs = null;
+ mParams.mTouchPositionCorrectionRadii = null;
+ }
+
mParams.GRID_WIDTH = res.getInteger(R.integer.config_keyboard_grid_width);
mParams.GRID_HEIGHT = res.getInteger(R.integer.config_keyboard_grid_height);
}
+ private boolean setTouchPositionCorrectionData(Context context) {
+ final TypedArray a = context.obtainStyledAttributes(R.styleable.KeyboardTheme);
+ final int resourceId = a.getResourceId(
+ R.styleable.KeyboardTheme_touchPositionCorrectionData, 0);
+ if (resourceId == 0) {
+ // In the regression test, we cannot use theme resources
+ // TODO: Fix this
+ return false;
+ }
+ final String[] data = context.getResources().getStringArray(resourceId);
+ a.recycle();
+ final int dataLength = data.length;
+ if (dataLength % TOUCH_POSITION_CORRECTION_RECORD_SIZE != 0) {
+ if (LatinImeLogger.sDBG) {
+ throw new RuntimeException("the size of touch position correction data is invalid");
+ }
+ return false;
+ }
+ final int length = dataLength / TOUCH_POSITION_CORRECTION_RECORD_SIZE;
+ mParams.mTouchPositionCorrectionXs = new float[length];
+ mParams.mTouchPositionCorrectionYs = new float[length];
+ mParams.mTouchPositionCorrectionRadii = new float[length];
+ try {
+ for (int i = 0; i < dataLength; ++i) {
+ final int type = i % TOUCH_POSITION_CORRECTION_RECORD_SIZE;
+ final int index = i / TOUCH_POSITION_CORRECTION_RECORD_SIZE;
+ final float value = Float.parseFloat(data[i]);
+ if (type == 0) {
+ mParams.mTouchPositionCorrectionXs[index] = value;
+ } else if (type == 1) {
+ mParams.mTouchPositionCorrectionYs[index] = value;
+ } else {
+ mParams.mTouchPositionCorrectionRadii[index] = value;
+ }
+ }
+ } catch (NumberFormatException e) {
+ if (LatinImeLogger.sDBG) {
+ throw new RuntimeException(
+ "the number format for touch position correction data is invalid");
+ }
+ return false;
+ }
+ return true;
+ }
+
public KeyboardBuilder load(KeyboardId id) {
mParams.mId = id;
try {
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java
index 97f58fad2..d1aea72a5 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardParams.java
@@ -68,6 +68,10 @@ public class KeyboardParams {
public int mMostCommonKeyHeight = 0;
public int mMostCommonKeyWidth = 0;
+ public float[] mTouchPositionCorrectionXs;
+ public float[] mTouchPositionCorrectionYs;
+ public float[] mTouchPositionCorrectionRadii;
+
protected void clearKeys() {
mKeys.clear();
mShiftKeys.clear();