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; break;
case MSG_TYPING_STATE_EXPIRED: case MSG_TYPING_STATE_EXPIRED:
cancelAndStartAnimators(keyboardView.mAltCodeKeyWhileTypingFadeoutAnimator, startWhileTypingFadeinAnimation(keyboardView);
keyboardView.mAltCodeKeyWhileTypingFadeinAnimator);
break; break;
} }
} }
@ -229,7 +228,7 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
removeMessages(MSG_LONGPRESS_KEY); removeMessages(MSG_LONGPRESS_KEY);
} }
public static void cancelAndStartAnimators(final ObjectAnimator animatorToCancel, private static void cancelAndStartAnimators(final ObjectAnimator animatorToCancel,
final ObjectAnimator animatorToStart) { final ObjectAnimator animatorToStart) {
float startFraction = 0.0f; float startFraction = 0.0f;
if (animatorToCancel.isStarted()) { if (animatorToCancel.isStarted()) {
@ -241,18 +240,39 @@ public class MainKeyboardView extends KeyboardView implements PointerTracker.Key
animatorToStart.setCurrentPlayTime(startTime); 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 @Override
public void startTypingStateTimer() { public void startTypingStateTimer(Key typedKey) {
if (typedKey.isModifier() || typedKey.altCodeWhileTyping()) {
return;
}
final boolean isTyping = isTypingState(); final boolean isTyping = isTypingState();
removeMessages(MSG_TYPING_STATE_EXPIRED); 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( sendMessageDelayed(
obtainMessage(MSG_TYPING_STATE_EXPIRED), mParams.mIgnoreAltCodeKeyTimeout); obtainMessage(MSG_TYPING_STATE_EXPIRED), mParams.mIgnoreAltCodeKeyTimeout);
if (isTyping) { if (isTyping) {
return; return;
} }
final MainKeyboardView keyboardView = getOuterInstance(); startWhileTypingFadeoutAnimation(keyboardView);
cancelAndStartAnimators(keyboardView.mAltCodeKeyWhileTypingFadeinAnimator,
keyboardView.mAltCodeKeyWhileTypingFadeoutAnimator);
} }
@Override @Override

View File

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