blob: c51725a2caac43fa56e797f27dcd1c9ccfde0142 [file] [log] [blame]
Chet Haase17fb4b02010-06-28 17:55:07 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.animation;
18
Chet Haasee60a6932016-03-17 06:59:16 -070019import android.annotation.Nullable;
Alan Viveretteac85f902016-03-11 15:15:51 -050020import android.content.pm.ActivityInfo.Config;
Yigit Boyard422dc32014-09-25 12:23:35 -070021import android.content.res.ConstantState;
22
Chet Haase17fb4b02010-06-28 17:55:07 -070023import java.util.ArrayList;
24
25/**
Chet Haasea18a86b2010-09-07 13:20:00 -070026 * This is the superclass for classes which provide basic support for animations which can be
27 * started, ended, and have <code>AnimatorListeners</code> added to them.
Chet Haase17fb4b02010-06-28 17:55:07 -070028 */
Chet Haasee8cee38c2013-04-16 17:54:14 -070029public abstract class Animator implements Cloneable {
Chet Haase17fb4b02010-06-28 17:55:07 -070030
31 /**
Doris Liu13099142015-07-10 17:32:41 -070032 * The value used to indicate infinite duration (e.g. when Animators repeat infinitely).
Doris Liu13099142015-07-10 17:32:41 -070033 */
34 public static final long DURATION_INFINITE = -1;
35 /**
Chet Haase17fb4b02010-06-28 17:55:07 -070036 * The set of listeners to be sent events through the life of an animation.
37 */
Chet Haasea18a86b2010-09-07 13:20:00 -070038 ArrayList<AnimatorListener> mListeners = null;
Chet Haase17fb4b02010-06-28 17:55:07 -070039
40 /**
Chet Haase8aa1ffb2013-08-08 14:00:00 -070041 * The set of listeners to be sent pause/resume events through the life
42 * of an animation.
43 */
44 ArrayList<AnimatorPauseListener> mPauseListeners = null;
45
46 /**
47 * Whether this animator is currently in a paused state.
48 */
49 boolean mPaused = false;
50
51 /**
Yigit Boyard422dc32014-09-25 12:23:35 -070052 * A set of flags which identify the type of configuration changes that can affect this
53 * Animator. Used by the Animator cache.
54 */
Alan Viveretteac85f902016-03-11 15:15:51 -050055 @Config int mChangingConfigurations = 0;
Yigit Boyard422dc32014-09-25 12:23:35 -070056
57 /**
58 * If this animator is inflated from a constant state, keep a reference to it so that
59 * ConstantState will not be garbage collected until this animator is collected
60 */
61 private AnimatorConstantState mConstantState;
62
63 /**
Chet Haasea18a86b2010-09-07 13:20:00 -070064 * Starts this animation. If the animation has a nonzero startDelay, the animation will start
Chet Haaseb8f574a2011-08-03 14:10:06 -070065 * running after that delay elapses. A non-delayed animation will have its initial
66 * value(s) set immediately, followed by calls to
67 * {@link AnimatorListener#onAnimationStart(Animator)} for any listeners of this animator.
Chet Haasee2ab7cc2010-12-06 16:10:07 -080068 *
69 * <p>The animation started by calling this method will be run on the thread that called
70 * this method. This thread should have a Looper on it (a runtime exception will be thrown if
71 * this is not the case). Also, if the animation will animate
72 * properties of objects in the view hierarchy, then the calling thread should be the UI
73 * thread for that view hierarchy.</p>
74 *
Chet Haase17fb4b02010-06-28 17:55:07 -070075 */
Chet Haasea18a86b2010-09-07 13:20:00 -070076 public void start() {
Chet Haasef54a8d72010-07-22 14:44:59 -070077 }
78
Chet Haased953d082010-08-16 17:44:28 -070079 /**
Chet Haasea18a86b2010-09-07 13:20:00 -070080 * Cancels the animation. Unlike {@link #end()}, <code>cancel()</code> causes the animation to
Chet Haasee2ab7cc2010-12-06 16:10:07 -080081 * stop in its tracks, sending an
82 * {@link android.animation.Animator.AnimatorListener#onAnimationCancel(Animator)} to
83 * its listeners, followed by an
84 * {@link android.animation.Animator.AnimatorListener#onAnimationEnd(Animator)} message.
85 *
86 * <p>This method must be called on the thread that is running the animation.</p>
Chet Haased953d082010-08-16 17:44:28 -070087 */
Chet Haasea18a86b2010-09-07 13:20:00 -070088 public void cancel() {
Chet Haased953d082010-08-16 17:44:28 -070089 }
90
Chet Haase21cd1382010-09-01 17:42:29 -070091 /**
Chet Haasea18a86b2010-09-07 13:20:00 -070092 * Ends the animation. This causes the animation to assign the end value of the property being
Chet Haasee2ab7cc2010-12-06 16:10:07 -080093 * animated, then calling the
94 * {@link android.animation.Animator.AnimatorListener#onAnimationEnd(Animator)} method on
Chet Haasea18a86b2010-09-07 13:20:00 -070095 * its listeners.
Chet Haasee2ab7cc2010-12-06 16:10:07 -080096 *
97 * <p>This method must be called on the thread that is running the animation.</p>
Chet Haase21cd1382010-09-01 17:42:29 -070098 */
Chet Haasea18a86b2010-09-07 13:20:00 -070099 public void end() {
Chet Haase17fb4b02010-06-28 17:55:07 -0700100 }
101
102 /**
Chet Haase8aa1ffb2013-08-08 14:00:00 -0700103 * Pauses a running animation. This method should only be called on the same thread on
104 * which the animation was started. If the animation has not yet been {@link
105 * #isStarted() started} or has since ended, then the call is ignored. Paused
106 * animations can be resumed by calling {@link #resume()}.
107 *
108 * @see #resume()
109 * @see #isPaused()
110 * @see AnimatorPauseListener
111 */
112 public void pause() {
113 if (isStarted() && !mPaused) {
114 mPaused = true;
115 if (mPauseListeners != null) {
116 ArrayList<AnimatorPauseListener> tmpListeners =
117 (ArrayList<AnimatorPauseListener>) mPauseListeners.clone();
118 int numListeners = tmpListeners.size();
119 for (int i = 0; i < numListeners; ++i) {
120 tmpListeners.get(i).onAnimationPause(this);
121 }
122 }
123 }
124 }
125
126 /**
127 * Resumes a paused animation, causing the animator to pick up where it left off
128 * when it was paused. This method should only be called on the same thread on
129 * which the animation was started. Calls to resume() on an animator that is
130 * not currently paused will be ignored.
131 *
132 * @see #pause()
133 * @see #isPaused()
134 * @see AnimatorPauseListener
135 */
136 public void resume() {
137 if (mPaused) {
138 mPaused = false;
139 if (mPauseListeners != null) {
140 ArrayList<AnimatorPauseListener> tmpListeners =
141 (ArrayList<AnimatorPauseListener>) mPauseListeners.clone();
142 int numListeners = tmpListeners.size();
143 for (int i = 0; i < numListeners; ++i) {
144 tmpListeners.get(i).onAnimationResume(this);
145 }
146 }
147 }
148 }
149
150 /**
151 * Returns whether this animator is currently in a paused state.
152 *
153 * @return True if the animator is currently paused, false otherwise.
154 *
155 * @see #pause()
156 * @see #resume()
157 */
158 public boolean isPaused() {
159 return mPaused;
160 }
161
162 /**
Chet Haasee8cee38c2013-04-16 17:54:14 -0700163 * The amount of time, in milliseconds, to delay processing the animation
164 * after {@link #start()} is called.
165 *
166 * @return the number of milliseconds to delay running the animation
167 */
168 public abstract long getStartDelay();
169
170 /**
171 * The amount of time, in milliseconds, to delay processing the animation
172 * after {@link #start()} is called.
173
174 * @param startDelay The amount of the delay, in milliseconds
175 */
176 public abstract void setStartDelay(long startDelay);
177
178 /**
179 * Sets the duration of the animation.
180 *
181 * @param duration The length of the animation, in milliseconds.
182 */
183 public abstract Animator setDuration(long duration);
184
185 /**
186 * Gets the duration of the animation.
187 *
188 * @return The length of the animation, in milliseconds.
189 */
190 public abstract long getDuration();
191
192 /**
Doris Liu13099142015-07-10 17:32:41 -0700193 * Gets the total duration of the animation, accounting for animation sequences, start delay,
194 * and repeating. Return {@link #DURATION_INFINITE} if the duration is infinite.
Doris Liu8b7c99c2015-10-01 17:27:20 -0700195 *
196 * @return Total time an animation takes to finish, starting from the time {@link #start()}
197 * is called. {@link #DURATION_INFINITE} will be returned if the animation or any
198 * child animation repeats infinite times.
Doris Liu13099142015-07-10 17:32:41 -0700199 */
200 public long getTotalDuration() {
Doris Liu8b7c99c2015-10-01 17:27:20 -0700201 long duration = getDuration();
202 if (duration == DURATION_INFINITE) {
203 return DURATION_INFINITE;
204 } else {
205 return getStartDelay() + duration;
206 }
Doris Liu13099142015-07-10 17:32:41 -0700207 }
208
209 /**
Chet Haasee8cee38c2013-04-16 17:54:14 -0700210 * The time interpolator used in calculating the elapsed fraction of the
211 * animation. The interpolator determines whether the animation runs with
212 * linear or non-linear motion, such as acceleration and deceleration. The
213 * default value is {@link android.view.animation.AccelerateDecelerateInterpolator}.
214 *
215 * @param value the interpolator to be used by this animation
216 */
217 public abstract void setInterpolator(TimeInterpolator value);
218
219 /**
220 * Returns the timing interpolator that this animation uses.
221 *
222 * @return The timing interpolator for this animation.
223 */
224 public TimeInterpolator getInterpolator() {
225 return null;
226 }
227
228 /**
Chet Haase8b699792011-08-05 15:20:19 -0700229 * Returns whether this Animator is currently running (having been started and gone past any
230 * initial startDelay period and not yet ended).
231 *
Chet Haasea18a86b2010-09-07 13:20:00 -0700232 * @return Whether the Animator is running.
233 */
234 public abstract boolean isRunning();
235
236 /**
Chet Haase4ddd9252015-06-10 09:25:16 +0100237 * Returns whether this Animator has been started and not yet ended. For reusable
238 * Animators (which most Animators are, apart from the one-shot animator produced by
239 * {@link android.view.ViewAnimationUtils#createCircularReveal(
240 * android.view.View, int, int, float, float) createCircularReveal()}),
241 * this state is a superset of {@link #isRunning()}, because an Animator with a
242 * nonzero {@link #getStartDelay() startDelay} will return true for {@link #isStarted()} during
243 * the delay phase, whereas {@link #isRunning()} will return true only after the delay phase
244 * is complete. Non-reusable animators will always return true after they have been
245 * started, because they cannot return to a non-started state.
Chet Haase8b699792011-08-05 15:20:19 -0700246 *
247 * @return Whether the Animator has been started and not yet ended.
248 */
249 public boolean isStarted() {
250 // Default method returns value for isRunning(). Subclasses should override to return a
251 // real value.
252 return isRunning();
253 }
254
255 /**
Chet Haasea18a86b2010-09-07 13:20:00 -0700256 * Adds a listener to the set of listeners that are sent events through the life of an
257 * animation, such as start, repeat, and end.
258 *
259 * @param listener the listener to be added to the current set of listeners for this animation.
260 */
261 public void addListener(AnimatorListener listener) {
262 if (mListeners == null) {
263 mListeners = new ArrayList<AnimatorListener>();
264 }
265 mListeners.add(listener);
266 }
267
268 /**
269 * Removes a listener from the set listening to this animation.
270 *
271 * @param listener the listener to be removed from the current set of listeners for this
272 * animation.
273 */
274 public void removeListener(AnimatorListener listener) {
275 if (mListeners == null) {
276 return;
277 }
278 mListeners.remove(listener);
279 if (mListeners.size() == 0) {
280 mListeners = null;
Chet Haase17fb4b02010-06-28 17:55:07 -0700281 }
282 }
283
284 /**
Chet Haasea18a86b2010-09-07 13:20:00 -0700285 * Gets the set of {@link android.animation.Animator.AnimatorListener} objects that are currently
286 * listening for events on this <code>Animator</code> object.
Chet Haase602e4d32010-08-16 08:57:23 -0700287 *
Chet Haasea18a86b2010-09-07 13:20:00 -0700288 * @return ArrayList<AnimatorListener> The set of listeners.
Chet Haase602e4d32010-08-16 08:57:23 -0700289 */
Chet Haasea18a86b2010-09-07 13:20:00 -0700290 public ArrayList<AnimatorListener> getListeners() {
291 return mListeners;
Chet Haase602e4d32010-08-16 08:57:23 -0700292 }
293
294 /**
Chet Haase8aa1ffb2013-08-08 14:00:00 -0700295 * Adds a pause listener to this animator.
296 *
297 * @param listener the listener to be added to the current set of pause listeners
298 * for this animation.
299 */
300 public void addPauseListener(AnimatorPauseListener listener) {
301 if (mPauseListeners == null) {
302 mPauseListeners = new ArrayList<AnimatorPauseListener>();
303 }
304 mPauseListeners.add(listener);
305 }
306
307 /**
308 * Removes a pause listener from the set listening to this animation.
309 *
310 * @param listener the listener to be removed from the current set of pause
311 * listeners for this animation.
312 */
313 public void removePauseListener(AnimatorPauseListener listener) {
314 if (mPauseListeners == null) {
315 return;
316 }
317 mPauseListeners.remove(listener);
318 if (mPauseListeners.size() == 0) {
319 mPauseListeners = null;
320 }
321 }
322
323 /**
Chet Haased82c8ac2013-08-26 14:20:16 -0700324 * Removes all {@link #addListener(android.animation.Animator.AnimatorListener) listeners}
325 * and {@link #addPauseListener(android.animation.Animator.AnimatorPauseListener)
326 * pauseListeners} from this object.
Chet Haase17fb4b02010-06-28 17:55:07 -0700327 */
Chet Haasea18a86b2010-09-07 13:20:00 -0700328 public void removeAllListeners() {
Chet Haase17fb4b02010-06-28 17:55:07 -0700329 if (mListeners != null) {
Chet Haasea18a86b2010-09-07 13:20:00 -0700330 mListeners.clear();
331 mListeners = null;
Chet Haase17fb4b02010-06-28 17:55:07 -0700332 }
Chet Haase8aa1ffb2013-08-08 14:00:00 -0700333 if (mPauseListeners != null) {
334 mPauseListeners.clear();
335 mPauseListeners = null;
336 }
Chet Haase17fb4b02010-06-28 17:55:07 -0700337 }
338
Yigit Boyard422dc32014-09-25 12:23:35 -0700339 /**
340 * Return a mask of the configuration parameters for which this animator may change, requiring
341 * that it should be re-created from Resources. The default implementation returns whatever
342 * value was provided through setChangingConfigurations(int) or 0 by default.
343 *
344 * @return Returns a mask of the changing configuration parameters, as defined by
345 * {@link android.content.pm.ActivityInfo}.
346 * @see android.content.pm.ActivityInfo
347 * @hide
348 */
Alan Viveretteac85f902016-03-11 15:15:51 -0500349 public @Config int getChangingConfigurations() {
Yigit Boyard422dc32014-09-25 12:23:35 -0700350 return mChangingConfigurations;
351 }
352
353 /**
354 * Set a mask of the configuration parameters for which this animator may change, requiring
355 * that it be re-created from resource.
356 *
357 * @param configs A mask of the changing configuration parameters, as
358 * defined by {@link android.content.pm.ActivityInfo}.
359 *
360 * @see android.content.pm.ActivityInfo
361 * @hide
362 */
Alan Viveretteac85f902016-03-11 15:15:51 -0500363 public void setChangingConfigurations(@Config int configs) {
Yigit Boyard422dc32014-09-25 12:23:35 -0700364 mChangingConfigurations = configs;
365 }
366
367 /**
368 * Sets the changing configurations value to the union of the current changing configurations
369 * and the provided configs.
370 * This method is called while loading the animator.
371 * @hide
372 */
Alan Viveretteac85f902016-03-11 15:15:51 -0500373 public void appendChangingConfigurations(@Config int configs) {
Yigit Boyard422dc32014-09-25 12:23:35 -0700374 mChangingConfigurations |= configs;
375 }
376
377 /**
378 * Return a {@link android.content.res.ConstantState} instance that holds the shared state of
379 * this Animator.
380 * <p>
381 * This constant state is used to create new instances of this animator when needed, instead
382 * of re-loading it from resources. Default implementation creates a new
383 * {@link AnimatorConstantState}. You can override this method to provide your custom logic or
384 * return null if you don't want this animator to be cached.
385 *
386 * @return The ConfigurationBoundResourceCache.BaseConstantState associated to this Animator.
387 * @see android.content.res.ConstantState
388 * @see #clone()
389 * @hide
390 */
391 public ConstantState<Animator> createConstantState() {
392 return new AnimatorConstantState(this);
393 }
394
Chet Haase49afa5b2010-08-23 11:39:53 -0700395 @Override
Chet Haase21cd1382010-09-01 17:42:29 -0700396 public Animator clone() {
Chet Haasea18a86b2010-09-07 13:20:00 -0700397 try {
398 final Animator anim = (Animator) super.clone();
399 if (mListeners != null) {
Yigit Boyard422dc32014-09-25 12:23:35 -0700400 anim.mListeners = new ArrayList<AnimatorListener>(mListeners);
Chet Haase49afa5b2010-08-23 11:39:53 -0700401 }
Chet Haase8aa1ffb2013-08-08 14:00:00 -0700402 if (mPauseListeners != null) {
Yigit Boyard422dc32014-09-25 12:23:35 -0700403 anim.mPauseListeners = new ArrayList<AnimatorPauseListener>(mPauseListeners);
Chet Haase8aa1ffb2013-08-08 14:00:00 -0700404 }
Chet Haasea18a86b2010-09-07 13:20:00 -0700405 return anim;
406 } catch (CloneNotSupportedException e) {
407 throw new AssertionError();
Chet Haase49afa5b2010-08-23 11:39:53 -0700408 }
Chet Haase49afa5b2010-08-23 11:39:53 -0700409 }
410
Chet Haase17fb4b02010-06-28 17:55:07 -0700411 /**
Chet Haasea18a86b2010-09-07 13:20:00 -0700412 * This method tells the object to use appropriate information to extract
413 * starting values for the animation. For example, a AnimatorSet object will pass
414 * this call to its child objects to tell them to set up the values. A
415 * ObjectAnimator object will use the information it has about its target object
416 * and PropertyValuesHolder objects to get the start values for its properties.
Ken Wakasaf76a50c2012-03-09 19:56:35 +0900417 * A ValueAnimator object will ignore the request since it does not have enough
Chet Haasea18a86b2010-09-07 13:20:00 -0700418 * information (such as a target object) to gather these values.
Chet Haase17fb4b02010-06-28 17:55:07 -0700419 */
Chet Haasea18a86b2010-09-07 13:20:00 -0700420 public void setupStartValues() {
421 }
422
423 /**
424 * This method tells the object to use appropriate information to extract
425 * ending values for the animation. For example, a AnimatorSet object will pass
426 * this call to its child objects to tell them to set up the values. A
427 * ObjectAnimator object will use the information it has about its target object
428 * and PropertyValuesHolder objects to get the start values for its properties.
Ken Wakasaf76a50c2012-03-09 19:56:35 +0900429 * A ValueAnimator object will ignore the request since it does not have enough
Chet Haasea18a86b2010-09-07 13:20:00 -0700430 * information (such as a target object) to gather these values.
431 */
432 public void setupEndValues() {
433 }
434
435 /**
436 * Sets the target object whose property will be animated by this animation. Not all subclasses
437 * operate on target objects (for example, {@link ValueAnimator}, but this method
438 * is on the superclass for the convenience of dealing generically with those subclasses
439 * that do handle targets.
Chet Haasee60a6932016-03-17 06:59:16 -0700440 * <p>
441 * <strong>Note:</strong> The target is stored as a weak reference internally to avoid leaking
442 * resources by having animators directly reference old targets. Therefore, you should
443 * ensure that animator targets always have a hard reference elsewhere.
Chet Haasea18a86b2010-09-07 13:20:00 -0700444 *
445 * @param target The object being animated
446 */
Chet Haasee60a6932016-03-17 06:59:16 -0700447 public void setTarget(@Nullable Object target) {
Chet Haasea18a86b2010-09-07 13:20:00 -0700448 }
449
ztenghui7bc6a3f2014-07-15 15:12:12 -0700450 // Hide reverse() and canReverse() for now since reverse() only work for simple
451 // cases, like we don't support sequential, neither startDelay.
452 // TODO: make reverse() works for all the Animators.
453 /**
454 * @hide
455 */
456 public boolean canReverse() {
457 return false;
458 }
459
460 /**
461 * @hide
462 */
463 public void reverse() {
John Reck291161a2014-07-22 07:31:09 -0700464 throw new IllegalStateException("Reverse is not supported");
ztenghui7bc6a3f2014-07-15 15:12:12 -0700465 }
466
Chet Haasea18a86b2010-09-07 13:20:00 -0700467 /**
468 * <p>An animation listener receives notifications from an animation.
469 * Notifications indicate animation related events, such as the end or the
470 * repetition of the animation.</p>
471 */
472 public static interface AnimatorListener {
Chet Haase17fb4b02010-06-28 17:55:07 -0700473 /**
Chet Haasea18a86b2010-09-07 13:20:00 -0700474 * <p>Notifies the start of the animation.</p>
475 *
476 * @param animation The started animation.
477 */
478 void onAnimationStart(Animator animation);
479
480 /**
481 * <p>Notifies the end of the animation. This callback is not invoked
482 * for animations with repeat count set to INFINITE.</p>
483 *
484 * @param animation The animation which reached its end.
485 */
486 void onAnimationEnd(Animator animation);
487
488 /**
489 * <p>Notifies the cancellation of the animation. This callback is not invoked
490 * for animations with repeat count set to INFINITE.</p>
491 *
492 * @param animation The animation which was canceled.
493 */
494 void onAnimationCancel(Animator animation);
495
496 /**
497 * <p>Notifies the repetition of the animation.</p>
Chet Haase17fb4b02010-06-28 17:55:07 -0700498 *
499 * @param animation The animation which was repeated.
500 */
Chet Haasea18a86b2010-09-07 13:20:00 -0700501 void onAnimationRepeat(Animator animation);
Chet Haase17fb4b02010-06-28 17:55:07 -0700502 }
Chet Haase8aa1ffb2013-08-08 14:00:00 -0700503
504 /**
505 * A pause listener receives notifications from an animation when the
506 * animation is {@link #pause() paused} or {@link #resume() resumed}.
507 *
508 * @see #addPauseListener(AnimatorPauseListener)
509 */
510 public static interface AnimatorPauseListener {
511 /**
512 * <p>Notifies that the animation was paused.</p>
513 *
514 * @param animation The animaton being paused.
515 * @see #pause()
516 */
517 void onAnimationPause(Animator animation);
518
519 /**
520 * <p>Notifies that the animation was resumed, after being
521 * previously paused.</p>
522 *
523 * @param animation The animation being resumed.
524 * @see #resume()
525 */
526 void onAnimationResume(Animator animation);
527 }
John Reckc01bd112014-07-18 16:22:09 -0700528
529 /**
530 * <p>Whether or not the Animator is allowed to run asynchronously off of
531 * the UI thread. This is a hint that informs the Animator that it is
532 * OK to run the animation off-thread, however the Animator may decide
533 * that it must run the animation on the UI thread anyway.
534 *
535 * <p>Regardless of whether or not the animation runs asynchronously, all
536 * listener callbacks will be called on the UI thread.</p>
537 *
538 * <p>To be able to use this hint the following must be true:</p>
539 * <ol>
540 * <li>The animator is immutable while {@link #isStarted()} is true. Requests
541 * to change duration, delay, etc... may be ignored.</li>
542 * <li>Lifecycle callback events may be asynchronous. Events such as
543 * {@link Animator.AnimatorListener#onAnimationEnd(Animator)} or
544 * {@link Animator.AnimatorListener#onAnimationRepeat(Animator)} may end up delayed
545 * as they must be posted back to the UI thread, and any actions performed
546 * by those callbacks (such as starting new animations) will not happen
547 * in the same frame.</li>
548 * <li>State change requests ({@link #cancel()}, {@link #end()}, {@link #reverse()}, etc...)
549 * may be asynchronous. It is guaranteed that all state changes that are
550 * performed on the UI thread in the same frame will be applied as a single
551 * atomic update, however that frame may be the current frame,
552 * the next frame, or some future frame. This will also impact the observed
553 * state of the Animator. For example, {@link #isStarted()} may still return true
554 * after a call to {@link #end()}. Using the lifecycle callbacks is preferred over
555 * queries to {@link #isStarted()}, {@link #isRunning()}, and {@link #isPaused()}
556 * for this reason.</li>
557 * </ol>
558 * @hide
559 */
560 public void setAllowRunningAsynchronously(boolean mayRunAsync) {
561 // It is up to subclasses to support this, if they can.
562 }
Yigit Boyard422dc32014-09-25 12:23:35 -0700563
564 /**
565 * Creates a {@link ConstantState} which holds changing configurations information associated
566 * with the given Animator.
567 * <p>
568 * When {@link #newInstance()} is called, default implementation clones the Animator.
569 */
570 private static class AnimatorConstantState extends ConstantState<Animator> {
571
572 final Animator mAnimator;
Alan Viveretteac85f902016-03-11 15:15:51 -0500573 @Config int mChangingConf;
Yigit Boyard422dc32014-09-25 12:23:35 -0700574
575 public AnimatorConstantState(Animator animator) {
576 mAnimator = animator;
577 // ensure a reference back to here so that constante state is not gc'ed.
578 mAnimator.mConstantState = this;
579 mChangingConf = mAnimator.getChangingConfigurations();
580 }
581
582 @Override
Alan Viveretteac85f902016-03-11 15:15:51 -0500583 public @Config int getChangingConfigurations() {
Yigit Boyard422dc32014-09-25 12:23:35 -0700584 return mChangingConf;
585 }
586
587 @Override
588 public Animator newInstance() {
589 final Animator clone = mAnimator.clone();
590 clone.mConstantState = this;
591 return clone;
592 }
593 }
Chet Haasea18a86b2010-09-07 13:20:00 -0700594}