Cancel long press shift key while chording input

Bug: 12123508
Change-Id: I693caad1f8ee47ebeb14419603d1fc29f6263a75
main
Tadashi G. Takaoka 2013-12-16 14:55:05 +09:00
parent 3f6c983adc
commit 1b5b0a3ebc
2 changed files with 25 additions and 4 deletions

View File

@ -70,6 +70,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
public void startKeyRepeatTimerOf(PointerTracker tracker, int repeatCount, int delay); public void startKeyRepeatTimerOf(PointerTracker tracker, int repeatCount, int delay);
public void startLongPressTimerOf(PointerTracker tracker, int delay); public void startLongPressTimerOf(PointerTracker tracker, int delay);
public void cancelLongPressTimerOf(PointerTracker tracker); public void cancelLongPressTimerOf(PointerTracker tracker);
public void cancelLongPressShiftKeyTimers();
public void cancelKeyTimersOf(PointerTracker tracker); public void cancelKeyTimersOf(PointerTracker tracker);
public void startDoubleTapShiftKeyTimer(); public void startDoubleTapShiftKeyTimer();
public void cancelDoubleTapShiftKeyTimer(); public void cancelDoubleTapShiftKeyTimer();
@ -90,6 +91,8 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
@Override @Override
public void cancelLongPressTimerOf(PointerTracker tracker) {} public void cancelLongPressTimerOf(PointerTracker tracker) {}
@Override @Override
public void cancelLongPressShiftKeyTimers() {}
@Override
public void cancelKeyTimersOf(PointerTracker tracker) {} public void cancelKeyTimersOf(PointerTracker tracker) {}
@Override @Override
public void startDoubleTapShiftKeyTimer() {} public void startDoubleTapShiftKeyTimer() {}
@ -1338,6 +1341,9 @@ public final class PointerTracker implements PointerTrackerQueue.Element {
} }
private void startLongPressTimer(final Key key) { private void startLongPressTimer(final Key key) {
// Note that we need to cancel all active long press shift key timers if any whenever we
// start a new long press timer for both non-shift and shift keys.
sTimerProxy.cancelLongPressShiftKeyTimers();
if (sInGesture) return; if (sInGesture) return;
if (key == null) return; if (key == null) return;
if (!key.isLongPressEnabled()) return; if (!key.isLongPressEnabled()) return;
@ -1349,6 +1355,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());
if (delay <= 0) return;
sTimerProxy.startLongPressTimerOf(this, delay); sTimerProxy.startLongPressTimerOf(this, delay);
} }

View File

@ -38,8 +38,9 @@ public final class TimerHandler extends LeakGuardHandlerWrapper<Callbacks> imple
private static final int MSG_TYPING_STATE_EXPIRED = 0; private static final int MSG_TYPING_STATE_EXPIRED = 0;
private static final int MSG_REPEAT_KEY = 1; private static final int MSG_REPEAT_KEY = 1;
private static final int MSG_LONGPRESS_KEY = 2; private static final int MSG_LONGPRESS_KEY = 2;
private static final int MSG_DOUBLE_TAP_SHIFT_KEY = 3; private static final int MSG_LONGPRESS_SHIFT_KEY = 3;
private static final int MSG_UPDATE_BATCH_INPUT = 4; private static final int MSG_DOUBLE_TAP_SHIFT_KEY = 4;
private static final int MSG_UPDATE_BATCH_INPUT = 5;
private final int mIgnoreAltCodeKeyTimeout; private final int mIgnoreAltCodeKeyTimeout;
private final int mGestureRecognitionUpdateTime; private final int mGestureRecognitionUpdateTime;
@ -66,6 +67,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:
case MSG_LONGPRESS_SHIFT_KEY:
cancelLongPressTimers(); cancelLongPressTimers();
callbacks.onLongPress(tracker); callbacks.onLongPress(tracker);
break; break;
@ -102,19 +104,31 @@ public final class TimerHandler extends LeakGuardHandlerWrapper<Callbacks> imple
@Override @Override
public void startLongPressTimerOf(final PointerTracker tracker, final int delay) { public void startLongPressTimerOf(final PointerTracker tracker, final int delay) {
if (delay <= 0) { final Key key = tracker.getKey();
if (key == null) {
return; return;
} }
sendMessageDelayed(obtainMessage(MSG_LONGPRESS_KEY, tracker), delay); // Use a separate message id for long pressing shift key, because long press shift key
// timers should be canceled when other key is pressed.
final int messageId = (key.getCode() == Constants.CODE_SHIFT)
? MSG_LONGPRESS_SHIFT_KEY : MSG_LONGPRESS_KEY;
sendMessageDelayed(obtainMessage(messageId, tracker), delay);
} }
@Override @Override
public void cancelLongPressTimerOf(final PointerTracker tracker) { public void cancelLongPressTimerOf(final PointerTracker tracker) {
removeMessages(MSG_LONGPRESS_KEY, tracker); removeMessages(MSG_LONGPRESS_KEY, tracker);
removeMessages(MSG_LONGPRESS_SHIFT_KEY, tracker);
}
@Override
public void cancelLongPressShiftKeyTimers() {
removeMessages(MSG_LONGPRESS_SHIFT_KEY);
} }
private void cancelLongPressTimers() { private void cancelLongPressTimers() {
removeMessages(MSG_LONGPRESS_KEY); removeMessages(MSG_LONGPRESS_KEY);
removeMessages(MSG_LONGPRESS_SHIFT_KEY);
} }
@Override @Override