Add hysteresis movement key debouncing
When key is pressed, each key will have a halo which is 0.05 inch wider than the key. Bug: bug2517112 Change-Id: I1368ff4af5f5d230b8c2f0c05c3c27bdb89027aemain
parent
e55a9a170e
commit
e36bce042b
|
@ -27,4 +27,5 @@
|
||||||
will not go into extract (fullscreen) mode. -->
|
will not go into extract (fullscreen) mode. -->
|
||||||
<dimen name="max_height_for_fullscreen">2.5in</dimen>
|
<dimen name="max_height_for_fullscreen">2.5in</dimen>
|
||||||
<dimen name="key_text_size">22sp</dimen>
|
<dimen name="key_text_size">22sp</dimen>
|
||||||
|
<dimen name="key_debounce_hysteresis_distance">0.05in</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -332,12 +332,10 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener
|
||||||
private long mLastMoveTime;
|
private long mLastMoveTime;
|
||||||
private long mCurrentKeyTime;
|
private long mCurrentKeyTime;
|
||||||
|
|
||||||
private int mKeyDebounceThreshold;
|
private final int mKeyDebounceThresholdSquared;
|
||||||
private static final int KEY_DEBOUNCE_FACTOR = 6;
|
|
||||||
|
|
||||||
KeyDebouncer(int proximityThreshold) {
|
KeyDebouncer(float hysteresisPixel) {
|
||||||
// 1/KEY_DEBOUNCE_FACTOR of distance between adjacent keys
|
mKeyDebounceThresholdSquared = (int)(hysteresisPixel * hysteresisPixel);
|
||||||
mKeyDebounceThreshold = proximityThreshold / KEY_DEBOUNCE_FACTOR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLastCodeX() {
|
public int getLastCodeX() {
|
||||||
|
@ -375,15 +373,23 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener
|
||||||
mLastCodeY = mLastY;
|
mLastCodeY = mLastY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMinorMoveBounce(int x, int y, int keyIndex, int currentKey) {
|
public boolean isMinorMoveBounce(int x, int y, Key newKey, Key curKey) {
|
||||||
// TODO: Check the coordinate against each key border. The current
|
if (newKey == curKey)
|
||||||
// logic is pretty simple.
|
|
||||||
if (keyIndex == currentKey)
|
|
||||||
return true;
|
return true;
|
||||||
int dx = x - mLastCodeX;
|
|
||||||
int dy = y - mLastCodeY;
|
return getSquareDistanceToKeyEdge(x, y, curKey) < mKeyDebounceThresholdSquared;
|
||||||
int delta = dx * dx + dy * dy;
|
}
|
||||||
return delta < mKeyDebounceThreshold;
|
|
||||||
|
private static int getSquareDistanceToKeyEdge(int x, int y, Key key) {
|
||||||
|
final int left = key.x;
|
||||||
|
final int right = key.x + key.width;
|
||||||
|
final int top = key.y;
|
||||||
|
final int bottom = key.y + key.height;
|
||||||
|
final int edgeX = x < left ? left : (x > right ? right : x);
|
||||||
|
final int edgeY = y < top ? top : (y > bottom ? bottom : y);
|
||||||
|
final int dx = x - edgeX;
|
||||||
|
final int dy = y - edgeY;
|
||||||
|
return dx * dx + dy * dy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startTimeDebouncing(long eventTime) {
|
public void startTimeDebouncing(long eventTime) {
|
||||||
|
@ -766,7 +772,9 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener
|
||||||
mProximityThreshold = (int) (dimensionSum * 1.4f / length);
|
mProximityThreshold = (int) (dimensionSum * 1.4f / length);
|
||||||
mProximityThreshold *= mProximityThreshold; // Square it
|
mProximityThreshold *= mProximityThreshold; // Square it
|
||||||
|
|
||||||
mDebouncer = new KeyDebouncer(mProximityThreshold);
|
final float hysteresisPixel = getContext().getResources()
|
||||||
|
.getDimension(R.dimen.key_debounce_hysteresis_distance);
|
||||||
|
mDebouncer = new KeyDebouncer(hysteresisPixel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1354,8 +1362,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,
|
} else if (mDebouncer.isMinorMoveBounce(touchX, touchY, mKeys[keyIndex],
|
||||||
keyIndex, mCurrentKey)) {
|
mKeys[mCurrentKey])) {
|
||||||
mDebouncer.updateTimeDebouncing(eventTime);
|
mDebouncer.updateTimeDebouncing(eventTime);
|
||||||
continueLongPress = true;
|
continueLongPress = true;
|
||||||
} else if (mRepeatKeyIndex == NOT_A_KEY) {
|
} else if (mRepeatKeyIndex == NOT_A_KEY) {
|
||||||
|
|
Loading…
Reference in New Issue