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

Commit d21a9fe2 authored by Chet Haase's avatar Chet Haase
Browse files

Add Developer Option setting for Animator scaling.

This new setting allows users to set a scale factor for the
duration and startDelay of all Animator-based animations. This
setting is very similar to the Transition animation scale and
Window animation scale settings, except this one applies specifically
to Animator animations. The property is only accessible by users
through the Settings UI, not programmatically. The value applies
system-wide and is picked up per-process at the time of the first
ValueAnimator construction.

Change-Id: I3d5fbc956695c88d01c30820259da3e107ffd8a3
parent ed734404
Loading
Loading
Loading
Loading
+20 −4
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.animation;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.SystemProperties;
import android.util.AndroidRuntimeException;
import android.view.Choreographer;
import android.view.animation.AccelerateDecelerateInterpolator;
@@ -52,6 +53,8 @@ public class ValueAnimator extends Animator {
    /**
     * Internal constants
     */
    private static float sDurationScale = 1.0f;
    private static boolean sDurationScaleInitialized = false;

    /**
     * Messages sent to timing handler: START is sent when an animation first begins.
@@ -159,9 +162,11 @@ public class ValueAnimator extends Animator {

    // How long the animation should last in ms
    private long mDuration = 300;
    private long mUnscaledDuration = 300;

    // The amount of time in ms to delay starting the animation after start() is called
    private long mStartDelay = 0;
    private long mUnscaledStartDelay = 0;

    // The number of times the animation will repeat. The default is 0, which means the animation
    // will play only once
@@ -223,6 +228,15 @@ public class ValueAnimator extends Animator {
     * useful.
     */
    public ValueAnimator() {
        if (!sDurationScaleInitialized) {
            // Scale value initialized per-process when first animator is constructed
            String scaleString = SystemProperties.get("persist.sys.ui.animation");
            if (!scaleString.isEmpty()) {
                sDurationScale = Float.parseFloat(scaleString);
            }
            sDurationScaleInitialized = true;
        }
        mDuration *= sDurationScale;
    }

    /**
@@ -453,7 +467,8 @@ public class ValueAnimator extends Animator {
            throw new IllegalArgumentException("Animators cannot have negative duration: " +
                    duration);
        }
        mDuration = duration;
        mUnscaledDuration = duration;
        mDuration = (long)(duration * sDurationScale);
        return this;
    }

@@ -463,7 +478,7 @@ public class ValueAnimator extends Animator {
     * @return The length of the animation, in milliseconds.
     */
    public long getDuration() {
        return mDuration;
        return mUnscaledDuration;
    }

    /**
@@ -658,7 +673,7 @@ public class ValueAnimator extends Animator {
     * @return the number of milliseconds to delay running the animation
     */
    public long getStartDelay() {
        return mStartDelay;
        return mUnscaledStartDelay;
    }

    /**
@@ -668,7 +683,8 @@ public class ValueAnimator extends Animator {
     * @param startDelay The amount of the delay, in milliseconds
     */
    public void setStartDelay(long startDelay) {
        this.mStartDelay = startDelay;
        this.mStartDelay = (long)(startDelay * sDurationScale);
        mUnscaledStartDelay = startDelay;
    }

    /**