Merge "Cancel the while-typing timer when user hits the spacebar" into jb-mr1-dev

main
Tadashi G. Takaoka 2012-07-31 04:03:14 -07:00 committed by Android (Google) Code Review
commit 8ec8c5feda
2 changed files with 31 additions and 15 deletions

View File

@ -154,8 +154,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
}
break;
case MSG_TYPING_STATE_EXPIRED:
cancelAndStartAnimators(keyboardView.mAltCodeKeyWhileTypingFadeoutAnimator,
keyboardView.mAltCodeKeyWhileTypingFadeinAnimator);
startWhileTypingFadeinAnimation(keyboardView);
break;
}
}
@ -229,7 +228,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
removeMessages(MSG_LONGPRESS_KEY);
}
public static void cancelAndStartAnimators(final ObjectAnimator animatorToCancel,
private static void cancelAndStartAnimators(final ObjectAnimator animatorToCancel,
final ObjectAnimator animatorToStart) {
float startFraction = 0.0f;
if (animatorToCancel.isStarted()) {
@ -241,18 +240,39 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
animatorToStart.setCurrentPlayTime(startTime);
}
private static void startWhileTypingFadeinAnimation(final MainKeyboardView keyboardView) {
cancelAndStartAnimators(keyboardView.mAltCodeKeyWhileTypingFadeoutAnimator,
keyboardView.mAltCodeKeyWhileTypingFadeinAnimator);
}
private static void startWhileTypingFadeoutAnimation(final MainKeyboardView keyboardView) {
cancelAndStartAnimators(keyboardView.mAltCodeKeyWhileTypingFadeinAnimator,
keyboardView.mAltCodeKeyWhileTypingFadeoutAnimator);
}
@Override
public void startTypingStateTimer() {
public void startTypingStateTimer(Key typedKey) {
if (typedKey.isModifier() || typedKey.altCodeWhileTyping()) {
return;
}
final boolean isTyping = isTypingState();
removeMessages(MSG_TYPING_STATE_EXPIRED);
final MainKeyboardView keyboardView = getOuterInstance();
// When user hits the space or the enter key, just cancel the while-typing timer.
final int typedCode = typedKey.mCode;
if (typedCode == Keyboard.CODE_SPACE || typedCode == Keyboard.CODE_ENTER) {
startWhileTypingFadeinAnimation(keyboardView);
return;
}
sendMessageDelayed(
obtainMessage(MSG_TYPING_STATE_EXPIRED), mParams.mIgnoreAltCodeKeyTimeout);
if (isTyping) {
return;
}
final MainKeyboardView keyboardView = getOuterInstance();
cancelAndStartAnimators(keyboardView.mAltCodeKeyWhileTypingFadeinAnimator,
keyboardView.mAltCodeKeyWhileTypingFadeoutAnimator);
startWhileTypingFadeoutAnimation(keyboardView);
}
@Override

View File

@ -82,7 +82,7 @@ public class PointerTracker {
}
public interface TimerProxy {
public void startTypingStateTimer();
public void startTypingStateTimer(Key typedKey);
public boolean isTypingState();
public void startKeyRepeatTimer(PointerTracker tracker);
public void startLongPressTimer(PointerTracker tracker);
@ -95,7 +95,7 @@ public class PointerTracker {
public static class Adapter implements TimerProxy {
@Override
public void startTypingStateTimer() {}
public void startTypingStateTimer(Key typedKey) {}
@Override
public boolean isTypingState() { return false; }
@Override
@ -329,9 +329,7 @@ public class PointerTracker {
mListener.onPressKey(key.mCode);
final boolean keyboardLayoutHasBeenChanged = mKeyboardLayoutHasBeenChanged;
mKeyboardLayoutHasBeenChanged = false;
if (!key.altCodeWhileTyping() && !key.isModifier()) {
mTimerProxy.startTypingStateTimer();
}
mTimerProxy.startTypingStateTimer(key);
return keyboardLayoutHasBeenChanged;
}
return false;
@ -956,9 +954,7 @@ public class PointerTracker {
public void onRegisterKey(Key key) {
if (key != null) {
detectAndSendKey(key, key.mX, key.mY);
if (!key.altCodeWhileTyping() && !key.isModifier()) {
mTimerProxy.startTypingStateTimer();
}
mTimerProxy.startTypingStateTimer(key);
}
}