From 6ca50d99208efdbcad96b3260fe7592bf95a6b00 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 25 Sep 2012 11:58:36 +0900 Subject: [PATCH] Fix touch position correction data passing Bug: 7225811 Change-Id: I3dcc0385ed633585d6810fdb742e0f88c2efbbd2 --- .../keyboard/KeyboardLayoutSet.java | 11 ++++--- .../inputmethod/keyboard/ProximityInfo.java | 16 +++++----- .../keyboard/internal/KeyboardBuilder.java | 7 ++--- .../internal/TouchPositionCorrection.java | 31 ++++++++++++++----- 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java index aaccf63ba..d97df7491 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java @@ -96,7 +96,7 @@ public class KeyboardLayoutSet { String mKeyboardLayoutSetName; int mMode; EditorInfo mEditorInfo; - boolean mTouchPositionCorrectionEnabled; + boolean mDisableTouchPositionCorrectionDataForTest; boolean mVoiceKeyEnabled; boolean mVoiceKeyOnMain; boolean mNoSettingsKey; @@ -167,7 +167,9 @@ public class KeyboardLayoutSet { } final int keyboardXmlId = elementParams.mKeyboardXmlId; builder.load(keyboardXmlId, id); - builder.setTouchPositionCorrectionEnabled(mParams.mTouchPositionCorrectionEnabled); + if (mParams.mDisableTouchPositionCorrectionDataForTest) { + builder.disableTouchPositionCorrectionDataForTest(); + } builder.setProximityCharsCorrectionEnabled( elementParams.mProximityCharsCorrectionEnabled); keyboard = builder.build(); @@ -264,8 +266,9 @@ public class KeyboardLayoutSet { return this; } - public void setTouchPositionCorrectionEnabled(final boolean enabled) { - mParams.mTouchPositionCorrectionEnabled = enabled; + // For test only + public void disableTouchPositionCorrectionDataForTest() { + mParams.mDisableTouchPositionCorrectionDataForTest = true; } public KeyboardLayoutSet build() { diff --git a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java index e1b082c16..6e138946f 100644 --- a/java/src/com/android/inputmethod/keyboard/ProximityInfo.java +++ b/java/src/com/android/inputmethod/keyboard/ProximityInfo.java @@ -44,7 +44,6 @@ public class ProximityInfo { private final int mKeyboardHeight; private final int mMostCommonKeyWidth; private final Key[] mKeys; - private final TouchPositionCorrection mTouchPositionCorrection; private final Key[][] mGridNeighbors; private final String mLocaleStr; @@ -67,14 +66,13 @@ public class ProximityInfo { mKeyHeight = mostCommonKeyHeight; mMostCommonKeyWidth = mostCommonKeyWidth; mKeys = keys; - mTouchPositionCorrection = touchPositionCorrection; mGridNeighbors = new Key[mGridSize][]; if (minWidth == 0 || height == 0) { // No proximity required. Keyboard might be more keys keyboard. return; } computeNearestNeighbors(); - mNativeProximityInfo = createNativeProximityInfo(); + mNativeProximityInfo = createNativeProximityInfo(touchPositionCorrection); } public static ProximityInfo createDummyProximityInfo() { @@ -106,12 +104,12 @@ public class ProximityInfo { private native void releaseProximityInfoNative(long nativeProximityInfo); - private final long createNativeProximityInfo() { + private final long createNativeProximityInfo( + final TouchPositionCorrection touchPositionCorrection) { final Key[][] gridNeighborKeys = mGridNeighbors; final int keyboardWidth = mKeyboardMinWidth; final int keyboardHeight = mKeyboardHeight; final Key[] keys = mKeys; - final TouchPositionCorrection touchPositionCorrection = mTouchPositionCorrection; final int[] proximityCharsArray = new int[mGridSize * MAX_PROXIMITY_CHARS_SIZE]; Arrays.fill(proximityCharsArray, Constants.NOT_A_CODE); for (int i = 0; i < mGridSize; ++i) { @@ -148,12 +146,12 @@ public class ProximityInfo { final Key key = keys[i]; final Rect hitBox = key.mHitBox; final int row = hitBox.top / mKeyHeight; - if (row < touchPositionCorrection.mRadii.length) { + if (row < touchPositionCorrection.getRows()) { final int hitBoxWidth = hitBox.width(); final int hitBoxHeight = hitBox.height(); - final float x = touchPositionCorrection.mXs[row]; - final float y = touchPositionCorrection.mYs[row]; - final float radius = touchPositionCorrection.mRadii[row]; + 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 diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java index 31c7cb565..b314a3795 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java @@ -177,9 +177,9 @@ public class KeyboardBuilder { return this; } - // TODO: Remove this method. - public void setTouchPositionCorrectionEnabled(final boolean enabled) { - mParams.mTouchPositionCorrection.setEnabled(enabled); + // For test only + public void disableTouchPositionCorrectionDataForTest() { + mParams.mTouchPositionCorrection.setEnabled(false); } public void setProximityCharsCorrectionEnabled(final boolean enabled) { @@ -314,7 +314,6 @@ public class KeyboardBuilder { final int resourceId = keyboardAttr.getResourceId( R.styleable.Keyboard_touchPositionCorrectionData, 0); - params.mTouchPositionCorrection.setEnabled(resourceId != 0); if (resourceId != 0) { final String[] data = mResources.getStringArray(resourceId); params.mTouchPositionCorrection.load(data); diff --git a/java/src/com/android/inputmethod/keyboard/internal/TouchPositionCorrection.java b/java/src/com/android/inputmethod/keyboard/internal/TouchPositionCorrection.java index 69dc01cd6..811a620b3 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/TouchPositionCorrection.java +++ b/java/src/com/android/inputmethod/keyboard/internal/TouchPositionCorrection.java @@ -21,10 +21,10 @@ import com.android.inputmethod.latin.LatinImeLogger; public class TouchPositionCorrection { private static final int TOUCH_POSITION_CORRECTION_RECORD_SIZE = 3; - public boolean mEnabled; - public float[] mXs; - public float[] mYs; - public float[] mRadii; + private boolean mEnabled; + private float[] mXs; + private float[] mYs; + private float[] mRadii; public void load(final String[] data) { final int dataLength = data.length; @@ -53,24 +53,41 @@ public class TouchPositionCorrection { mRadii[index] = value; } } + mEnabled = dataLength > 0; } catch (NumberFormatException e) { if (LatinImeLogger.sDBG) { throw new RuntimeException( "the number format for touch position correction data is invalid"); } + mEnabled = false; mXs = null; mYs = null; mRadii = null; } } - // TODO: Remove this method. + // For test only public void setEnabled(final boolean enabled) { mEnabled = enabled; } public boolean isValid() { - return mEnabled && mXs != null && mYs != null && mRadii != null - && mXs.length > 0 && mYs.length > 0 && mRadii.length > 0; + return mEnabled; + } + + public int getRows() { + return mRadii.length; + } + + public float getX(final int row) { + return mXs[row]; + } + + public float getY(final int row) { + return mYs[row]; + } + + public float getRadius(final int row) { + return mRadii[row]; } }