Bug 772940 - Add support for alpha animations with PropertyAnimator (r=mfinkle)
authorLucas Rocha <lucasr@mozilla.com>
Fri, 12 Oct 2012 13:22:02 +0100
changeset 110202 94ea880274516fadcbd0e95616d03e4cbcd3ecfc
parent 110201 9f6acef4c469c2b7f6988e4283a56941fdda590f
child 110203 d15a22572dbd5476a200b7f326b5245f357dffe2
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersmfinkle
bugs772940
milestone19.0a1
Bug 772940 - Add support for alpha animations with PropertyAnimator (r=mfinkle)
mobile/android/base/PropertyAnimator.java
--- a/mobile/android/base/PropertyAnimator.java
+++ b/mobile/android/base/PropertyAnimator.java
@@ -17,16 +17,17 @@ import android.view.animation.Interpolat
 
 import java.util.ArrayList;
 import java.util.List;
 
 public class PropertyAnimator implements Runnable {
     private static final String LOGTAG = "GeckoPropertyAnimator";
 
     public static enum Property {
+        ALPHA,
         TRANSLATION_X,
         TRANSLATION_Y,
         SCROLL_X,
         SCROLL_Y
     }
 
     private class ElementHolder {
         View view;
@@ -62,17 +63,17 @@ public class PropertyAnimator implements
         mFramePoster = FramePoster.create(this);
         mUseHardwareLayer = true;
     }
 
     public void setUseHardwareLayer(boolean useHardwareLayer) {
         mUseHardwareLayer = useHardwareLayer;
     }
 
-    public void attach(View view, Property property, int to) {
+    public void attach(View view, Property property, float to) {
         ElementHolder element = new ElementHolder();
 
         element.view = view;
         element.proxy = AnimatorProxy.create(view);
         element.property = property;
         element.to = to;
 
         mElementsList.add(element);
@@ -100,17 +101,19 @@ public class PropertyAnimator implements
         mFramePoster.postNextAnimationFrame();
     }
 
     public void start() {
         mStartTime = AnimationUtils.currentAnimationTimeMillis();
 
         // Fix the from value based on current position and property
         for (ElementHolder element : mElementsList) {
-            if (element.property == Property.TRANSLATION_Y)
+            if (element.property == Property.ALPHA)
+                element.from = element.proxy.getAlpha();
+            else if (element.property == Property.TRANSLATION_Y)
                 element.from = element.proxy.getTranslationY();
             else if (element.property == Property.TRANSLATION_X)
                 element.from = element.proxy.getTranslationX();
             else if (element.property == Property.SCROLL_Y)
                 element.from = element.proxy.getScrollY();
             else if (element.property == Property.SCROLL_X)
                 element.from = element.proxy.getScrollX();
 
@@ -149,31 +152,35 @@ public class PropertyAnimator implements
             return false;
 
         if (Build.VERSION.SDK_INT < 11)
             return false;
 
         if (!(element.view instanceof ViewGroup))
             return false;
 
-        if (element.property == Property.TRANSLATION_Y || element.property == Property.TRANSLATION_X)
+        if (element.property == Property.ALPHA ||
+            element.property == Property.TRANSLATION_Y ||
+            element.property == Property.TRANSLATION_X)
             return true;
 
         return false;
     }
 
     private void invalidate(final ElementHolder element, final float delta) {
         final View view = element.view;
 
         // check to see if the view was detached between the check above and this code
         // getting run on the UI thread.
         if (view.getHandler() == null)
             return;
 
-        if (element.property == Property.TRANSLATION_Y)
+        if (element.property == Property.ALPHA)
+            element.proxy.setAlpha(delta);
+        else if (element.property == Property.TRANSLATION_Y)
             element.proxy.setTranslationY(delta);
         else if (element.property == Property.TRANSLATION_X)
             element.proxy.setTranslationX(delta);
         else if (element.property == Property.SCROLL_Y)
             element.proxy.scrollTo(element.proxy.getScrollX(), (int) delta);
         else if (element.property == Property.SCROLL_X)
             element.proxy.scrollTo((int) delta, element.proxy.getScrollY());
     }