am 10d76cdc: Merge "Fix touch position correction data passing" into jb-mr1-dev

* commit '10d76cdcd6fe08c6df01d6f72f58e1215836000e':
  Fix touch position correction data passing
main
Tadashi G. Takaoka 2012-09-24 22:28:30 -07:00 committed by Android Git Automerger
commit 4156a11d35
4 changed files with 41 additions and 24 deletions

View File

@ -96,7 +96,7 @@ public class KeyboardLayoutSet {
String mKeyboardLayoutSetName; String mKeyboardLayoutSetName;
int mMode; int mMode;
EditorInfo mEditorInfo; EditorInfo mEditorInfo;
boolean mTouchPositionCorrectionEnabled; boolean mDisableTouchPositionCorrectionDataForTest;
boolean mVoiceKeyEnabled; boolean mVoiceKeyEnabled;
boolean mVoiceKeyOnMain; boolean mVoiceKeyOnMain;
boolean mNoSettingsKey; boolean mNoSettingsKey;
@ -167,7 +167,9 @@ public class KeyboardLayoutSet {
} }
final int keyboardXmlId = elementParams.mKeyboardXmlId; final int keyboardXmlId = elementParams.mKeyboardXmlId;
builder.load(keyboardXmlId, id); builder.load(keyboardXmlId, id);
builder.setTouchPositionCorrectionEnabled(mParams.mTouchPositionCorrectionEnabled); if (mParams.mDisableTouchPositionCorrectionDataForTest) {
builder.disableTouchPositionCorrectionDataForTest();
}
builder.setProximityCharsCorrectionEnabled( builder.setProximityCharsCorrectionEnabled(
elementParams.mProximityCharsCorrectionEnabled); elementParams.mProximityCharsCorrectionEnabled);
keyboard = builder.build(); keyboard = builder.build();
@ -264,8 +266,9 @@ public class KeyboardLayoutSet {
return this; return this;
} }
public void setTouchPositionCorrectionEnabled(final boolean enabled) { // For test only
mParams.mTouchPositionCorrectionEnabled = enabled; public void disableTouchPositionCorrectionDataForTest() {
mParams.mDisableTouchPositionCorrectionDataForTest = true;
} }
public KeyboardLayoutSet build() { public KeyboardLayoutSet build() {

View File

@ -44,7 +44,6 @@ public class ProximityInfo {
private final int mKeyboardHeight; private final int mKeyboardHeight;
private final int mMostCommonKeyWidth; private final int mMostCommonKeyWidth;
private final Key[] mKeys; private final Key[] mKeys;
private final TouchPositionCorrection mTouchPositionCorrection;
private final Key[][] mGridNeighbors; private final Key[][] mGridNeighbors;
private final String mLocaleStr; private final String mLocaleStr;
@ -67,14 +66,13 @@ public class ProximityInfo {
mKeyHeight = mostCommonKeyHeight; mKeyHeight = mostCommonKeyHeight;
mMostCommonKeyWidth = mostCommonKeyWidth; mMostCommonKeyWidth = mostCommonKeyWidth;
mKeys = keys; mKeys = keys;
mTouchPositionCorrection = touchPositionCorrection;
mGridNeighbors = new Key[mGridSize][]; mGridNeighbors = new Key[mGridSize][];
if (minWidth == 0 || height == 0) { if (minWidth == 0 || height == 0) {
// No proximity required. Keyboard might be more keys keyboard. // No proximity required. Keyboard might be more keys keyboard.
return; return;
} }
computeNearestNeighbors(); computeNearestNeighbors();
mNativeProximityInfo = createNativeProximityInfo(); mNativeProximityInfo = createNativeProximityInfo(touchPositionCorrection);
} }
public static ProximityInfo createDummyProximityInfo() { public static ProximityInfo createDummyProximityInfo() {
@ -106,12 +104,12 @@ public class ProximityInfo {
private native void releaseProximityInfoNative(long nativeProximityInfo); private native void releaseProximityInfoNative(long nativeProximityInfo);
private final long createNativeProximityInfo() { private final long createNativeProximityInfo(
final TouchPositionCorrection touchPositionCorrection) {
final Key[][] gridNeighborKeys = mGridNeighbors; final Key[][] gridNeighborKeys = mGridNeighbors;
final int keyboardWidth = mKeyboardMinWidth; final int keyboardWidth = mKeyboardMinWidth;
final int keyboardHeight = mKeyboardHeight; final int keyboardHeight = mKeyboardHeight;
final Key[] keys = mKeys; final Key[] keys = mKeys;
final TouchPositionCorrection touchPositionCorrection = mTouchPositionCorrection;
final int[] proximityCharsArray = new int[mGridSize * MAX_PROXIMITY_CHARS_SIZE]; final int[] proximityCharsArray = new int[mGridSize * MAX_PROXIMITY_CHARS_SIZE];
Arrays.fill(proximityCharsArray, Constants.NOT_A_CODE); Arrays.fill(proximityCharsArray, Constants.NOT_A_CODE);
for (int i = 0; i < mGridSize; ++i) { for (int i = 0; i < mGridSize; ++i) {
@ -148,12 +146,12 @@ public class ProximityInfo {
final Key key = keys[i]; final Key key = keys[i];
final Rect hitBox = key.mHitBox; final Rect hitBox = key.mHitBox;
final int row = hitBox.top / mKeyHeight; final int row = hitBox.top / mKeyHeight;
if (row < touchPositionCorrection.mRadii.length) { if (row < touchPositionCorrection.getRows()) {
final int hitBoxWidth = hitBox.width(); final int hitBoxWidth = hitBox.width();
final int hitBoxHeight = hitBox.height(); final int hitBoxHeight = hitBox.height();
final float x = touchPositionCorrection.mXs[row]; final float x = touchPositionCorrection.getX(row);
final float y = touchPositionCorrection.mYs[row]; final float y = touchPositionCorrection.getY(row);
final float radius = touchPositionCorrection.mRadii[row]; final float radius = touchPositionCorrection.getRadius(row);
sweetSpotCenterXs[i] = hitBox.exactCenterX() + x * hitBoxWidth; sweetSpotCenterXs[i] = hitBox.exactCenterX() + x * hitBoxWidth;
sweetSpotCenterYs[i] = hitBox.exactCenterY() + y * hitBoxHeight; sweetSpotCenterYs[i] = hitBox.exactCenterY() + y * hitBoxHeight;
// Note that, in recent versions of Android, FloatMath is actually slower than // Note that, in recent versions of Android, FloatMath is actually slower than

View File

@ -177,9 +177,9 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
return this; return this;
} }
// TODO: Remove this method. // For test only
public void setTouchPositionCorrectionEnabled(final boolean enabled) { public void disableTouchPositionCorrectionDataForTest() {
mParams.mTouchPositionCorrection.setEnabled(enabled); mParams.mTouchPositionCorrection.setEnabled(false);
} }
public void setProximityCharsCorrectionEnabled(final boolean enabled) { public void setProximityCharsCorrectionEnabled(final boolean enabled) {
@ -314,7 +314,6 @@ public class KeyboardBuilder<KP extends KeyboardParams> {
final int resourceId = keyboardAttr.getResourceId( final int resourceId = keyboardAttr.getResourceId(
R.styleable.Keyboard_touchPositionCorrectionData, 0); R.styleable.Keyboard_touchPositionCorrectionData, 0);
params.mTouchPositionCorrection.setEnabled(resourceId != 0);
if (resourceId != 0) { if (resourceId != 0) {
final String[] data = mResources.getStringArray(resourceId); final String[] data = mResources.getStringArray(resourceId);
params.mTouchPositionCorrection.load(data); params.mTouchPositionCorrection.load(data);

View File

@ -21,10 +21,10 @@ import com.android.inputmethod.latin.LatinImeLogger;
public class TouchPositionCorrection { public class TouchPositionCorrection {
private static final int TOUCH_POSITION_CORRECTION_RECORD_SIZE = 3; private static final int TOUCH_POSITION_CORRECTION_RECORD_SIZE = 3;
public boolean mEnabled; private boolean mEnabled;
public float[] mXs; private float[] mXs;
public float[] mYs; private float[] mYs;
public float[] mRadii; private float[] mRadii;
public void load(final String[] data) { public void load(final String[] data) {
final int dataLength = data.length; final int dataLength = data.length;
@ -53,24 +53,41 @@ public class TouchPositionCorrection {
mRadii[index] = value; mRadii[index] = value;
} }
} }
mEnabled = dataLength > 0;
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
if (LatinImeLogger.sDBG) { if (LatinImeLogger.sDBG) {
throw new RuntimeException( throw new RuntimeException(
"the number format for touch position correction data is invalid"); "the number format for touch position correction data is invalid");
} }
mEnabled = false;
mXs = null; mXs = null;
mYs = null; mYs = null;
mRadii = null; mRadii = null;
} }
} }
// TODO: Remove this method. // For test only
public void setEnabled(final boolean enabled) { public void setEnabled(final boolean enabled) {
mEnabled = enabled; mEnabled = enabled;
} }
public boolean isValid() { public boolean isValid() {
return mEnabled && mXs != null && mYs != null && mRadii != null return mEnabled;
&& mXs.length > 0 && mYs.length > 0 && mRadii.length > 0; }
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];
} }
} }