Skip to content

Commit d21a9fe

Browse files
committed
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
1 parent ed73440 commit d21a9fe

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

core/java/android/animation/ValueAnimator.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import android.os.Handler;
2020
import android.os.Looper;
2121
import android.os.Message;
22+
import android.os.SystemProperties;
2223
import android.util.AndroidRuntimeException;
2324
import android.view.Choreographer;
2425
import android.view.animation.AccelerateDecelerateInterpolator;
@@ -52,6 +53,8 @@ public class ValueAnimator extends Animator {
5253
/**
5354
* Internal constants
5455
*/
56+
private static float sDurationScale = 1.0f;
57+
private static boolean sDurationScaleInitialized = false;
5558

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

160163
// How long the animation should last in ms
161164
private long mDuration = 300;
165+
private long mUnscaledDuration = 300;
162166

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

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

228242
/**
@@ -453,7 +467,8 @@ public ValueAnimator setDuration(long duration) {
453467
throw new IllegalArgumentException("Animators cannot have negative duration: " +
454468
duration);
455469
}
456-
mDuration = duration;
470+
mUnscaledDuration = duration;
471+
mDuration = (long)(duration * sDurationScale);
457472
return this;
458473
}
459474

@@ -463,7 +478,7 @@ public ValueAnimator setDuration(long duration) {
463478
* @return The length of the animation, in milliseconds.
464479
*/
465480
public long getDuration() {
466-
return mDuration;
481+
return mUnscaledDuration;
467482
}
468483

469484
/**
@@ -658,7 +673,7 @@ public void onAnimate() {
658673
* @return the number of milliseconds to delay running the animation
659674
*/
660675
public long getStartDelay() {
661-
return mStartDelay;
676+
return mUnscaledStartDelay;
662677
}
663678

664679
/**
@@ -668,7 +683,8 @@ public long getStartDelay() {
668683
* @param startDelay The amount of the delay, in milliseconds
669684
*/
670685
public void setStartDelay(long startDelay) {
671-
this.mStartDelay = startDelay;
686+
this.mStartDelay = (long)(startDelay * sDurationScale);
687+
mUnscaledStartDelay = startDelay;
672688
}
673689

674690
/**

0 commit comments

Comments
 (0)