Bug 767980 - Don't make assumptions about time passed in PropertyAnimator (r=mfinkle)
authorLucas Rocha <lucasr@mozilla.com>
Fri, 12 Oct 2012 12:57:06 +0100
changeset 110193 c1ea82d15f11e21ceda0649e6ed737f9b58487ab
parent 110192 a68a80aabfe556f8006d5c8d9679fbc2d9098ed0
child 110194 0f085751610fbfc275ff10c36b07a29c16f972a9
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersmfinkle
bugs767980
milestone19.0a1
Bug 767980 - Don't make assumptions about time passed in PropertyAnimator (r=mfinkle)
mobile/android/base/PropertyAnimator.java
--- a/mobile/android/base/PropertyAnimator.java
+++ b/mobile/android/base/PropertyAnimator.java
@@ -4,16 +4,17 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko;
 
 import android.os.Handler;
 import android.util.Log;
 import android.view.View;
 import android.view.ViewGroup;
+import android.view.animation.AnimationUtils;
 import android.view.animation.DecelerateInterpolator;
 import android.view.animation.Interpolator;
 
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Timer;
 import java.util.TimerTask;
 
@@ -37,18 +38,18 @@ public class PropertyAnimator extends Ti
         int to;
     }
 
     public static interface PropertyAnimationListener {
         public void onPropertyAnimationStart();
         public void onPropertyAnimationEnd();
     }
 
-    private int mCount;
-    private int mDuration;
+    private long mStartTime;
+    private long mDuration;
     private List<ElementHolder> mElementsList;
     private PropertyAnimationListener mListener;
 
     // Default refresh rate in ms.
     private static final int INTERVAL = 10;
 
     public PropertyAnimator(int duration) {
         mDuration = duration;
@@ -79,31 +80,30 @@ public class PropertyAnimator extends Ti
     }
 
     public void setPropertyAnimationListener(PropertyAnimationListener listener) {
         mListener = listener;
     }
 
     @Override
     public void run() {
-        float interpolation = mInterpolator.getInterpolation((float) (mCount * INTERVAL) / (float) mDuration);
+        long timePassed = AnimationUtils.currentAnimationTimeMillis() - mStartTime;
+        float interpolation = mInterpolator.getInterpolation((float) (timePassed) / (float) mDuration);
 
         for (ElementHolder element : mElementsList) { 
             int delta = element.from + (int) ((element.to - element.from) * interpolation);
             invalidate(element, delta);
         }
 
-        mCount++;
-
-        if (mCount * INTERVAL >= mDuration)
+        if (timePassed >= mDuration)
             stop();
     }
 
     public void start() {
-        mCount = 0;
+        mStartTime = AnimationUtils.currentAnimationTimeMillis();
 
         // Fix the from value based on current position and property
         for (ElementHolder element : mElementsList) {
             if (element.property == Property.SLIDE_TOP)
                 element.from = element.view.getScrollY();
             else if (element.property == Property.SLIDE_LEFT)
                 element.from = element.view.getScrollX();
             else {