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,45 +1268,53 @@ 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:
|
||||||
|
onDownEvent(touchX, touchY, eventTime);
|
||||||
|
break;
|
||||||
|
case MotionEvent.ACTION_MOVE:
|
||||||
|
onMoveEvent(touchX, touchY, eventTime);
|
||||||
|
break;
|
||||||
|
case MotionEvent.ACTION_UP:
|
||||||
|
onUpEvent(touchX, touchY, eventTime);
|
||||||
|
break;
|
||||||
|
case MotionEvent.ACTION_CANCEL:
|
||||||
|
onCancelEvent(touchX, touchY, eventTime);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onDownEvent(int touchX, int touchY, long eventTime) {
|
||||||
|
int keyIndex = mProximityKeyDetector.getKeyIndexAndNearbyCodes(touchX, touchY, null);
|
||||||
mAbortKey = false;
|
mAbortKey = false;
|
||||||
mCurrentKey = keyIndex;
|
mCurrentKey = keyIndex;
|
||||||
mStartX = touchX;
|
mStartX = touchX;
|
||||||
|
@ -1307,31 +1322,31 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener
|
||||||
mDebouncer.startMoveDebouncing(touchX, touchY);
|
mDebouncer.startMoveDebouncing(touchX, touchY);
|
||||||
mDebouncer.startTimeDebouncing(eventTime);
|
mDebouncer.startTimeDebouncing(eventTime);
|
||||||
checkMultiTap(eventTime, keyIndex);
|
checkMultiTap(eventTime, keyIndex);
|
||||||
mKeyboardActionListener.onPress(keyIndex != NOT_A_KEY ?
|
mKeyboardActionListener.onPress(keyIndex != NOT_A_KEY ? mKeys[keyIndex].codes[0] : 0);
|
||||||
mKeys[keyIndex].codes[0] : 0);
|
|
||||||
if (keyIndex >= 0 && mKeys[keyIndex].repeatable) {
|
if (keyIndex >= 0 && mKeys[keyIndex].repeatable) {
|
||||||
repeatKey(keyIndex);
|
repeatKey(keyIndex);
|
||||||
mHandler.startKeyRepeatTimer(REPEAT_START_DELAY, keyIndex);
|
mHandler.startKeyRepeatTimer(REPEAT_START_DELAY, keyIndex);
|
||||||
// Delivering the key could have caused an abort
|
// Delivering the key could have caused an abort
|
||||||
if (mAbortKey) {
|
if (mAbortKey) {
|
||||||
mHandler.cancelKeyRepeatTimer();
|
mHandler.cancelKeyRepeatTimer();
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (keyIndex != NOT_A_KEY) {
|
if (keyIndex != NOT_A_KEY) {
|
||||||
mHandler.startLongPressTimer(keyIndex, LONGPRESS_TIMEOUT);
|
mHandler.startLongPressTimer(keyIndex, LONGPRESS_TIMEOUT);
|
||||||
}
|
}
|
||||||
showPreview(keyIndex);
|
showPreview(keyIndex);
|
||||||
break;
|
mDebouncer.updateMoveDebouncing(touchX, touchY);
|
||||||
|
}
|
||||||
|
|
||||||
case MotionEvent.ACTION_MOVE:
|
private void onMoveEvent(int touchX, int touchY, long eventTime) {
|
||||||
|
int keyIndex = mProximityKeyDetector.getKeyIndexAndNearbyCodes(touchX, touchY, null);
|
||||||
if (keyIndex != NOT_A_KEY) {
|
if (keyIndex != NOT_A_KEY) {
|
||||||
if (mCurrentKey == NOT_A_KEY) {
|
if (mCurrentKey == NOT_A_KEY) {
|
||||||
mDebouncer.updateTimeDebouncing(eventTime);
|
mDebouncer.updateTimeDebouncing(eventTime);
|
||||||
mCurrentKey = keyIndex;
|
mCurrentKey = keyIndex;
|
||||||
mHandler.startLongPressTimer(keyIndex, LONGPRESS_TIMEOUT);
|
mHandler.startLongPressTimer(keyIndex, LONGPRESS_TIMEOUT);
|
||||||
} else if (mDebouncer.isMinorMoveBounce(touchX, touchY, keyIndex,
|
} else if (mDebouncer.isMinorMoveBounce(touchX, touchY, keyIndex, mCurrentKey)) {
|
||||||
mCurrentKey)) {
|
|
||||||
mDebouncer.updateTimeDebouncing(eventTime);
|
mDebouncer.updateTimeDebouncing(eventTime);
|
||||||
} else {
|
} else {
|
||||||
resetMultiTap();
|
resetMultiTap();
|
||||||
|
@ -1350,9 +1365,11 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener
|
||||||
* should not be showed as popup preview.
|
* should not be showed as popup preview.
|
||||||
*/
|
*/
|
||||||
showPreview(mDebouncer.isMinorTimeBounce() ? mDebouncer.getLastKey() : mCurrentKey);
|
showPreview(mDebouncer.isMinorTimeBounce() ? mDebouncer.getLastKey() : mCurrentKey);
|
||||||
break;
|
mDebouncer.updateMoveDebouncing(touchX, touchY);
|
||||||
|
}
|
||||||
|
|
||||||
case MotionEvent.ACTION_UP:
|
private void onUpEvent(int touchX, int touchY, long eventTime) {
|
||||||
|
int keyIndex = mProximityKeyDetector.getKeyIndexAndNearbyCodes(touchX, touchY, null);
|
||||||
boolean wasInKeyRepeat = mHandler.isInKeyRepeat();
|
boolean wasInKeyRepeat = mHandler.isInKeyRepeat();
|
||||||
mHandler.cancelKeyTimers();
|
mHandler.cancelKeyTimers();
|
||||||
mHandler.cancelPopupPreview();
|
mHandler.cancelPopupPreview();
|
||||||
|
@ -1374,19 +1391,15 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener
|
||||||
detectAndSendKey(mCurrentKey, touchX, touchY, eventTime);
|
detectAndSendKey(mCurrentKey, touchX, touchY, eventTime);
|
||||||
}
|
}
|
||||||
invalidateKey(keyIndex);
|
invalidateKey(keyIndex);
|
||||||
break;
|
}
|
||||||
|
|
||||||
case MotionEvent.ACTION_CANCEL:
|
private void onCancelEvent(int touchX, int touchY, long eventTime) {
|
||||||
mHandler.cancelKeyTimers();
|
mHandler.cancelKeyTimers();
|
||||||
mHandler.cancelPopupPreview();
|
mHandler.cancelPopupPreview();
|
||||||
dismissPopupKeyboard();
|
dismissPopupKeyboard();
|
||||||
mAbortKey = true;
|
mAbortKey = true;
|
||||||
showPreview(NOT_A_KEY);
|
showPreview(NOT_A_KEY);
|
||||||
invalidateKey(mCurrentKey);
|
invalidateKey(mCurrentKey);
|
||||||
break;
|
|
||||||
}
|
|
||||||
mDebouncer.updateMoveDebouncing(touchX, touchY);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void repeatKey(int keyIndex) {
|
private void repeatKey(int keyIndex) {
|
||||||
|
|
Loading…
Reference in New Issue