Refactor long press related code

This change eliminates mCurrentKey dependency from openPopupIfRequired
method.  Also slightly cleanup onModifiedTouchEvent.

Bug: 2910379
Change-Id: I90c9b39c46c0bb32ecc6588abfc49eb60315f54c
main
Tadashi G. Takaoka 2010-08-25 12:08:20 +09:00
parent edadd2661b
commit 8ee1321264
1 changed files with 13 additions and 18 deletions

View File

@ -266,7 +266,7 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener
} }
break; break;
case MSG_LOGPRESS_KEY: case MSG_LOGPRESS_KEY:
openPopupIfRequired((MotionEvent) msg.obj); openPopupIfRequired(msg.arg1);
break; break;
} }
} }
@ -292,8 +292,9 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener
sendMessageDelayed(obtainMessage(MSG_REPEAT_KEY), delay); sendMessageDelayed(obtainMessage(MSG_REPEAT_KEY), delay);
} }
public void startLongPressTimer(MotionEvent me, long delay) { public void startLongPressTimer(int keyIndex, long delay) {
sendMessageDelayed(obtainMessage(MSG_LOGPRESS_KEY, me), delay); removeMessages(MSG_LOGPRESS_KEY);
sendMessageDelayed(obtainMessage(MSG_LOGPRESS_KEY, keyIndex, 0), delay);
} }
public void cancelLongPressTimer() { public void cancelLongPressTimer() {
@ -1166,16 +1167,16 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener
key.x + key.width + getPaddingLeft(), key.y + key.height + getPaddingTop()); key.x + key.width + getPaddingLeft(), key.y + key.height + getPaddingTop());
} }
private boolean openPopupIfRequired(MotionEvent me) { private boolean openPopupIfRequired(int keyIndex) {
// Check if we have a popup layout specified first. // Check if we have a popup layout specified first.
if (mPopupLayout == 0) { if (mPopupLayout == 0) {
return false; return false;
} }
if (mCurrentKey < 0 || mCurrentKey >= mKeys.length) { if (keyIndex < 0 || keyIndex >= mKeys.length) {
return false; return false;
} }
Key popupKey = mKeys[mCurrentKey]; Key popupKey = mKeys[keyIndex];
boolean result = onLongPress(popupKey); boolean result = onLongPress(popupKey);
if (result) { if (result) {
mAbortKey = true; mAbortKey = true;
@ -1366,36 +1367,30 @@ public class LatinKeyboardBaseView extends View implements View.OnClickListener
break; break;
} }
} }
if (mCurrentKey != NOT_A_KEY) { if (keyIndex != NOT_A_KEY) {
mHandler.startLongPressTimer(me, LONGPRESS_TIMEOUT); mHandler.startLongPressTimer(keyIndex, LONGPRESS_TIMEOUT);
} }
showPreview(keyIndex); showPreview(keyIndex);
break; break;
case MotionEvent.ACTION_MOVE: case MotionEvent.ACTION_MOVE:
boolean continueLongPress = false;
if (keyIndex != NOT_A_KEY) { if (keyIndex != NOT_A_KEY) {
if (mCurrentKey == NOT_A_KEY) { if (mCurrentKey == NOT_A_KEY) {
mCurrentKey = keyIndex;
mDebouncer.updateTimeDebouncing(eventTime); mDebouncer.updateTimeDebouncing(eventTime);
mCurrentKey = keyIndex;
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);
continueLongPress = true;
} else if (mRepeatKeyIndex == NOT_A_KEY) { } else if (mRepeatKeyIndex == NOT_A_KEY) {
resetMultiTap(); resetMultiTap();
mDebouncer.resetTimeDebouncing(eventTime, mCurrentKey); mDebouncer.resetTimeDebouncing(eventTime, mCurrentKey);
mDebouncer.resetMoveDebouncing(); mDebouncer.resetMoveDebouncing();
mCurrentKey = keyIndex; mCurrentKey = keyIndex;
mHandler.startLongPressTimer(keyIndex, LONGPRESS_TIMEOUT);
} }
} } else {
if (!continueLongPress) {
// Cancel old longpress
mHandler.cancelLongPressTimer(); mHandler.cancelLongPressTimer();
// Start new longpress if key has changed
if (keyIndex != NOT_A_KEY) {
mHandler.startLongPressTimer(me, LONGPRESS_TIMEOUT);
}
} }
/* /*
* While time debouncing is in effect, mCurrentKey holds the new key and mDebouncer * While time debouncing is in effect, mCurrentKey holds the new key and mDebouncer