Merge "Refactor onModifiedTouchEvent into several methods." into gingerbread
commit
830fd4af56
|
@ -214,8 +214,8 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener
|
||||||
|
|
||||||
// Variables for dealing with multiple pointers
|
// Variables for dealing with multiple pointers
|
||||||
private int mOldPointerCount = 1;
|
private int mOldPointerCount = 1;
|
||||||
private float mOldPointerX;
|
private int mOldPointerX;
|
||||||
private float mOldPointerY;
|
private int mOldPointerY;
|
||||||
|
|
||||||
private Drawable mKeyBackground;
|
private Drawable mKeyBackground;
|
||||||
|
|
||||||
|
@ -1215,14 +1215,21 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getTouchX(float x) {
|
||||||
|
return (int)x - getPaddingLeft();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getTouchY(float y) {
|
||||||
|
return (int)y + mVerticalCorrection - getPaddingTop();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent me) {
|
public boolean onTouchEvent(MotionEvent me) {
|
||||||
// Convert multi-pointer up/down events to single up/down events to
|
// Convert multi-pointer up/down events to single up/down events to
|
||||||
// deal with the typical multi-pointer behavior of two-thumb typing
|
// deal with the typical multi-pointer behavior of two-thumb typing
|
||||||
final int pointerCount = me.getPointerCount();
|
final int pointerCount = me.getPointerCount();
|
||||||
final int action = me.getAction();
|
final int action = me.getAction();
|
||||||
boolean result = false;
|
final long eventTime = me.getEventTime();
|
||||||
final long now = me.getEventTime();
|
|
||||||
|
|
||||||
if (pointerCount > 1 && mOldPointerCount > 1) {
|
if (pointerCount > 1 && mOldPointerCount > 1) {
|
||||||
// Don't do anything when 2 or more pointers are down and moving.
|
// Don't do anything when 2 or more pointers are down and moving.
|
||||||
|
@ -1261,132 +1268,138 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener
|
||||||
// Up event will pass through.
|
// Up event will pass through.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int touchX = getTouchX(me.getX());
|
||||||
|
int touchY = getTouchY(me.getY());
|
||||||
if (pointerCount != mOldPointerCount) {
|
if (pointerCount != mOldPointerCount) {
|
||||||
if (pointerCount == 1) {
|
if (pointerCount == 1) {
|
||||||
// Send a down event for the latest pointer
|
// Send a down event for the latest pointer
|
||||||
MotionEvent down = MotionEvent.obtain(now, now, MotionEvent.ACTION_DOWN,
|
onDownEvent(touchX, touchY, eventTime);
|
||||||
me.getX(), me.getY(), me.getMetaState());
|
|
||||||
result = onModifiedTouchEvent(down);
|
|
||||||
down.recycle();
|
|
||||||
// If it's an up action, then deliver the up as well.
|
// If it's an up action, then deliver the up as well.
|
||||||
if (action == MotionEvent.ACTION_UP) {
|
if (action == MotionEvent.ACTION_UP) {
|
||||||
result = onModifiedTouchEvent(me);
|
onUpEvent(touchX, touchY, eventTime);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Send an up event for the last pointer
|
// Send an up event for the last pointer
|
||||||
MotionEvent up = MotionEvent.obtain(now, now, MotionEvent.ACTION_UP,
|
onUpEvent(mOldPointerX, mOldPointerY, eventTime);
|
||||||
mOldPointerX, mOldPointerY, me.getMetaState());
|
|
||||||
result = onModifiedTouchEvent(up);
|
|
||||||
up.recycle();
|
|
||||||
}
|
}
|
||||||
mOldPointerCount = pointerCount;
|
mOldPointerCount = pointerCount;
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if (pointerCount == 1) {
|
if (pointerCount == 1) {
|
||||||
result = onModifiedTouchEvent(me);
|
onModifiedTouchEvent(action, touchX, touchY, eventTime);
|
||||||
mOldPointerX = me.getX();
|
mOldPointerX = touchX;
|
||||||
mOldPointerY = me.getY();
|
mOldPointerY = touchY;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean onModifiedTouchEvent(MotionEvent me) {
|
private void onModifiedTouchEvent(int action, int touchX, int touchY, long eventTime) {
|
||||||
int touchX = (int) me.getX() - getPaddingLeft();
|
|
||||||
int touchY = (int) me.getY() + mVerticalCorrection - getPaddingTop();
|
|
||||||
final int action = me.getAction();
|
|
||||||
final long eventTime = me.getEventTime();
|
|
||||||
int keyIndex = mProximityKeyDetector.getKeyIndexAndNearbyCodes(touchX, touchY, null);
|
|
||||||
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case MotionEvent.ACTION_DOWN:
|
case MotionEvent.ACTION_DOWN:
|
||||||
mAbortKey = false;
|
onDownEvent(touchX, touchY, eventTime);
|
||||||
mCurrentKey = keyIndex;
|
|
||||||
mStartX = touchX;
|
|
||||||
mStartY = touchY;
|
|
||||||
mDebouncer.startMoveDebouncing(touchX, touchY);
|
|
||||||
mDebouncer.startTimeDebouncing(eventTime);
|
|
||||||
checkMultiTap(eventTime, keyIndex);
|
|
||||||
mKeyboardActionListener.onPress(keyIndex != NOT_A_KEY ?
|
|
||||||
mKeys[keyIndex].codes[0] : 0);
|
|
||||||
if (keyIndex >= 0 && mKeys[keyIndex].repeatable) {
|
|
||||||
repeatKey(keyIndex);
|
|
||||||
mHandler.startKeyRepeatTimer(REPEAT_START_DELAY, keyIndex);
|
|
||||||
// Delivering the key could have caused an abort
|
|
||||||
if (mAbortKey) {
|
|
||||||
mHandler.cancelKeyRepeatTimer();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (keyIndex != NOT_A_KEY) {
|
|
||||||
mHandler.startLongPressTimer(keyIndex, LONGPRESS_TIMEOUT);
|
|
||||||
}
|
|
||||||
showPreview(keyIndex);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MotionEvent.ACTION_MOVE:
|
case MotionEvent.ACTION_MOVE:
|
||||||
if (keyIndex != NOT_A_KEY) {
|
onMoveEvent(touchX, touchY, eventTime);
|
||||||
if (mCurrentKey == NOT_A_KEY) {
|
|
||||||
mDebouncer.updateTimeDebouncing(eventTime);
|
|
||||||
mCurrentKey = keyIndex;
|
|
||||||
mHandler.startLongPressTimer(keyIndex, LONGPRESS_TIMEOUT);
|
|
||||||
} else if (mDebouncer.isMinorMoveBounce(touchX, touchY, keyIndex,
|
|
||||||
mCurrentKey)) {
|
|
||||||
mDebouncer.updateTimeDebouncing(eventTime);
|
|
||||||
} else {
|
|
||||||
resetMultiTap();
|
|
||||||
mDebouncer.resetTimeDebouncing(eventTime, mCurrentKey);
|
|
||||||
mDebouncer.resetMoveDebouncing();
|
|
||||||
mCurrentKey = keyIndex;
|
|
||||||
mHandler.startLongPressTimer(keyIndex, LONGPRESS_TIMEOUT);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mHandler.cancelLongPressTimer();
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
* While time debouncing is in effect, mCurrentKey holds the new key and mDebouncer
|
|
||||||
* holds the last key. At ACTION_UP event if time debouncing will be in effect
|
|
||||||
* eventually, the last key should be sent as the result. In such case mCurrentKey
|
|
||||||
* should not be showed as popup preview.
|
|
||||||
*/
|
|
||||||
showPreview(mDebouncer.isMinorTimeBounce() ? mDebouncer.getLastKey() : mCurrentKey);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MotionEvent.ACTION_UP:
|
case MotionEvent.ACTION_UP:
|
||||||
boolean wasInKeyRepeat = mHandler.isInKeyRepeat();
|
onUpEvent(touchX, touchY, eventTime);
|
||||||
mHandler.cancelKeyTimers();
|
|
||||||
mHandler.cancelPopupPreview();
|
|
||||||
if (mDebouncer.isMinorMoveBounce(touchX, touchY, keyIndex, mCurrentKey)) {
|
|
||||||
mDebouncer.updateTimeDebouncing(eventTime);
|
|
||||||
} else {
|
|
||||||
resetMultiTap();
|
|
||||||
mDebouncer.resetTimeDebouncing(eventTime, mCurrentKey);
|
|
||||||
mCurrentKey = keyIndex;
|
|
||||||
}
|
|
||||||
if (mDebouncer.isMinorTimeBounce()) {
|
|
||||||
mCurrentKey = mDebouncer.getLastKey();
|
|
||||||
touchX = mDebouncer.getLastCodeX();
|
|
||||||
touchY = mDebouncer.getLastCodeY();
|
|
||||||
}
|
|
||||||
showPreview(NOT_A_KEY);
|
|
||||||
// If we're not on a repeating key (which sends on a DOWN event)
|
|
||||||
if (!wasInKeyRepeat && !mMiniKeyboardOnScreen && !mAbortKey) {
|
|
||||||
detectAndSendKey(mCurrentKey, touchX, touchY, eventTime);
|
|
||||||
}
|
|
||||||
invalidateKey(keyIndex);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MotionEvent.ACTION_CANCEL:
|
case MotionEvent.ACTION_CANCEL:
|
||||||
mHandler.cancelKeyTimers();
|
onCancelEvent(touchX, touchY, eventTime);
|
||||||
mHandler.cancelPopupPreview();
|
|
||||||
dismissPopupKeyboard();
|
|
||||||
mAbortKey = true;
|
|
||||||
showPreview(NOT_A_KEY);
|
|
||||||
invalidateKey(mCurrentKey);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onDownEvent(int touchX, int touchY, long eventTime) {
|
||||||
|
int keyIndex = mProximityKeyDetector.getKeyIndexAndNearbyCodes(touchX, touchY, null);
|
||||||
|
mAbortKey = false;
|
||||||
|
mCurrentKey = keyIndex;
|
||||||
|
mStartX = touchX;
|
||||||
|
mStartY = touchY;
|
||||||
|
mDebouncer.startMoveDebouncing(touchX, touchY);
|
||||||
|
mDebouncer.startTimeDebouncing(eventTime);
|
||||||
|
checkMultiTap(eventTime, keyIndex);
|
||||||
|
mKeyboardActionListener.onPress(keyIndex != NOT_A_KEY ? mKeys[keyIndex].codes[0] : 0);
|
||||||
|
if (keyIndex >= 0 && mKeys[keyIndex].repeatable) {
|
||||||
|
repeatKey(keyIndex);
|
||||||
|
mHandler.startKeyRepeatTimer(REPEAT_START_DELAY, keyIndex);
|
||||||
|
// Delivering the key could have caused an abort
|
||||||
|
if (mAbortKey) {
|
||||||
|
mHandler.cancelKeyRepeatTimer();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (keyIndex != NOT_A_KEY) {
|
||||||
|
mHandler.startLongPressTimer(keyIndex, LONGPRESS_TIMEOUT);
|
||||||
|
}
|
||||||
|
showPreview(keyIndex);
|
||||||
mDebouncer.updateMoveDebouncing(touchX, touchY);
|
mDebouncer.updateMoveDebouncing(touchX, touchY);
|
||||||
return true;
|
}
|
||||||
|
|
||||||
|
private void onMoveEvent(int touchX, int touchY, long eventTime) {
|
||||||
|
int keyIndex = mProximityKeyDetector.getKeyIndexAndNearbyCodes(touchX, touchY, null);
|
||||||
|
if (keyIndex != NOT_A_KEY) {
|
||||||
|
if (mCurrentKey == NOT_A_KEY) {
|
||||||
|
mDebouncer.updateTimeDebouncing(eventTime);
|
||||||
|
mCurrentKey = keyIndex;
|
||||||
|
mHandler.startLongPressTimer(keyIndex, LONGPRESS_TIMEOUT);
|
||||||
|
} else if (mDebouncer.isMinorMoveBounce(touchX, touchY, keyIndex, mCurrentKey)) {
|
||||||
|
mDebouncer.updateTimeDebouncing(eventTime);
|
||||||
|
} else {
|
||||||
|
resetMultiTap();
|
||||||
|
mDebouncer.resetTimeDebouncing(eventTime, mCurrentKey);
|
||||||
|
mDebouncer.resetMoveDebouncing();
|
||||||
|
mCurrentKey = keyIndex;
|
||||||
|
mHandler.startLongPressTimer(keyIndex, LONGPRESS_TIMEOUT);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mHandler.cancelLongPressTimer();
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* While time debouncing is in effect, mCurrentKey holds the new key and mDebouncer
|
||||||
|
* holds the last key. At ACTION_UP event if time debouncing will be in effect
|
||||||
|
* eventually, the last key should be sent as the result. In such case mCurrentKey
|
||||||
|
* should not be showed as popup preview.
|
||||||
|
*/
|
||||||
|
showPreview(mDebouncer.isMinorTimeBounce() ? mDebouncer.getLastKey() : mCurrentKey);
|
||||||
|
mDebouncer.updateMoveDebouncing(touchX, touchY);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onUpEvent(int touchX, int touchY, long eventTime) {
|
||||||
|
int keyIndex = mProximityKeyDetector.getKeyIndexAndNearbyCodes(touchX, touchY, null);
|
||||||
|
boolean wasInKeyRepeat = mHandler.isInKeyRepeat();
|
||||||
|
mHandler.cancelKeyTimers();
|
||||||
|
mHandler.cancelPopupPreview();
|
||||||
|
if (mDebouncer.isMinorMoveBounce(touchX, touchY, keyIndex, mCurrentKey)) {
|
||||||
|
mDebouncer.updateTimeDebouncing(eventTime);
|
||||||
|
} else {
|
||||||
|
resetMultiTap();
|
||||||
|
mDebouncer.resetTimeDebouncing(eventTime, mCurrentKey);
|
||||||
|
mCurrentKey = keyIndex;
|
||||||
|
}
|
||||||
|
if (mDebouncer.isMinorTimeBounce()) {
|
||||||
|
mCurrentKey = mDebouncer.getLastKey();
|
||||||
|
touchX = mDebouncer.getLastCodeX();
|
||||||
|
touchY = mDebouncer.getLastCodeY();
|
||||||
|
}
|
||||||
|
showPreview(NOT_A_KEY);
|
||||||
|
// If we're not on a repeating key (which sends on a DOWN event)
|
||||||
|
if (!wasInKeyRepeat && !mMiniKeyboardOnScreen && !mAbortKey) {
|
||||||
|
detectAndSendKey(mCurrentKey, touchX, touchY, eventTime);
|
||||||
|
}
|
||||||
|
invalidateKey(keyIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onCancelEvent(int touchX, int touchY, long eventTime) {
|
||||||
|
mHandler.cancelKeyTimers();
|
||||||
|
mHandler.cancelPopupPreview();
|
||||||
|
dismissPopupKeyboard();
|
||||||
|
mAbortKey = true;
|
||||||
|
showPreview(NOT_A_KEY);
|
||||||
|
invalidateKey(mCurrentKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void repeatKey(int keyIndex) {
|
private void repeatKey(int keyIndex) {
|
||||||
|
|
Loading…
Reference in New Issue