Commit e6b17a67 authored by Justin Klaassen's avatar Justin Klaassen
Browse files

Set AlarmActivity's animator progress directly

Bug: 17935860

Power save mode changes the ValueAnimator's internal duration scale,
which prevents ValueAnimator#setCurrentPlayTime(long) from functioning
correctly (b/17404930). As a workaround, set the animator's animated
fraction directly, jumping the animation to a specific point that isn't
dependent on the animator's duration scale or the current play time.
This functionality isn't yet exposed (b/17938711), so the internal
ValueAnimator#animateValue(float) method must be invoked via reflection.

Change-Id: I1af77300b3a95e62c960d482fb2f0263cbbc4fc6
parent 70782a0d
......@@ -26,6 +26,9 @@ import android.view.View;
import android.view.animation.Interpolator;
import android.widget.ImageView;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class AnimatorUtils {
public static final long ANIM_DURATION_SHORT = 266L; // 8/30 frames long
......@@ -78,14 +81,31 @@ public class AnimatorUtils {
public static final TypeEvaluator ARGB_EVALUATOR = new ArgbEvaluator();
public static ValueAnimator getScaleAnimator(View view, float... values) {
return ObjectAnimator.ofPropertyValuesHolder(view,
PropertyValuesHolder.ofFloat(View.SCALE_X, values),
PropertyValuesHolder.ofFloat(View.SCALE_Y, values));
}
private static Method sAnimateValue;
private static boolean sTryAnimateValue = true;
public static void setAnimatedFraction(ValueAnimator animator, float fraction) {
animator.setCurrentPlayTime(Math.round((double) fraction * animator.getDuration()));
if (sTryAnimateValue) {
// try to set the animated fraction directly so that it isn't affected by the
// internal animator scale or time (b/17938711)
try {
if (sAnimateValue == null) {
sAnimateValue = ValueAnimator.class
.getDeclaredMethod("animateValue", float.class);
sAnimateValue.setAccessible(true);
}
sAnimateValue.invoke(animator, fraction);
return;
} catch (NoSuchMethodException|InvocationTargetException|IllegalAccessException e) {
// something went wrong, don't try that again
LogUtils.e("Unable to use animateValue directly", e);
sTryAnimateValue = false;
}
}
// if that doesn't work then just fall back to setting the current play time
animator.setCurrentPlayTime(Math.round(fraction * animator.getDuration()));
}
public static void start(ValueAnimator... animators) {
......@@ -113,4 +133,10 @@ public class AnimatorUtils {
animator.cancel();
}
}
public static ValueAnimator getScaleAnimator(View view, float... values) {
return ObjectAnimator.ofPropertyValuesHolder(view,
PropertyValuesHolder.ofFloat(View.SCALE_X, values),
PropertyValuesHolder.ofFloat(View.SCALE_Y, values));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment