117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase/* 217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * Copyright (C) 2010 The Android Open Source Project 317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * Licensed under the Apache License, Version 2.0 (the "License"); 517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * you may not use this file except in compliance with the License. 617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * You may obtain a copy of the License at 717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * http://www.apache.org/licenses/LICENSE-2.0 917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 1017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * Unless required by applicable law or agreed to in writing, software 1117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * distributed under the License is distributed on an "AS IS" BASIS, 1217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * See the License for the specific language governing permissions and 1417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * limitations under the License. 1517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 1617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 1717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haasepackage android.animation; 1817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 19d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyarimport android.content.res.ConstantState; 20d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 2117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haaseimport java.util.ArrayList; 2217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 2317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase/** 24a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * This is the superclass for classes which provide basic support for animations which can be 25a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * started, ended, and have <code>AnimatorListeners</code> added to them. 2617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 27e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haasepublic abstract class Animator implements Cloneable { 2817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 2917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 3017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * The set of listeners to be sent events through the life of an animation. 3117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 32a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase ArrayList<AnimatorListener> mListeners = null; 33d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase 34d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase /** 358aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * The set of listeners to be sent pause/resume events through the life 368aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * of an animation. 378aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase */ 388aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase ArrayList<AnimatorPauseListener> mPauseListeners = null; 398aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase 408aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase /** 418aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * Whether this animator is currently in a paused state. 428aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase */ 438aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase boolean mPaused = false; 448aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase 458aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase /** 46d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * A set of flags which identify the type of configuration changes that can affect this 47d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * Animator. Used by the Animator cache. 48d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar */ 49d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar int mChangingConfigurations = 0; 50d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 51d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar /** 52d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * If this animator is inflated from a constant state, keep a reference to it so that 53d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * ConstantState will not be garbage collected until this animator is collected 54d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar */ 55d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar private AnimatorConstantState mConstantState; 56d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 57d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar /** 58a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * Starts this animation. If the animation has a nonzero startDelay, the animation will start 59b8f574a165bf6ec5b316734b367ac274ded4809bChet Haase * running after that delay elapses. A non-delayed animation will have its initial 60b8f574a165bf6ec5b316734b367ac274ded4809bChet Haase * value(s) set immediately, followed by calls to 61b8f574a165bf6ec5b316734b367ac274ded4809bChet Haase * {@link AnimatorListener#onAnimationStart(Animator)} for any listeners of this animator. 62e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * 63e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * <p>The animation started by calling this method will be run on the thread that called 64e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * this method. This thread should have a Looper on it (a runtime exception will be thrown if 65e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * this is not the case). Also, if the animation will animate 66e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * properties of objects in the view hierarchy, then the calling thread should be the UI 67e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * thread for that view hierarchy.</p> 68e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * 69d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase */ 70a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public void start() { 715d7b50b800b9898f5ca0b2b4d8b73ed6a4ee1749Chet Haase } 725d7b50b800b9898f5ca0b2b4d8b73ed6a4ee1749Chet Haase 735d7b50b800b9898f5ca0b2b4d8b73ed6a4ee1749Chet Haase /** 74a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * Cancels the animation. Unlike {@link #end()}, <code>cancel()</code> causes the animation to 75e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * stop in its tracks, sending an 76e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * {@link android.animation.Animator.AnimatorListener#onAnimationCancel(Animator)} to 77e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * its listeners, followed by an 78e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * {@link android.animation.Animator.AnimatorListener#onAnimationEnd(Animator)} message. 79e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * 80e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * <p>This method must be called on the thread that is running the animation.</p> 815d7b50b800b9898f5ca0b2b4d8b73ed6a4ee1749Chet Haase */ 82a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public void cancel() { 83fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase } 84fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase 85fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase /** 86a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * Ends the animation. This causes the animation to assign the end value of the property being 87e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * animated, then calling the 88e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * {@link android.animation.Animator.AnimatorListener#onAnimationEnd(Animator)} method on 89a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * its listeners. 90e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * 91e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * <p>This method must be called on the thread that is running the animation.</p> 9217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 93a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public void end() { 9417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 9517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 9617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 978aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * Pauses a running animation. This method should only be called on the same thread on 988aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * which the animation was started. If the animation has not yet been {@link 998aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * #isStarted() started} or has since ended, then the call is ignored. Paused 1008aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * animations can be resumed by calling {@link #resume()}. 1018aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * 1028aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @see #resume() 1038aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @see #isPaused() 1048aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @see AnimatorPauseListener 1058aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase */ 1068aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase public void pause() { 1078aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase if (isStarted() && !mPaused) { 1088aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase mPaused = true; 1098aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase if (mPauseListeners != null) { 1108aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase ArrayList<AnimatorPauseListener> tmpListeners = 1118aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase (ArrayList<AnimatorPauseListener>) mPauseListeners.clone(); 1128aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase int numListeners = tmpListeners.size(); 1138aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase for (int i = 0; i < numListeners; ++i) { 1148aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase tmpListeners.get(i).onAnimationPause(this); 1158aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 1168aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 1178aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 1188aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 1198aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase 1208aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase /** 1218aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * Resumes a paused animation, causing the animator to pick up where it left off 1228aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * when it was paused. This method should only be called on the same thread on 1238aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * which the animation was started. Calls to resume() on an animator that is 1248aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * not currently paused will be ignored. 1258aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * 1268aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @see #pause() 1278aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @see #isPaused() 1288aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @see AnimatorPauseListener 1298aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase */ 1308aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase public void resume() { 1318aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase if (mPaused) { 1328aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase mPaused = false; 1338aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase if (mPauseListeners != null) { 1348aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase ArrayList<AnimatorPauseListener> tmpListeners = 1358aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase (ArrayList<AnimatorPauseListener>) mPauseListeners.clone(); 1368aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase int numListeners = tmpListeners.size(); 1378aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase for (int i = 0; i < numListeners; ++i) { 1388aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase tmpListeners.get(i).onAnimationResume(this); 1398aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 1408aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 1418aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 1428aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 1438aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase 1448aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase /** 1458aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * Returns whether this animator is currently in a paused state. 1468aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * 1478aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @return True if the animator is currently paused, false otherwise. 1488aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * 1498aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @see #pause() 1508aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @see #resume() 1518aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase */ 1528aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase public boolean isPaused() { 1538aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase return mPaused; 1548aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 1558aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase 1568aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase /** 157e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * The amount of time, in milliseconds, to delay processing the animation 158e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * after {@link #start()} is called. 159e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * 160e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * @return the number of milliseconds to delay running the animation 161e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase */ 162e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase public abstract long getStartDelay(); 163e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase 164e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase /** 165e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * The amount of time, in milliseconds, to delay processing the animation 166e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * after {@link #start()} is called. 167e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase 168e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * @param startDelay The amount of the delay, in milliseconds 169e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase */ 170e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase public abstract void setStartDelay(long startDelay); 171e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase 172e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase /** 173e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * Sets the duration of the animation. 174e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * 175e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * @param duration The length of the animation, in milliseconds. 176e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase */ 177e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase public abstract Animator setDuration(long duration); 178e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase 179e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase /** 180e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * Gets the duration of the animation. 181e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * 182e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * @return The length of the animation, in milliseconds. 183e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase */ 184e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase public abstract long getDuration(); 185e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase 186e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase /** 187e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * The time interpolator used in calculating the elapsed fraction of the 188e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * animation. The interpolator determines whether the animation runs with 189e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * linear or non-linear motion, such as acceleration and deceleration. The 190e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * default value is {@link android.view.animation.AccelerateDecelerateInterpolator}. 191e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * 192e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * @param value the interpolator to be used by this animation 193e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase */ 194e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase public abstract void setInterpolator(TimeInterpolator value); 195e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase 196e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase /** 197e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * Returns the timing interpolator that this animation uses. 198e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * 199e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * @return The timing interpolator for this animation. 200e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase */ 201e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase public TimeInterpolator getInterpolator() { 202e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase return null; 203e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase } 204e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase 205e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase /** 2068b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase * Returns whether this Animator is currently running (having been started and gone past any 2078b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase * initial startDelay period and not yet ended). 2088b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase * 209a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * @return Whether the Animator is running. 21017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 211a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public abstract boolean isRunning(); 21217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 21317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 2148b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase * Returns whether this Animator has been started and not yet ended. This state is a superset 2158b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase * of the state of {@link #isRunning()}, because an Animator with a nonzero 2168b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase * {@link #getStartDelay() startDelay} will return true for {@link #isStarted()} during the 2178b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase * delay phase, whereas {@link #isRunning()} will return true only after the delay phase 2188b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase * is complete. 2198b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase * 2208b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase * @return Whether the Animator has been started and not yet ended. 2218b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase */ 2228b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase public boolean isStarted() { 2238b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase // Default method returns value for isRunning(). Subclasses should override to return a 2248b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase // real value. 2258b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase return isRunning(); 2268b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase } 2278b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase 2288b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase /** 229a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * Adds a listener to the set of listeners that are sent events through the life of an 230a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * animation, such as start, repeat, and end. 23117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 23217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * @param listener the listener to be added to the current set of listeners for this animation. 23317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 234a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public void addListener(AnimatorListener listener) { 235a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase if (mListeners == null) { 236a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase mListeners = new ArrayList<AnimatorListener>(); 23717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 238a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase mListeners.add(listener); 23917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 24017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 24117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 242a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * Removes a listener from the set listening to this animation. 24317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 244a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * @param listener the listener to be removed from the current set of listeners for this 245a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * animation. 24617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 247a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public void removeListener(AnimatorListener listener) { 248a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase if (mListeners == null) { 24917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase return; 25017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 251a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase mListeners.remove(listener); 252a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase if (mListeners.size() == 0) { 253a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase mListeners = null; 25417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 25517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 25617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 25717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 258a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * Gets the set of {@link android.animation.Animator.AnimatorListener} objects that are currently 259a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * listening for events on this <code>Animator</code> object. 26017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 261a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * @return ArrayList<AnimatorListener> The set of listeners. 26217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 263a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public ArrayList<AnimatorListener> getListeners() { 264a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase return mListeners; 26517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 26617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 26717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 2688aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * Adds a pause listener to this animator. 2698aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * 2708aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @param listener the listener to be added to the current set of pause listeners 2718aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * for this animation. 2728aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase */ 2738aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase public void addPauseListener(AnimatorPauseListener listener) { 2748aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase if (mPauseListeners == null) { 2758aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase mPauseListeners = new ArrayList<AnimatorPauseListener>(); 2768aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 2778aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase mPauseListeners.add(listener); 2788aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 2798aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase 2808aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase /** 2818aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * Removes a pause listener from the set listening to this animation. 2828aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * 2838aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @param listener the listener to be removed from the current set of pause 2848aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * listeners for this animation. 2858aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase */ 2868aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase public void removePauseListener(AnimatorPauseListener listener) { 2878aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase if (mPauseListeners == null) { 2888aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase return; 2898aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 2908aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase mPauseListeners.remove(listener); 2918aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase if (mPauseListeners.size() == 0) { 2928aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase mPauseListeners = null; 2938aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 2948aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 2958aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase 2968aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase /** 297d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * Removes all {@link #addListener(android.animation.Animator.AnimatorListener) listeners} 298d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * and {@link #addPauseListener(android.animation.Animator.AnimatorPauseListener) 299d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * pauseListeners} from this object. 300602e4d3824bf8b9cb9f817375d195b969712176aChet Haase */ 301a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public void removeAllListeners() { 30217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase if (mListeners != null) { 303a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase mListeners.clear(); 304a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase mListeners = null; 30517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 3068aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase if (mPauseListeners != null) { 3078aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase mPauseListeners.clear(); 3088aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase mPauseListeners = null; 3098aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 31017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 31117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 312d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar /** 313d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * Return a mask of the configuration parameters for which this animator may change, requiring 314d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * that it should be re-created from Resources. The default implementation returns whatever 315d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * value was provided through setChangingConfigurations(int) or 0 by default. 316d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * 317d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * @return Returns a mask of the changing configuration parameters, as defined by 318d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * {@link android.content.pm.ActivityInfo}. 319d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * @see android.content.pm.ActivityInfo 320d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * @hide 321d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar */ 322d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar public int getChangingConfigurations() { 323d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar return mChangingConfigurations; 324d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar } 325d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 326d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar /** 327d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * Set a mask of the configuration parameters for which this animator may change, requiring 328d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * that it be re-created from resource. 329d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * 330d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * @param configs A mask of the changing configuration parameters, as 331d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * defined by {@link android.content.pm.ActivityInfo}. 332d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * 333d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * @see android.content.pm.ActivityInfo 334d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * @hide 335d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar */ 336d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar public void setChangingConfigurations(int configs) { 337d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar mChangingConfigurations = configs; 338d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar } 339d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 340d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar /** 341d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * Sets the changing configurations value to the union of the current changing configurations 342d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * and the provided configs. 343d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * This method is called while loading the animator. 344d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * @hide 345d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar */ 346d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar public void appendChangingConfigurations(int configs) { 347d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar mChangingConfigurations |= configs; 348d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar } 349d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 350d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar /** 351d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * Return a {@link android.content.res.ConstantState} instance that holds the shared state of 352d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * this Animator. 353d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * <p> 354d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * This constant state is used to create new instances of this animator when needed, instead 355d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * of re-loading it from resources. Default implementation creates a new 356d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * {@link AnimatorConstantState}. You can override this method to provide your custom logic or 357d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * return null if you don't want this animator to be cached. 358d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * 359d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * @return The ConfigurationBoundResourceCache.BaseConstantState associated to this Animator. 360d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * @see android.content.res.ConstantState 361d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * @see #clone() 362d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * @hide 363d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar */ 364d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar public ConstantState<Animator> createConstantState() { 365d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar return new AnimatorConstantState(this); 366d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar } 367d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 3685c7649857246333572eb332b505ad617365ef5faChet Haase @Override 369a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public Animator clone() { 370a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase try { 371a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase final Animator anim = (Animator) super.clone(); 372a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase if (mListeners != null) { 373d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar anim.mListeners = new ArrayList<AnimatorListener>(mListeners); 374673e42fafd4088970ec95e1f13c61dc83132c74eChet Haase } 3758aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase if (mPauseListeners != null) { 376d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar anim.mPauseListeners = new ArrayList<AnimatorPauseListener>(mPauseListeners); 3778aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 378a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase return anim; 379a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase } catch (CloneNotSupportedException e) { 380a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase throw new AssertionError(); 381673e42fafd4088970ec95e1f13c61dc83132c74eChet Haase } 3825c7649857246333572eb332b505ad617365ef5faChet Haase } 3835c7649857246333572eb332b505ad617365ef5faChet Haase 3845c7649857246333572eb332b505ad617365ef5faChet Haase /** 385a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * This method tells the object to use appropriate information to extract 386a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * starting values for the animation. For example, a AnimatorSet object will pass 387a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * this call to its child objects to tell them to set up the values. A 388a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * ObjectAnimator object will use the information it has about its target object 389a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * and PropertyValuesHolder objects to get the start values for its properties. 390f76a50ce8fdc6aea22cabc77b2977a1a15a79630Ken Wakasa * A ValueAnimator object will ignore the request since it does not have enough 391a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * information (such as a target object) to gather these values. 3925c7649857246333572eb332b505ad617365ef5faChet Haase */ 393a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public void setupStartValues() { 3945c7649857246333572eb332b505ad617365ef5faChet Haase } 3955c7649857246333572eb332b505ad617365ef5faChet Haase 3965c7649857246333572eb332b505ad617365ef5faChet Haase /** 397a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * This method tells the object to use appropriate information to extract 398a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * ending values for the animation. For example, a AnimatorSet object will pass 399a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * this call to its child objects to tell them to set up the values. A 400a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * ObjectAnimator object will use the information it has about its target object 401a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * and PropertyValuesHolder objects to get the start values for its properties. 402f76a50ce8fdc6aea22cabc77b2977a1a15a79630Ken Wakasa * A ValueAnimator object will ignore the request since it does not have enough 403a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * information (such as a target object) to gather these values. 40417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 405a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public void setupEndValues() { 40617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 40717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 40817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 409a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * Sets the target object whose property will be animated by this animation. Not all subclasses 410a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * operate on target objects (for example, {@link ValueAnimator}, but this method 411a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * is on the superclass for the convenience of dealing generically with those subclasses 412a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * that do handle targets. 41317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 414a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * @param target The object being animated 41517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 416a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public void setTarget(Object target) { 4177bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui } 4187bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui 4197bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui // Hide reverse() and canReverse() for now since reverse() only work for simple 4207bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui // cases, like we don't support sequential, neither startDelay. 4217bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui // TODO: make reverse() works for all the Animators. 4227bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui /** 4237bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui * @hide 4247bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui */ 4257bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui public boolean canReverse() { 4267bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui return false; 4277bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui } 4287bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui 4297bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui /** 4307bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui * @hide 4317bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui */ 4327bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui public void reverse() { 433291161ac3815fb853fd6af21055d60f57a869608John Reck throw new IllegalStateException("Reverse is not supported"); 43417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 43517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 43617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 437a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * <p>An animation listener receives notifications from an animation. 438a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * Notifications indicate animation related events, such as the end or the 439a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * repetition of the animation.</p> 44017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 441a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public static interface AnimatorListener { 442a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase /** 443a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * <p>Notifies the start of the animation.</p> 444a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * 445a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * @param animation The started animation. 446a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase */ 447a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase void onAnimationStart(Animator animation); 44817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 449a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase /** 450a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * <p>Notifies the end of the animation. This callback is not invoked 451a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * for animations with repeat count set to INFINITE.</p> 452a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * 453a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * @param animation The animation which reached its end. 454a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase */ 455a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase void onAnimationEnd(Animator animation); 45617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 457a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase /** 458a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * <p>Notifies the cancellation of the animation. This callback is not invoked 459a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * for animations with repeat count set to INFINITE.</p> 460a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * 461a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * @param animation The animation which was canceled. 462a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase */ 463a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase void onAnimationCancel(Animator animation); 46449afa5bc100e5d4c069fea980dd6b09501f56397Chet Haase 46517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 466a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * <p>Notifies the repetition of the animation.</p> 46717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 46817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * @param animation The animation which was repeated. 46917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 470a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase void onAnimationRepeat(Animator animation); 47117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 4728aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase 4738aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase /** 4748aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * A pause listener receives notifications from an animation when the 4758aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * animation is {@link #pause() paused} or {@link #resume() resumed}. 4768aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * 4778aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @see #addPauseListener(AnimatorPauseListener) 4788aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase */ 4798aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase public static interface AnimatorPauseListener { 4808aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase /** 4818aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * <p>Notifies that the animation was paused.</p> 4828aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * 4838aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @param animation The animaton being paused. 4848aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @see #pause() 4858aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase */ 4868aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase void onAnimationPause(Animator animation); 4878aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase 4888aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase /** 4898aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * <p>Notifies that the animation was resumed, after being 4908aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * previously paused.</p> 4918aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * 4928aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @param animation The animation being resumed. 4938aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @see #resume() 4948aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase */ 4958aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase void onAnimationResume(Animator animation); 4968aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 497c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck 498c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck /** 499c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * <p>Whether or not the Animator is allowed to run asynchronously off of 500c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * the UI thread. This is a hint that informs the Animator that it is 501c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * OK to run the animation off-thread, however the Animator may decide 502c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * that it must run the animation on the UI thread anyway. 503c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * 504c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * <p>Regardless of whether or not the animation runs asynchronously, all 505c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * listener callbacks will be called on the UI thread.</p> 506c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * 507c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * <p>To be able to use this hint the following must be true:</p> 508c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * <ol> 509c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * <li>The animator is immutable while {@link #isStarted()} is true. Requests 510c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * to change duration, delay, etc... may be ignored.</li> 511c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * <li>Lifecycle callback events may be asynchronous. Events such as 512c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * {@link Animator.AnimatorListener#onAnimationEnd(Animator)} or 513c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * {@link Animator.AnimatorListener#onAnimationRepeat(Animator)} may end up delayed 514c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * as they must be posted back to the UI thread, and any actions performed 515c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * by those callbacks (such as starting new animations) will not happen 516c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * in the same frame.</li> 517c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * <li>State change requests ({@link #cancel()}, {@link #end()}, {@link #reverse()}, etc...) 518c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * may be asynchronous. It is guaranteed that all state changes that are 519c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * performed on the UI thread in the same frame will be applied as a single 520c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * atomic update, however that frame may be the current frame, 521c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * the next frame, or some future frame. This will also impact the observed 522c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * state of the Animator. For example, {@link #isStarted()} may still return true 523c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * after a call to {@link #end()}. Using the lifecycle callbacks is preferred over 524c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * queries to {@link #isStarted()}, {@link #isRunning()}, and {@link #isPaused()} 525c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * for this reason.</li> 526c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * </ol> 527c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * @hide 528c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck */ 529c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck public void setAllowRunningAsynchronously(boolean mayRunAsync) { 530c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck // It is up to subclasses to support this, if they can. 531c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck } 532d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 533d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar /** 534d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * Creates a {@link ConstantState} which holds changing configurations information associated 535d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * with the given Animator. 536d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * <p> 537d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * When {@link #newInstance()} is called, default implementation clones the Animator. 538d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar */ 539d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar private static class AnimatorConstantState extends ConstantState<Animator> { 540d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 541d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar final Animator mAnimator; 542d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar int mChangingConf; 543d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 544d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar public AnimatorConstantState(Animator animator) { 545d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar mAnimator = animator; 546d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar // ensure a reference back to here so that constante state is not gc'ed. 547d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar mAnimator.mConstantState = this; 548d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar mChangingConf = mAnimator.getChangingConfigurations(); 549d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar } 550d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 551d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar @Override 552d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar public int getChangingConfigurations() { 553d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar return mChangingConf; 554d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar } 555d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 556d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar @Override 557d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar public Animator newInstance() { 558d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar final Animator clone = mAnimator.clone(); 559d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar clone.mConstantState = this; 560d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar return clone; 561d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar } 562d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar } 563a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase} 564