Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(883)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/ChromeAnimation.java

Issue 2782143002: Reland of [Android] Respect animation multiplier from Developer Options. (Closed)
Patch Set: remove assert Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/ChromeAnimation.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/ChromeAnimation.java b/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/ChromeAnimation.java
index 5933a66a8e46883d77b32d6ee32565aec3c7377a..cfab524c83eb78591685c65fef1d6d7dd6a9ffd9 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/ChromeAnimation.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/compositor/layouts/ChromeAnimation.java
@@ -4,12 +4,18 @@
package org.chromium.chrome.browser.compositor.layouts;
+import android.annotation.TargetApi;
+import android.os.Build;
import android.os.SystemClock;
+import android.provider.Settings;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
+import org.chromium.base.ContextUtils;
+import org.chromium.chrome.browser.util.MathUtils;
+
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -31,9 +37,10 @@ public class ChromeAnimation<T> {
private static final int FIRST_FRAME_OFFSET_MS = 1000 / 60;
/**
- * Can be used to slow down created animations for debugging purposes.
+ * Multiplier for animation durations for debugging. Can be set in Developer Options and cached
+ * here.
*/
- private static final int ANIMATION_MULTIPLIER = 1;
+ private static Float sAnimationMultiplier;
private final AtomicBoolean mFinishCalled = new AtomicBoolean();
private final ArrayList<Animation<T>> mAnimations = new ArrayList<Animation<T>>();
@@ -247,20 +254,33 @@ public class ChromeAnimation<T> {
* @param start The starting value of the animation.
* @param end The ending value of the animation.
* @param duration The duration of the animation. This does not include the startTime.
- * The duration must be strictly positive.
* @param startTime The time at which this animation should start.
*/
public Animation(T t, float start, float end, long duration,
long startTime) {
- assert duration > 0;
mAnimatedObject = t;
mStart = start;
mEnd = end;
- mDuration = duration * ANIMATION_MULTIPLIER;
- mStartDelay = startTime * ANIMATION_MULTIPLIER;
+ float animationMultiplier = getAnimationMultiplier();
+ mDuration = (long) (duration * animationMultiplier);
+ mStartDelay = (long) (startTime * animationMultiplier);
mCurrentTime = 0;
}
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
+ private float getAnimationMultiplier() {
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) return 1f;
+
+ synchronized (sLock) {
+ if (sAnimationMultiplier == null) {
+ sAnimationMultiplier = Settings.Global.getFloat(
+ ContextUtils.getApplicationContext().getContentResolver(),
+ Settings.Global.ANIMATOR_DURATION_SCALE, 1f);
+ }
+ return sAnimationMultiplier;
+ }
+ }
+
/**
* Returns the object being animated.
*/
@@ -303,11 +323,14 @@ public class ChromeAnimation<T> {
}
// Figure out the relative fraction of time we need to animate.
- long relativeTime = Math.max(0, Math.min(mCurrentTime - mStartDelay,
- mDuration));
+ long relativeTime = MathUtils.clamp(mCurrentTime - mStartDelay, 0, mDuration);
- setProperty(mStart + (mEnd - mStart)
- * mInterpolator.getInterpolation((float) relativeTime / (float) mDuration));
+ if (mDuration > 0) {
+ setProperty(MathUtils.interpolate(mStart, mEnd,
+ mInterpolator.getInterpolation((float) relativeTime / (float) mDuration)));
+ } else {
+ setProperty(mEnd);
+ }
}
/**
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698