am 8ee13212: Refactor long press related code

Merge commit '8ee1321264a721a20fa2371d45bb14a07906f60c' into gingerbread-plus-aosp

* commit '8ee1321264a721a20fa2371d45bb14a07906f60c':
  Refactor long press related code
main
Tadashi G. Takaoka 2010-08-24 20:23:38 -07:00 committed by Android Git Automerger
commit ed99b8d9c1
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