am f7d71c33: Merge "Refactor PointerTracker to add isValidKeyIndex() predicate." into gingerbread
Merge commit 'f7d71c338f2585810ca2da95e7aee5c166b06ac2' into gingerbread-plus-aosp * commit 'f7d71c338f2585810ca2da95e7aee5c166b06ac2': Refactor PointerTracker to add isValidKeyIndex() predicate.main
commit
d8417f1cfe
|
@ -100,21 +100,25 @@ public class PointerTracker {
|
|||
mKeyDebounceThresholdSquared = (int)(hysteresisPixel * hysteresisPixel);
|
||||
}
|
||||
|
||||
private boolean isValidKeyIndex(int keyIndex) {
|
||||
return keyIndex >= 0 && keyIndex < mKeys.length;
|
||||
}
|
||||
|
||||
public Key getKey(int keyIndex) {
|
||||
return (keyIndex >= 0 && keyIndex < mKeys.length) ? mKeys[keyIndex] : null;
|
||||
return isValidKeyIndex(keyIndex) ? mKeys[keyIndex] : null;
|
||||
}
|
||||
|
||||
public void updateKey(int keyIndex) {
|
||||
int oldKeyIndex = mPreviousKey;
|
||||
mPreviousKey = keyIndex;
|
||||
if (keyIndex != oldKeyIndex) {
|
||||
if (oldKeyIndex != NOT_A_KEY && oldKeyIndex < mKeys.length) {
|
||||
if (isValidKeyIndex(oldKeyIndex)) {
|
||||
// if new key index is not a key, old key was just released inside of the key.
|
||||
final boolean inside = (keyIndex == NOT_A_KEY);
|
||||
mKeys[oldKeyIndex].onReleased(inside);
|
||||
mProxy.invalidateKey(mKeys[oldKeyIndex]);
|
||||
}
|
||||
if (keyIndex != NOT_A_KEY && keyIndex < mKeys.length) {
|
||||
if (isValidKeyIndex(keyIndex)) {
|
||||
mKeys[keyIndex].onPressed();
|
||||
mProxy.invalidateKey(mKeys[keyIndex]);
|
||||
}
|
||||
|
@ -130,14 +134,14 @@ public class PointerTracker {
|
|||
startTimeDebouncing(eventTime);
|
||||
checkMultiTap(eventTime, keyIndex);
|
||||
if (mListener != null) {
|
||||
int primaryCode = (keyIndex != NOT_A_KEY) ? mKeys[keyIndex].codes[0] : 0;
|
||||
int primaryCode = isValidKeyIndex(keyIndex) ? mKeys[keyIndex].codes[0] : 0;
|
||||
mListener.onPress(primaryCode);
|
||||
}
|
||||
if (keyIndex >= 0 && mKeys[keyIndex].repeatable) {
|
||||
repeatKey(keyIndex);
|
||||
mHandler.startKeyRepeatTimer(REPEAT_START_DELAY, keyIndex, this);
|
||||
}
|
||||
if (keyIndex != NOT_A_KEY) {
|
||||
if (isValidKeyIndex(keyIndex)) {
|
||||
if (mKeys[keyIndex].repeatable) {
|
||||
repeatKey(keyIndex);
|
||||
mHandler.startKeyRepeatTimer(REPEAT_START_DELAY, keyIndex, this);
|
||||
}
|
||||
mHandler.startLongPressTimer(keyIndex, LONGPRESS_TIMEOUT);
|
||||
}
|
||||
showKeyPreviewAndUpdateKey(keyIndex);
|
||||
|
@ -146,7 +150,7 @@ public class PointerTracker {
|
|||
|
||||
public void onMoveEvent(int touchX, int touchY, long eventTime) {
|
||||
int keyIndex = mKeyDetector.getKeyIndexAndNearbyCodes(touchX, touchY, null);
|
||||
if (keyIndex != NOT_A_KEY) {
|
||||
if (isValidKeyIndex(keyIndex)) {
|
||||
if (mCurrentKey == NOT_A_KEY) {
|
||||
updateTimeDebouncing(eventTime);
|
||||
mCurrentKey = keyIndex;
|
||||
|
@ -195,7 +199,7 @@ public class PointerTracker {
|
|||
if (!wasInKeyRepeat && !mProxy.isMiniKeyboardOnScreen()) {
|
||||
detectAndSendKey(mCurrentKey, touchX, touchY, eventTime);
|
||||
}
|
||||
if (keyIndex != NOT_A_KEY && keyIndex < mKeys.length)
|
||||
if (isValidKeyIndex(keyIndex))
|
||||
mProxy.invalidateKey(mKeys[keyIndex]);
|
||||
}
|
||||
|
||||
|
@ -205,15 +209,17 @@ public class PointerTracker {
|
|||
mProxy.dismissPopupKeyboard();
|
||||
showKeyPreviewAndUpdateKey(NOT_A_KEY);
|
||||
int keyIndex = mCurrentKey;
|
||||
if (keyIndex != NOT_A_KEY && keyIndex < mKeys.length)
|
||||
if (isValidKeyIndex(keyIndex))
|
||||
mProxy.invalidateKey(mKeys[keyIndex]);
|
||||
}
|
||||
|
||||
public void repeatKey(int keyIndex) {
|
||||
Key key = mKeys[keyIndex];
|
||||
// While key is repeating, because there is no need to handle multi-tap key, we can pass
|
||||
// -1 as eventTime argument.
|
||||
detectAndSendKey(keyIndex, key.x, key.y, -1);
|
||||
Key key = getKey(keyIndex);
|
||||
if (key != null) {
|
||||
// While key is repeating, because there is no need to handle multi-tap key, we can
|
||||
// pass -1 as eventTime argument.
|
||||
detectAndSendKey(keyIndex, key.x, key.y, -1);
|
||||
}
|
||||
}
|
||||
|
||||
// These package scope methods are only for debugging purpose.
|
||||
|
@ -253,7 +259,7 @@ public class PointerTracker {
|
|||
throw new IllegalStateException("keyboard and/or hysteresis not set");
|
||||
if (newKey == curKey) {
|
||||
return true;
|
||||
} else if (curKey >= 0 && curKey < mKeys.length) {
|
||||
} else if (isValidKeyIndex(curKey)) {
|
||||
return getSquareDistanceToKeyEdge(x, y, mKeys[curKey])
|
||||
< mKeyDebounceThresholdSquared;
|
||||
} else {
|
||||
|
@ -303,7 +309,7 @@ public class PointerTracker {
|
|||
}
|
||||
|
||||
private void detectAndSendKey(int index, int x, int y, long eventTime) {
|
||||
if (index != NOT_A_KEY && index < mKeys.length) {
|
||||
if (isValidKeyIndex(index)) {
|
||||
final Key key = mKeys[index];
|
||||
OnKeyboardActionListener listener = mListener;
|
||||
if (key.text != null) {
|
||||
|
@ -366,11 +372,15 @@ public class PointerTracker {
|
|||
}
|
||||
|
||||
private void checkMultiTap(long eventTime, int keyIndex) {
|
||||
if (keyIndex == NOT_A_KEY) return;
|
||||
Key key = mKeys[keyIndex];
|
||||
Key key = getKey(keyIndex);
|
||||
if (key == null)
|
||||
return;
|
||||
|
||||
final boolean isMultiTap =
|
||||
(eventTime < mLastTapTime + MULTITAP_INTERVAL && keyIndex == mLastSentIndex);
|
||||
if (key.codes.length > 1) {
|
||||
mInMultiTap = true;
|
||||
if (eventTime < mLastTapTime + MULTITAP_INTERVAL && keyIndex == mLastSentIndex) {
|
||||
if (isMultiTap) {
|
||||
mTapCount = (mTapCount + 1) % key.codes.length;
|
||||
return;
|
||||
} else {
|
||||
|
@ -378,7 +388,7 @@ public class PointerTracker {
|
|||
return;
|
||||
}
|
||||
}
|
||||
if (eventTime > mLastTapTime + MULTITAP_INTERVAL || keyIndex != mLastSentIndex) {
|
||||
if (!isMultiTap) {
|
||||
resetMultiTap();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue