Don't start long press timer while other one is running

Bug: 11908158
Bug: 12088861
Change-Id: I2537855f505884da9fe958d946c79840bd19dc5f
This commit is contained in:
Tadashi G. Takaoka 2013-11-28 19:13:38 +09:00
parent 7c8075c2ac
commit fa860a091e
3 changed files with 43 additions and 31 deletions

View file

@ -425,8 +425,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
*/ */
@Override @Override
public void setKeyboard(final Keyboard keyboard) { public void setKeyboard(final Keyboard keyboard) {
// Remove any pending messages, except dismissing preview and key repeat. // Remove any pending messages.
mKeyTimerHandler.cancelLongPressTimer(); mKeyTimerHandler.cancelAllKeyTimers();
super.setKeyboard(keyboard); super.setKeyboard(keyboard);
mKeyDetector.setKeyboard( mKeyDetector.setKeyboard(
keyboard, -getPaddingLeft(), -getPaddingTop() + getVerticalCorrection()); keyboard, -getPaddingLeft(), -getPaddingTop() + getVerticalCorrection());
@ -987,7 +987,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
if (mNonDistinctMultitouchHelper != null) { if (mNonDistinctMultitouchHelper != null) {
if (me.getPointerCount() > 1 && mKeyTimerHandler.isInKeyRepeat()) { if (me.getPointerCount() > 1 && mKeyTimerHandler.isInKeyRepeat()) {
// Key repeating timer will be canceled if 2 or more keys are in action. // Key repeating timer will be canceled if 2 or more keys are in action.
mKeyTimerHandler.cancelKeyRepeatTimer(); mKeyTimerHandler.cancelKeyRepeatTimers();
} }
// Non distinct multitouch screen support // Non distinct multitouch screen support
mNonDistinctMultitouchHelper.processMotionEvent(me, mKeyDetector); mNonDistinctMultitouchHelper.processMotionEvent(me, mKeyDetector);

View file

@ -67,13 +67,13 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
public interface TimerProxy { public interface TimerProxy {
public void startTypingStateTimer(Key typedKey); public void startTypingStateTimer(Key typedKey);
public boolean isTypingState(); public boolean isTypingState();
public void startKeyRepeatTimer(PointerTracker tracker, int repeatCount, int delay); public void startKeyRepeatTimerOf(PointerTracker tracker, int repeatCount, int delay);
public void startLongPressTimer(PointerTracker tracker, int delay); public void startLongPressTimerOf(PointerTracker tracker, int delay);
public void cancelLongPressTimer(); public void cancelLongPressTimerOf(PointerTracker tracker);
public void cancelKeyTimersOf(PointerTracker tracker);
public void startDoubleTapShiftKeyTimer(); public void startDoubleTapShiftKeyTimer();
public void cancelDoubleTapShiftKeyTimer(); public void cancelDoubleTapShiftKeyTimer();
public boolean isInDoubleTapShiftKeyTimeout(); public boolean isInDoubleTapShiftKeyTimeout();
public void cancelKeyTimers();
public void startUpdateBatchInputTimer(PointerTracker tracker); public void startUpdateBatchInputTimer(PointerTracker tracker);
public void cancelUpdateBatchInputTimer(PointerTracker tracker); public void cancelUpdateBatchInputTimer(PointerTracker tracker);
public void cancelAllUpdateBatchInputTimers(); public void cancelAllUpdateBatchInputTimers();
@ -84,11 +84,13 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
@Override @Override
public boolean isTypingState() { return false; } public boolean isTypingState() { return false; }
@Override @Override
public void startKeyRepeatTimer(PointerTracker tracker, int repeatCount, int delay) {} public void startKeyRepeatTimerOf(PointerTracker tracker, int repeatCount, int delay) {}
@Override @Override
public void startLongPressTimer(PointerTracker tracker, int delay) {} public void startLongPressTimerOf(PointerTracker tracker, int delay) {}
@Override @Override
public void cancelLongPressTimer() {} public void cancelLongPressTimerOf(PointerTracker tracker) {}
@Override
public void cancelKeyTimersOf(PointerTracker tracker) {}
@Override @Override
public void startDoubleTapShiftKeyTimer() {} public void startDoubleTapShiftKeyTimer() {}
@Override @Override
@ -96,8 +98,6 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
@Override @Override
public boolean isInDoubleTapShiftKeyTimeout() { return false; } public boolean isInDoubleTapShiftKeyTimeout() { return false; }
@Override @Override
public void cancelKeyTimers() {}
@Override
public void startUpdateBatchInputTimer(PointerTracker tracker) {} public void startUpdateBatchInputTimer(PointerTracker tracker) {}
@Override @Override
public void cancelUpdateBatchInputTimer(PointerTracker tracker) {} public void cancelUpdateBatchInputTimer(PointerTracker tracker) {}
@ -741,7 +741,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
sListener.onStartBatchInput(); sListener.onStartBatchInput();
dismissAllMoreKeysPanels(); dismissAllMoreKeysPanels();
} }
sTimerProxy.cancelLongPressTimer(); sTimerProxy.cancelLongPressTimerOf(this);
// A gesture floating preview text will be shown at the oldest pointer/finger on the screen. // A gesture floating preview text will be shown at the oldest pointer/finger on the screen.
sDrawingProxy.showGestureTrail( sDrawingProxy.showGestureTrail(
this, isOldestTrackerInQueue() /* showsFloatingPreviewText */); this, isOldestTrackerInQueue() /* showsFloatingPreviewText */);
@ -1072,7 +1072,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
setReleasedKeyGraphics(oldKey); setReleasedKeyGraphics(oldKey);
callListenerOnRelease(oldKey, oldKey.getCode(), true /* withSliding */); callListenerOnRelease(oldKey, oldKey.getCode(), true /* withSliding */);
startKeySelectionByDraggingFinger(oldKey); startKeySelectionByDraggingFinger(oldKey);
sTimerProxy.cancelKeyTimers(); sTimerProxy.cancelKeyTimersOf(this);
} }
private void dragFingerFromOldKeyToNewKey(final Key key, final int x, final int y, private void dragFingerFromOldKeyToNewKey(final Key key, final int x, final int y,
@ -1195,15 +1195,12 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
if (DEBUG_EVENT) { if (DEBUG_EVENT) {
printTouchEvent("onPhntEvent:", mLastX, mLastY, eventTime); printTouchEvent("onPhntEvent:", mLastX, mLastY, eventTime);
} }
if (isShowingMoreKeysPanel()) {
return;
}
onUpEventInternal(mLastX, mLastY, eventTime); onUpEventInternal(mLastX, mLastY, eventTime);
cancelTrackingForAction(); cancelTrackingForAction();
} }
private void onUpEventInternal(final int x, final int y, final long eventTime) { private void onUpEventInternal(final int x, final int y, final long eventTime) {
sTimerProxy.cancelKeyTimers(); sTimerProxy.cancelKeyTimersOf(this);
final boolean isInDraggingFinger = mIsInDraggingFinger; final boolean isInDraggingFinger = mIsInDraggingFinger;
final boolean isInSlidingKeyInput = mIsInSlidingKeyInput; final boolean isInSlidingKeyInput = mIsInSlidingKeyInput;
resetKeySelectionByDraggingFinger(); resetKeySelectionByDraggingFinger();
@ -1282,7 +1279,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
} }
private void onCancelEventInternal() { private void onCancelEventInternal() {
sTimerProxy.cancelKeyTimers(); sTimerProxy.cancelKeyTimersOf(this);
setReleasedKeyGraphics(mCurrentKey); setReleasedKeyGraphics(mCurrentKey);
resetKeySelectionByDraggingFinger(); resetKeySelectionByDraggingFinger();
if (isShowingMoreKeysPanel()) { if (isShowingMoreKeysPanel()) {
@ -1345,7 +1342,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
if (mIsInDraggingFinger && key.getMoreKeys() == null) return; if (mIsInDraggingFinger && key.getMoreKeys() == null) return;
final int delay = getLongPressTimeout(key.getCode()); final int delay = getLongPressTimeout(key.getCode());
sTimerProxy.startLongPressTimer(this, delay); sTimerProxy.startLongPressTimerOf(this, delay);
} }
private int getLongPressTimeout(final int code) { private int getLongPressTimeout(final int code) {
@ -1398,7 +1395,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
private void startKeyRepeatTimer(final int repeatCount) { private void startKeyRepeatTimer(final int repeatCount) {
final int delay = final int delay =
(repeatCount == 1) ? sParams.mKeyRepeatStartTimeout : sParams.mKeyRepeatInterval; (repeatCount == 1) ? sParams.mKeyRepeatStartTimeout : sParams.mKeyRepeatInterval;
sTimerProxy.startKeyRepeatTimer(this, repeatCount, delay); sTimerProxy.startKeyRepeatTimerOf(this, repeatCount, delay);
} }
private void printTouchEvent(final String title, final int x, final int y, private void printTouchEvent(final String title, final int x, final int y,

View file

@ -66,6 +66,7 @@ public final class TimerHandler extends LeakGuardHandlerWrapper<Callbacks> imple
tracker.onKeyRepeat(msg.arg1 /* code */, msg.arg2 /* repeatCount */); tracker.onKeyRepeat(msg.arg1 /* code */, msg.arg2 /* repeatCount */);
break; break;
case MSG_LONGPRESS_KEY: case MSG_LONGPRESS_KEY:
cancelLongPressTimers();
callbacks.onLongPress(tracker); callbacks.onLongPress(tracker);
break; break;
case MSG_UPDATE_BATCH_INPUT: case MSG_UPDATE_BATCH_INPUT:
@ -76,7 +77,7 @@ public final class TimerHandler extends LeakGuardHandlerWrapper<Callbacks> imple
} }
@Override @Override
public void startKeyRepeatTimer(final PointerTracker tracker, final int repeatCount, public void startKeyRepeatTimerOf(final PointerTracker tracker, final int repeatCount,
final int delay) { final int delay) {
final Key key = tracker.getKey(); final Key key = tracker.getKey();
if (key == null || delay == 0) { if (key == null || delay == 0) {
@ -86,7 +87,11 @@ public final class TimerHandler extends LeakGuardHandlerWrapper<Callbacks> imple
obtainMessage(MSG_REPEAT_KEY, key.getCode(), repeatCount, tracker), delay); obtainMessage(MSG_REPEAT_KEY, key.getCode(), repeatCount, tracker), delay);
} }
public void cancelKeyRepeatTimer() { private void cancelKeyRepeatTimerOf(final PointerTracker tracker) {
removeMessages(MSG_REPEAT_KEY, tracker);
}
public void cancelKeyRepeatTimers() {
removeMessages(MSG_REPEAT_KEY); removeMessages(MSG_REPEAT_KEY);
} }
@ -96,14 +101,19 @@ public final class TimerHandler extends LeakGuardHandlerWrapper<Callbacks> imple
} }
@Override @Override
public void startLongPressTimer(final PointerTracker tracker, final int delay) { public void startLongPressTimerOf(final PointerTracker tracker, final int delay) {
cancelLongPressTimer(); if (delay <= 0) {
if (delay <= 0) return; return;
}
sendMessageDelayed(obtainMessage(MSG_LONGPRESS_KEY, tracker), delay); sendMessageDelayed(obtainMessage(MSG_LONGPRESS_KEY, tracker), delay);
} }
@Override @Override
public void cancelLongPressTimer() { public void cancelLongPressTimerOf(final PointerTracker tracker) {
removeMessages(MSG_LONGPRESS_KEY, tracker);
}
private void cancelLongPressTimers() {
removeMessages(MSG_LONGPRESS_KEY); removeMessages(MSG_LONGPRESS_KEY);
} }
@ -159,9 +169,14 @@ public final class TimerHandler extends LeakGuardHandlerWrapper<Callbacks> imple
} }
@Override @Override
public void cancelKeyTimers() { public void cancelKeyTimersOf(final PointerTracker tracker) {
cancelKeyRepeatTimer(); cancelKeyRepeatTimerOf(tracker);
cancelLongPressTimer(); cancelLongPressTimerOf(tracker);
}
public void cancelAllKeyTimers() {
cancelKeyRepeatTimers();
cancelLongPressTimers();
} }
@Override @Override
@ -185,7 +200,7 @@ public final class TimerHandler extends LeakGuardHandlerWrapper<Callbacks> imple
} }
public void cancelAllMessages() { public void cancelAllMessages() {
cancelKeyTimers(); cancelAllKeyTimers();
cancelAllUpdateBatchInputTimers(); cancelAllUpdateBatchInputTimers();
} }
} }