Bug 772940 - Add support for setting/getting alpha in AnimatorProxy (r=mfinkle)
authorLucas Rocha <lucasr@mozilla.com>
Fri, 12 Oct 2012 13:22:02 +0100
changeset 110069 9f6acef4c469c2b7f6988e4283a56941fdda590f
parent 110068 eeba6e1170813924da9464290b2f3900262e0542
child 110070 94ea880274516fadcbd0e95616d03e4cbcd3ecfc
push id23671
push userryanvm@gmail.com
push dateSat, 13 Oct 2012 08:36:40 +0000
treeherdermozilla-central@0be7bfea4744 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs772940
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 772940 - Add support for setting/getting alpha in AnimatorProxy (r=mfinkle)
mobile/android/base/AnimatorProxy.java
--- a/mobile/android/base/AnimatorProxy.java
+++ b/mobile/android/base/AnimatorProxy.java
@@ -20,16 +20,19 @@ public class AnimatorProxy {
     private static final WeakHashMap<View, AnimatorProxy> PROXIES =
             new WeakHashMap<View, AnimatorProxy>();
 
     private static interface AnimatorProxyImpl {
         public int getScrollX();
         public int getScrollY();
         public void scrollTo(int scrollX, int scrollY);
 
+        public float getAlpha();
+        public void setAlpha(float alpha);
+
         public float getTranslationX();
         public void setTranslationX(float translationX);
 
         public float getTranslationY();
         public void setTranslationY(float translationY);
     }
 
     private AnimatorProxyImpl mImpl;
@@ -62,16 +65,24 @@ public class AnimatorProxy {
     public int getScrollY() {
         return mImpl.getScrollY();
     }
 
     public void scrollTo(int scrollX, int scrollY) {
         mImpl.scrollTo(scrollX, scrollY);
     }
 
+    public float getAlpha() {
+        return mImpl.getAlpha();
+    }
+
+    public void setAlpha(float alpha) {
+        mImpl.setAlpha(alpha);
+    }
+
     public float getTranslationX() {
         return mImpl.getTranslationX();
     }
 
     public void setTranslationX(float translationX) {
         mImpl.setTranslationX(translationX);
     }
 
@@ -92,24 +103,26 @@ public class AnimatorProxy {
      */
     private static class AnimatorProxyPreHC extends Animation implements AnimatorProxyImpl {
         private WeakReference<View> mViewRef;
 
         private final RectF mBefore;
         private final RectF mAfter;
         private final Matrix mTempMatrix;
 
+        private float mAlpha;
         private float mTranslationX;
         private float mTranslationY;
 
         public AnimatorProxyPreHC(View view) {
             mBefore = new RectF();
             mAfter = new RectF();
             mTempMatrix = new Matrix();
 
+            mAlpha = 1;
             mTranslationX = 0;
             mTranslationY = 0;
 
             loadCurrentTransformation(view);
 
             setDuration(0);
             setFillAfter(true);
             view.setAnimation(this);
@@ -123,16 +136,17 @@ public class AnimatorProxy {
                 return;
 
             Transformation transformation = new Transformation();
             float[] matrix = new float[9];
 
             animation.getTransformation(AnimationUtils.currentAnimationTimeMillis(), transformation);
             transformation.getMatrix().getValues(matrix);
 
+            mAlpha = transformation.getAlpha();
             mTranslationX = matrix[Matrix.MTRANS_X];
             mTranslationY = matrix[Matrix.MTRANS_Y];
         }
 
         private void prepareForUpdate() {
             View view = mViewRef.get();
             if (view != null)
                 computeRect(mBefore, view);
@@ -193,16 +207,33 @@ public class AnimatorProxy {
         @Override
         public void scrollTo(int scrollX, int scrollY) {
             View view = mViewRef.get();
             if (view != null)
                 view.scrollTo(scrollX, scrollY);
         }
 
         @Override
+        public float getAlpha() {
+            return mTranslationX;
+        }
+
+        @Override
+        public void setAlpha(float alpha) {
+            if (alpha == alpha)
+                return;
+
+            mAlpha = alpha;
+
+            View view = mViewRef.get();
+            if (view != null)
+                view.invalidate();
+        }
+
+        @Override
         public float getTranslationX() {
             return mTranslationX;
         }
 
         @Override
         public void setTranslationX(float translationX) {
             if (mTranslationX == translationX)
                 return;
@@ -225,18 +256,20 @@ public class AnimatorProxy {
             prepareForUpdate();
             mTranslationY = translationY;
             invalidateAfterUpdate();
         }
 
         @Override
         protected void applyTransformation(float interpolatedTime, Transformation t) {
             View view = mViewRef.get();
-            if (view != null)
+            if (view != null) {
+                t.setAlpha(mAlpha);
                 transformMatrix(t.getMatrix(), view);
+            }
         }
     }
 
     private static class AnimatorProxyPostHC implements AnimatorProxyImpl {
         private WeakReference<View> mViewRef;
 
         public AnimatorProxyPostHC(View view) {
             mViewRef = new WeakReference<View>(view);
@@ -263,16 +296,32 @@ public class AnimatorProxy {
         @Override
         public void scrollTo(int scrollX, int scrollY) {
             View view = mViewRef.get();
             if (view != null)
                 view.scrollTo(scrollX, scrollY);
         }
 
         @Override
+        public float getAlpha() {
+            View view = mViewRef.get();
+            if (view != null)
+                return view.getAlpha();
+
+            return 1;
+        }
+
+        @Override
+        public void setAlpha(float alpha) {
+            View view = mViewRef.get();
+            if (view != null)
+                view.setAlpha(alpha);
+        }
+
+        @Override
         public float getTranslationX() {
             View view = mViewRef.get();
             if (view != null)
                 return view.getTranslationX();
 
             return 0;
         }