OLD | NEW |
---|---|
1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.compositor.layouts; | 5 package org.chromium.chrome.browser.compositor.layouts; |
6 | 6 |
7 import android.annotation.TargetApi; | |
8 import android.os.Build; | |
7 import android.os.SystemClock; | 9 import android.os.SystemClock; |
10 import android.provider.Settings; | |
8 import android.view.animation.AccelerateInterpolator; | 11 import android.view.animation.AccelerateInterpolator; |
9 import android.view.animation.DecelerateInterpolator; | 12 import android.view.animation.DecelerateInterpolator; |
10 import android.view.animation.Interpolator; | 13 import android.view.animation.Interpolator; |
11 import android.view.animation.LinearInterpolator; | 14 import android.view.animation.LinearInterpolator; |
12 | 15 |
16 import org.chromium.base.ContextUtils; | |
17 | |
13 import java.util.ArrayList; | 18 import java.util.ArrayList; |
14 import java.util.concurrent.atomic.AtomicBoolean; | 19 import java.util.concurrent.atomic.AtomicBoolean; |
15 | 20 |
16 /** | 21 /** |
17 * A class to handle simple animation sets. This can animate any object passed in by overriding | 22 * A class to handle simple animation sets. This can animate any object passed in by overriding |
18 * the ChromeAnimation.Animation object. | 23 * the ChromeAnimation.Animation object. |
19 * | 24 * |
20 * @param <T> The type of Object being animated by this ChromeAnimation set. | 25 * @param <T> The type of Object being animated by this ChromeAnimation set. |
21 */ | 26 */ |
22 @SuppressWarnings("unchecked") | 27 @SuppressWarnings("unchecked") |
23 public class ChromeAnimation<T> { | 28 public class ChromeAnimation<T> { |
24 /** | 29 /** |
25 * The amount we jump into the animation for the first frame. We do this as we assume | 30 * The amount we jump into the animation for the first frame. We do this as we assume |
26 * the object be animated is already resting in the initial value specified. To avoid wasting | 31 * the object be animated is already resting in the initial value specified. To avoid wasting |
27 * a frame of animation on something that will look exactly the same, we jum p into the | 32 * a frame of animation on something that will look exactly the same, we jum p into the |
28 * animation by this frame offset (calculated by the desired time required t o draw one frame | 33 * animation by this frame offset (calculated by the desired time required t o draw one frame |
29 * at 60 FPS). | 34 * at 60 FPS). |
30 */ | 35 */ |
31 private static final int FIRST_FRAME_OFFSET_MS = 1000 / 60; | 36 private static final int FIRST_FRAME_OFFSET_MS = 1000 / 60; |
32 | 37 |
33 /** | 38 /** |
34 * Can be used to slow down created animations for debugging purposes. | 39 * Multiplier for animation durations for debugging. Can be set in Developer Options and cached |
40 * here. | |
35 */ | 41 */ |
36 private static final int ANIMATION_MULTIPLIER = 1; | 42 private static Float sAnimationMultiplier; |
mdjones
2017/03/15 20:50:38
I'm guessing this can't be final because it is set
Bernhard Bauer
2017/03/15 21:21:58
It's static, so it would have to be set when the c
mdjones
2017/03/15 22:13:12
Ah right. I think what you have is fine.
| |
37 | 43 |
38 private final AtomicBoolean mFinishCalled = new AtomicBoolean(); | 44 private final AtomicBoolean mFinishCalled = new AtomicBoolean(); |
39 private final ArrayList<Animation<T>> mAnimations = new ArrayList<Animation< T>>(); | 45 private final ArrayList<Animation<T>> mAnimations = new ArrayList<Animation< T>>(); |
40 private long mCurrentTime; | 46 private long mCurrentTime; |
41 | 47 |
42 // Keep a reference to one of each standard interpolator to avoid allocation s. | 48 // Keep a reference to one of each standard interpolator to avoid allocation s. |
43 private static AccelerateInterpolator sAccelerateInterpolator; | 49 private static AccelerateInterpolator sAccelerateInterpolator; |
44 private static LinearInterpolator sLinearInterpolator; | 50 private static LinearInterpolator sLinearInterpolator; |
45 private static DecelerateInterpolator sDecelerateInterpolator; | 51 private static DecelerateInterpolator sDecelerateInterpolator; |
46 private static final Object sLock = new Object(); | 52 private static final Object sLock = new Object(); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 * @param duration The duration of the animation. This does not include the startTime. | 255 * @param duration The duration of the animation. This does not include the startTime. |
250 * The duration must be strictly positive. | 256 * The duration must be strictly positive. |
251 * @param startTime The time at which this animation should start. | 257 * @param startTime The time at which this animation should start. |
252 */ | 258 */ |
253 public Animation(T t, float start, float end, long duration, | 259 public Animation(T t, float start, float end, long duration, |
254 long startTime) { | 260 long startTime) { |
255 assert duration > 0; | 261 assert duration > 0; |
256 mAnimatedObject = t; | 262 mAnimatedObject = t; |
257 mStart = start; | 263 mStart = start; |
258 mEnd = end; | 264 mEnd = end; |
259 mDuration = duration * ANIMATION_MULTIPLIER; | 265 float animationMultiplier = getAnimationMultiplier(); |
260 mStartDelay = startTime * ANIMATION_MULTIPLIER; | 266 mDuration = (long) (duration * animationMultiplier); |
267 mStartDelay = (long) (startTime * animationMultiplier); | |
261 mCurrentTime = 0; | 268 mCurrentTime = 0; |
262 } | 269 } |
263 | 270 |
271 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) | |
272 private float getAnimationMultiplier() { | |
273 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) retu rn 1f; | |
274 | |
275 synchronized (sLock) { | |
276 if (sAnimationMultiplier == null) { | |
277 sAnimationMultiplier = Settings.Global.getFloat( | |
278 ContextUtils.getApplicationContext().getContentResol ver(), | |
279 Settings.Global.ANIMATOR_DURATION_SCALE, 1f); | |
280 } | |
281 return sAnimationMultiplier; | |
282 } | |
283 } | |
284 | |
264 /** | 285 /** |
265 * Returns the object being animated. | 286 * Returns the object being animated. |
266 */ | 287 */ |
267 protected T getAnimatedObject() { | 288 protected T getAnimatedObject() { |
268 return mAnimatedObject; | 289 return mAnimatedObject; |
269 } | 290 } |
270 | 291 |
271 /** | 292 /** |
272 * @param delayStartValue Whether to delay setting the animation's initi al value until | 293 * @param delayStartValue Whether to delay setting the animation's initi al value until |
273 * after the specified start delay (Default = false). | 294 * after the specified start delay (Default = false). |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
502 | 523 |
503 /** | 524 /** |
504 * Checks if the given property is being animated. | 525 * Checks if the given property is being animated. |
505 */ | 526 */ |
506 @Override | 527 @Override |
507 public <V extends Enum<?>> boolean checkProperty(V prop) { | 528 public <V extends Enum<?>> boolean checkProperty(V prop) { |
508 return mProperty == prop; | 529 return mProperty == prop; |
509 } | 530 } |
510 } | 531 } |
511 } | 532 } |
OLD | NEW |