Merge "Fix NPE introduced by Change-Id: Ie482167b2ae2804fa1aa43ffb5067af47b7553f1"

main
Tadashi G. Takaoka 2010-07-29 11:38:29 -07:00 committed by Android (Google) Code Review
commit bc305c21bf
1 changed files with 16 additions and 10 deletions

View File

@ -320,6 +320,8 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener
}; };
static class KeyDebouncer { static class KeyDebouncer {
private Key[] mKeys;
// for move de-bouncing // for move de-bouncing
private int mLastCodeX; private int mLastCodeX;
private int mLastCodeY; private int mLastCodeY;
@ -334,7 +336,8 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener
private final int mKeyDebounceThresholdSquared; private final int mKeyDebounceThresholdSquared;
KeyDebouncer(float hysteresisPixel) { KeyDebouncer(Key[] keys, float hysteresisPixel) {
mKeys = keys;
mKeyDebounceThresholdSquared = (int)(hysteresisPixel * hysteresisPixel); mKeyDebounceThresholdSquared = (int)(hysteresisPixel * hysteresisPixel);
} }
@ -373,11 +376,15 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener
mLastCodeY = mLastY; mLastCodeY = mLastY;
} }
public boolean isMinorMoveBounce(int x, int y, Key newKey, Key curKey) { public boolean isMinorMoveBounce(int x, int y, int newKey, int curKey) {
if (newKey == curKey) if (newKey == curKey) {
return true; return true;
} else if (curKey == NOT_A_KEY) {
return getSquareDistanceToKeyEdge(x, y, curKey) < mKeyDebounceThresholdSquared; return false;
} else {
return getSquareDistanceToKeyEdge(x, y, mKeys[curKey])
< mKeyDebounceThresholdSquared;
}
} }
private static int getSquareDistanceToKeyEdge(int x, int y, Key key) { private static int getSquareDistanceToKeyEdge(int x, int y, Key key) {
@ -774,7 +781,7 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener
final float hysteresisPixel = getContext().getResources() final float hysteresisPixel = getContext().getResources()
.getDimension(R.dimen.key_debounce_hysteresis_distance); .getDimension(R.dimen.key_debounce_hysteresis_distance);
mDebouncer = new KeyDebouncer(hysteresisPixel); mDebouncer = new KeyDebouncer(keys, hysteresisPixel);
} }
@Override @Override
@ -1368,8 +1375,8 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener
if (mCurrentKey == NOT_A_KEY) { if (mCurrentKey == NOT_A_KEY) {
mCurrentKey = keyIndex; mCurrentKey = keyIndex;
mDebouncer.updateTimeDebouncing(eventTime); mDebouncer.updateTimeDebouncing(eventTime);
} else if (mDebouncer.isMinorMoveBounce(touchX, touchY, mKeys[keyIndex], } else if (mDebouncer.isMinorMoveBounce(touchX, touchY, keyIndex,
mKeys[mCurrentKey])) { mCurrentKey)) {
mDebouncer.updateTimeDebouncing(eventTime); mDebouncer.updateTimeDebouncing(eventTime);
continueLongPress = true; continueLongPress = true;
} else if (mRepeatKeyIndex == NOT_A_KEY) { } else if (mRepeatKeyIndex == NOT_A_KEY) {
@ -1398,8 +1405,7 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener
case MotionEvent.ACTION_UP: case MotionEvent.ACTION_UP:
mHandler.cancelKeyTimersAndPopupPreview(); mHandler.cancelKeyTimersAndPopupPreview();
if (mDebouncer.isMinorMoveBounce(touchX, touchY, mKeys[keyIndex], if (mDebouncer.isMinorMoveBounce(touchX, touchY, keyIndex, mCurrentKey)) {
mKeys[mCurrentKey])) {
mDebouncer.updateTimeDebouncing(eventTime); mDebouncer.updateTimeDebouncing(eventTime);
} else { } else {
resetMultiTap(); resetMultiTap();