Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f30b8e4b authored by Justin Klaassen's avatar Justin Klaassen Committed by Android Git Automerger
Browse files

am 7d2e0755: Merge "Set AlarmActivity\'s animator progress directly" into lmp-dev

* commit '7d2e0755':
  Set AlarmActivity's animator progress directly
parents 0abba366 7d2e0755
Loading
Loading
Loading
Loading
+32 −6
Original line number Diff line number Diff line
@@ -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));
    }
}