From b9720a55b47684589e3176434cd2b1a08942d112 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 15 Mar 2012 21:05:17 +0900 Subject: [PATCH] Don't reset animation alpha value when keyboard is set The keys' blinking that mentioned in the bug is caused by switching keyboard layout resets the animation's alpha value to opaque but the animation is still running and changing the alpha value asynchronously. I think that switching keyboard layout between alphabet and symbols doesn't imply that the user stops typing. So the keyboard view should continue typing state timer to keep animations' alpha values changing and never reset the value. Bug: 6174273 Change-Id: Id795feaf44750358f30c1b3dc8e783a7e62aefe8 --- .../inputmethod/keyboard/Keyboard.java | 1 + .../keyboard/LatinKeyboardView.java | 72 +++++++------------ 2 files changed, 26 insertions(+), 47 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java index cdf07ed70..973f64b4d 100644 --- a/java/src/com/android/inputmethod/keyboard/Keyboard.java +++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java @@ -383,6 +383,7 @@ public class Keyboard { case CODE_ACTION_ENTER: return "actionEnter"; case CODE_ACTION_NEXT: return "actionNext"; case CODE_ACTION_PREVIOUS: return "actionPrevious"; + case CODE_LANGUAGE_SWITCH: return "languageSwitch"; case CODE_UNSPECIFIED: return "unspec"; case CODE_TAB: return "tab"; case CODE_ENTER: return "enter"; diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index 97f4d07d9..343842552 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -84,7 +84,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke private static final int ALPHA_OPAQUE = 255; private boolean mNeedsToDisplayLanguage; private Locale mSpacebarLocale; - private int mSpacebarTextAlpha; + private int mSpacebarTextAlpha = ALPHA_OPAQUE; private final float mSpacebarTextRatio; private float mSpacebarTextSize; private final int mSpacebarTextColor; @@ -101,7 +101,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke // Stuff to draw altCodeWhileTyping keys. private ValueAnimator mAltCodeKeyWhileTypingFadeoutAnimator; private ValueAnimator mAltCodeKeyWhileTypingFadeinAnimator; - private int mAltCodeKeyWhileTypingAnimAlpha; + private int mAltCodeKeyWhileTypingAnimAlpha = ALPHA_OPAQUE; // More keys keyboard private PopupWindow mMoreKeysWindow; @@ -154,16 +154,8 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke } break; case MSG_TYPING_STATE_EXPIRED: - final ValueAnimator fadeout = keyboardView.mAltCodeKeyWhileTypingFadeoutAnimator; - if (fadeout != null && fadeout.isStarted()) { - fadeout.cancel(); - } - // TODO: Start the fade in animation with an initial value that is the same as the - // final value when the above fade out animation gets cancelled. - final ValueAnimator fadein = keyboardView.mAltCodeKeyWhileTypingFadeinAnimator; - if (fadein != null && !fadein.isStarted()) { - fadein.start(); - } + cancelAndStartAnimators(keyboardView.mAltCodeKeyWhileTypingFadeoutAnimator, + keyboardView.mAltCodeKeyWhileTypingFadeinAnimator); break; } } @@ -238,26 +230,34 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke removeMessages(MSG_LONGPRESS_KEY); } + private static void cancelAndStartAnimators(ValueAnimator animatorToCancel, + ValueAnimator animatorToStart) { + if (animatorToCancel != null && animatorToCancel.isStarted()) { + animatorToCancel.cancel(); + } + // TODO: Start the animation with an initial value that is the same as the final value + // of the above animation when it gets cancelled. + if (animatorToStart != null && !animatorToStart.isStarted()) { + animatorToStart.start(); + } + } + + private void cancelTypingStateTimer() { + removeMessages(MSG_TYPING_STATE_EXPIRED); + } + @Override public void startTypingStateTimer() { final boolean isTyping = isTypingState(); - removeMessages(MSG_TYPING_STATE_EXPIRED); + cancelTypingStateTimer(); sendMessageDelayed( obtainMessage(MSG_TYPING_STATE_EXPIRED), mParams.mIgnoreAltCodeKeyTimeout); - final LatinKeyboardView keyboardView = getOuterInstance(); if (isTyping) { return; } - final ValueAnimator fadein = keyboardView.mAltCodeKeyWhileTypingFadeinAnimator; - if (fadein != null && fadein.isStarted()) { - fadein.cancel(); - } - // TODO: Start the fade out animation with an initial value that is the same as the - // final value when the above fade in animation gets cancelled. - final ValueAnimator fadeout = keyboardView.mAltCodeKeyWhileTypingFadeoutAnimator; - if (fadeout != null && !fadeout.isStarted()) { - fadeout.start(); - } + final LatinKeyboardView keyboardView = getOuterInstance(); + cancelAndStartAnimators(keyboardView.mAltCodeKeyWhileTypingFadeinAnimator, + keyboardView.mAltCodeKeyWhileTypingFadeoutAnimator); } @Override @@ -289,6 +289,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke public void cancelAllMessages() { cancelKeyTimers(); + cancelTypingStateTimer(); } } @@ -323,15 +324,6 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke public final int mLongPressSpaceKeyTimeout; public final int mIgnoreAltCodeKeyTimeout; - KeyTimerParams() { - mKeyRepeatStartTimeout = 0; - mKeyRepeatInterval = 0; - mLongPressKeyTimeout = 0; - mLongPressShiftKeyTimeout = 0; - mLongPressSpaceKeyTimeout = 0; - mIgnoreAltCodeKeyTimeout = 0; - } - public KeyTimerParams(TypedArray latinKeyboardViewAttr) { mKeyRepeatStartTimeout = latinKeyboardViewAttr.getInt( R.styleable.LatinKeyboardView_keyRepeatStartTimeout, 0); @@ -424,12 +416,6 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke updateAltCodeKeyWhileTyping(); } }); - fadeout.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator a) { - final ValueAnimator valueAnimator = (ValueAnimator)a; - } - }); } mAltCodeKeyWhileTypingFadeoutAnimator = fadeout; @@ -442,12 +428,6 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke updateAltCodeKeyWhileTyping(); } }); - fadein.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator a) { - final ValueAnimator valueAnimator = (ValueAnimator)a; - } - }); } mAltCodeKeyWhileTypingFadeinAnimator = fadein; } @@ -510,8 +490,6 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke final int keyHeight = keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap; mSpacebarTextSize = keyHeight * mSpacebarTextRatio; mSpacebarLocale = keyboard.mId.mLocale; - mSpacebarTextAlpha = ALPHA_OPAQUE; - mAltCodeKeyWhileTypingAnimAlpha = ALPHA_OPAQUE; } /**