Polish fade-in/out animations for the gray-out-while-typing keys

Bug: 6326723
Change-Id: Idb6fa023c497cf1f0f584f496e7e5ae82b1c9f4f
diff --git a/java/res/anim/alt_code_key_while_typing_fadein.xml b/java/res/anim/alt_code_key_while_typing_fadein.xml
index f8caca3..079c980 100644
--- a/java/res/anim/alt_code_key_while_typing_fadein.xml
+++ b/java/res/anim/alt_code_key_while_typing_fadein.xml
@@ -22,6 +22,6 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:propertyName="altCodeKeyWhileTypingAnimAlpha"
     android:valueType="intType"
-    android:duration="100"
+    android:duration="1000"
     android:valueFrom="128"
     android:valueTo="255" />
diff --git a/java/res/anim/alt_code_key_while_typing_fadeout.xml b/java/res/anim/alt_code_key_while_typing_fadeout.xml
index bad1e74..511e138 100644
--- a/java/res/anim/alt_code_key_while_typing_fadeout.xml
+++ b/java/res/anim/alt_code_key_while_typing_fadeout.xml
@@ -22,6 +22,6 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:propertyName="altCodeKeyWhileTypingAnimAlpha"
     android:valueType="intType"
-    android:duration="70"
+    android:duration="3000"
     android:valueFrom="255"
     android:valueTo="128" />
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
index a08c074..7fadb3b 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
@@ -227,16 +227,16 @@
             removeMessages(MSG_LONGPRESS_KEY);
         }
 
-        public static void cancelAndStartAnimators(ObjectAnimator animatorToCancel,
-                ObjectAnimator animatorToStart) {
-            if (animatorToCancel != null && animatorToCancel.isStarted()) {
+        public static void cancelAndStartAnimators(final ObjectAnimator animatorToCancel,
+                final ObjectAnimator animatorToStart) {
+            float startFraction = 0.0f;
+            if (animatorToCancel.isStarted()) {
                 animatorToCancel.cancel();
+                startFraction = 1.0f - animatorToCancel.getAnimatedFraction();
             }
-            // 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();
-            }
+            final long startTime = (long)(animatorToStart.getDuration() * startFraction);
+            animatorToStart.start();
+            animatorToStart.setCurrentPlayTime(startTime);
         }
 
         @Override