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 19e60a693d847a160b7a0d70046eb1d0e6d2cb4f10Chet Haaseimport android.annotation.Nullable; 20ac85f90466dd60d2af8ffc3942d503a0de606726Alan Viveretteimport android.content.pm.ActivityInfo.Config; 21d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyarimport android.content.res.ConstantState; 22d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 2317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haaseimport java.util.ArrayList; 2417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 2517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase/** 26a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * This is the superclass for classes which provide basic support for animations which can be 27a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * started, ended, and have <code>AnimatorListeners</code> added to them. 2817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 29e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haasepublic abstract class Animator implements Cloneable { 3017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 3117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 321309914ebf21e705fc59d7d44014124d8a21a2d2Doris Liu * The value used to indicate infinite duration (e.g. when Animators repeat infinitely). 331309914ebf21e705fc59d7d44014124d8a21a2d2Doris Liu */ 341309914ebf21e705fc59d7d44014124d8a21a2d2Doris Liu public static final long DURATION_INFINITE = -1; 351309914ebf21e705fc59d7d44014124d8a21a2d2Doris Liu /** 3617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * The set of listeners to be sent events through the life of an animation. 3717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 38a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase ArrayList<AnimatorListener> mListeners = null; 39d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase 40d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase /** 418aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * The set of listeners to be sent pause/resume events through the life 428aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * of an animation. 438aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase */ 448aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase ArrayList<AnimatorPauseListener> mPauseListeners = null; 458aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase 468aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase /** 478aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * Whether this animator is currently in a paused state. 488aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase */ 498aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase boolean mPaused = false; 508aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase 518aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase /** 52d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * A set of flags which identify the type of configuration changes that can affect this 53d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * Animator. Used by the Animator cache. 54d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar */ 55ac85f90466dd60d2af8ffc3942d503a0de606726Alan Viverette @Config int mChangingConfigurations = 0; 56d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 57d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar /** 58d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * If this animator is inflated from a constant state, keep a reference to it so that 59d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * ConstantState will not be garbage collected until this animator is collected 60d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar */ 61d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar private AnimatorConstantState mConstantState; 62d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 63d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar /** 64a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * Starts this animation. If the animation has a nonzero startDelay, the animation will start 65b8f574a165bf6ec5b316734b367ac274ded4809bChet Haase * running after that delay elapses. A non-delayed animation will have its initial 66b8f574a165bf6ec5b316734b367ac274ded4809bChet Haase * value(s) set immediately, followed by calls to 67b8f574a165bf6ec5b316734b367ac274ded4809bChet Haase * {@link AnimatorListener#onAnimationStart(Animator)} for any listeners of this animator. 68e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * 69e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * <p>The animation started by calling this method will be run on the thread that called 70e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * this method. This thread should have a Looper on it (a runtime exception will be thrown if 71e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * this is not the case). Also, if the animation will animate 72e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * properties of objects in the view hierarchy, then the calling thread should be the UI 73e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * thread for that view hierarchy.</p> 74e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * 75d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase */ 76a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public void start() { 775d7b50b800b9898f5ca0b2b4d8b73ed6a4ee1749Chet Haase } 785d7b50b800b9898f5ca0b2b4d8b73ed6a4ee1749Chet Haase 795d7b50b800b9898f5ca0b2b4d8b73ed6a4ee1749Chet Haase /** 80a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * Cancels the animation. Unlike {@link #end()}, <code>cancel()</code> causes the animation to 81e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * stop in its tracks, sending an 82e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * {@link android.animation.Animator.AnimatorListener#onAnimationCancel(Animator)} to 83e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * its listeners, followed by an 84e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * {@link android.animation.Animator.AnimatorListener#onAnimationEnd(Animator)} message. 85e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * 86e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * <p>This method must be called on the thread that is running the animation.</p> 875d7b50b800b9898f5ca0b2b4d8b73ed6a4ee1749Chet Haase */ 88a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public void cancel() { 89fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase } 90fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase 91fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase /** 92a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * Ends the animation. This causes the animation to assign the end value of the property being 93e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * animated, then calling the 94e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * {@link android.animation.Animator.AnimatorListener#onAnimationEnd(Animator)} method on 95a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * its listeners. 96e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * 97e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase * <p>This method must be called on the thread that is running the animation.</p> 9817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 99a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public void end() { 10017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 10117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 10217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 1038aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * Pauses a running animation. This method should only be called on the same thread on 1048aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * which the animation was started. If the animation has not yet been {@link 1058aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * #isStarted() started} or has since ended, then the call is ignored. Paused 1068aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * animations can be resumed by calling {@link #resume()}. 1078aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * 1088aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @see #resume() 1098aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @see #isPaused() 1108aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @see AnimatorPauseListener 1118aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase */ 1128aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase public void pause() { 1138aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase if (isStarted() && !mPaused) { 1148aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase mPaused = true; 1158aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase if (mPauseListeners != null) { 1168aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase ArrayList<AnimatorPauseListener> tmpListeners = 1178aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase (ArrayList<AnimatorPauseListener>) mPauseListeners.clone(); 1188aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase int numListeners = tmpListeners.size(); 1198aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase for (int i = 0; i < numListeners; ++i) { 1208aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase tmpListeners.get(i).onAnimationPause(this); 1218aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 1228aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 1238aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 1248aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 1258aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase 1268aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase /** 1278aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * Resumes a paused animation, causing the animator to pick up where it left off 1288aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * when it was paused. This method should only be called on the same thread on 1298aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * which the animation was started. Calls to resume() on an animator that is 1308aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * not currently paused will be ignored. 1318aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * 1328aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @see #pause() 1338aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @see #isPaused() 1348aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @see AnimatorPauseListener 1358aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase */ 1368aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase public void resume() { 1378aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase if (mPaused) { 1388aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase mPaused = false; 1398aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase if (mPauseListeners != null) { 1408aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase ArrayList<AnimatorPauseListener> tmpListeners = 1418aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase (ArrayList<AnimatorPauseListener>) mPauseListeners.clone(); 1428aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase int numListeners = tmpListeners.size(); 1438aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase for (int i = 0; i < numListeners; ++i) { 1448aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase tmpListeners.get(i).onAnimationResume(this); 1458aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 1468aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 1478aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 1488aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 1498aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase 1508aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase /** 1518aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * Returns whether this animator is currently in a paused state. 1528aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * 1538aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @return True if the animator is currently paused, false otherwise. 1548aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * 1558aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @see #pause() 1568aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @see #resume() 1578aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase */ 1588aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase public boolean isPaused() { 1598aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase return mPaused; 1608aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 1618aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase 1628aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase /** 163e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * The amount of time, in milliseconds, to delay processing the animation 164e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * after {@link #start()} is called. 165e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * 166e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * @return the number of milliseconds to delay running the animation 167e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase */ 168e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase public abstract long getStartDelay(); 169e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase 170e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase /** 171e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * The amount of time, in milliseconds, to delay processing the animation 172e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * after {@link #start()} is called. 173e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase 174e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * @param startDelay The amount of the delay, in milliseconds 175e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase */ 176e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase public abstract void setStartDelay(long startDelay); 177e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase 178e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase /** 179e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * Sets the duration of the animation. 180e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * 181e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * @param duration The length of the animation, in milliseconds. 182e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase */ 183e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase public abstract Animator setDuration(long duration); 184e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase 185e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase /** 186e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * Gets the duration of the animation. 187e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * 188e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * @return The length of the animation, in milliseconds. 189e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase */ 190e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase public abstract long getDuration(); 191e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase 192e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase /** 1931309914ebf21e705fc59d7d44014124d8a21a2d2Doris Liu * Gets the total duration of the animation, accounting for animation sequences, start delay, 1941309914ebf21e705fc59d7d44014124d8a21a2d2Doris Liu * and repeating. Return {@link #DURATION_INFINITE} if the duration is infinite. 1958b7c99cca2c9996a0ac2d87f24bd3ef83fd10be5Doris Liu * 1968b7c99cca2c9996a0ac2d87f24bd3ef83fd10be5Doris Liu * @return Total time an animation takes to finish, starting from the time {@link #start()} 1978b7c99cca2c9996a0ac2d87f24bd3ef83fd10be5Doris Liu * is called. {@link #DURATION_INFINITE} will be returned if the animation or any 1988b7c99cca2c9996a0ac2d87f24bd3ef83fd10be5Doris Liu * child animation repeats infinite times. 1991309914ebf21e705fc59d7d44014124d8a21a2d2Doris Liu */ 2001309914ebf21e705fc59d7d44014124d8a21a2d2Doris Liu public long getTotalDuration() { 2018b7c99cca2c9996a0ac2d87f24bd3ef83fd10be5Doris Liu long duration = getDuration(); 2028b7c99cca2c9996a0ac2d87f24bd3ef83fd10be5Doris Liu if (duration == DURATION_INFINITE) { 2038b7c99cca2c9996a0ac2d87f24bd3ef83fd10be5Doris Liu return DURATION_INFINITE; 2048b7c99cca2c9996a0ac2d87f24bd3ef83fd10be5Doris Liu } else { 2058b7c99cca2c9996a0ac2d87f24bd3ef83fd10be5Doris Liu return getStartDelay() + duration; 2068b7c99cca2c9996a0ac2d87f24bd3ef83fd10be5Doris Liu } 2071309914ebf21e705fc59d7d44014124d8a21a2d2Doris Liu } 2081309914ebf21e705fc59d7d44014124d8a21a2d2Doris Liu 2091309914ebf21e705fc59d7d44014124d8a21a2d2Doris Liu /** 210e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * The time interpolator used in calculating the elapsed fraction of the 211e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * animation. The interpolator determines whether the animation runs with 212e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * linear or non-linear motion, such as acceleration and deceleration. The 213e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * default value is {@link android.view.animation.AccelerateDecelerateInterpolator}. 214e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * 215e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * @param value the interpolator to be used by this animation 216e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase */ 217e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase public abstract void setInterpolator(TimeInterpolator value); 218e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase 219e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase /** 220e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * Returns the timing interpolator that this animation uses. 221e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * 222e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase * @return The timing interpolator for this animation. 223e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase */ 224e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase public TimeInterpolator getInterpolator() { 225e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase return null; 226e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase } 227e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase 228e8cee38c6a8dd54cc222cbbd8655ae32a66a8e73Chet Haase /** 2298b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase * Returns whether this Animator is currently running (having been started and gone past any 2308b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase * initial startDelay period and not yet ended). 2318b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase * 232a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * @return Whether the Animator is running. 23317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 234a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public abstract boolean isRunning(); 23517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 23617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 2374ddd9257d60c378ddcf5b537ea2a03b80629f097Chet Haase * Returns whether this Animator has been started and not yet ended. For reusable 2384ddd9257d60c378ddcf5b537ea2a03b80629f097Chet Haase * Animators (which most Animators are, apart from the one-shot animator produced by 2394ddd9257d60c378ddcf5b537ea2a03b80629f097Chet Haase * {@link android.view.ViewAnimationUtils#createCircularReveal( 2404ddd9257d60c378ddcf5b537ea2a03b80629f097Chet Haase * android.view.View, int, int, float, float) createCircularReveal()}), 2414ddd9257d60c378ddcf5b537ea2a03b80629f097Chet Haase * this state is a superset of {@link #isRunning()}, because an Animator with a 2424ddd9257d60c378ddcf5b537ea2a03b80629f097Chet Haase * nonzero {@link #getStartDelay() startDelay} will return true for {@link #isStarted()} during 2434ddd9257d60c378ddcf5b537ea2a03b80629f097Chet Haase * the delay phase, whereas {@link #isRunning()} will return true only after the delay phase 2444ddd9257d60c378ddcf5b537ea2a03b80629f097Chet Haase * is complete. Non-reusable animators will always return true after they have been 2454ddd9257d60c378ddcf5b537ea2a03b80629f097Chet Haase * started, because they cannot return to a non-started state. 2468b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase * 2478b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase * @return Whether the Animator has been started and not yet ended. 2488b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase */ 2498b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase public boolean isStarted() { 2508b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase // Default method returns value for isRunning(). Subclasses should override to return a 2518b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase // real value. 2528b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase return isRunning(); 2538b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase } 2548b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase 2558b699792b677bd4dd8442b32641ac09d48fdd79cChet Haase /** 256a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * Adds a listener to the set of listeners that are sent events through the life of an 257a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * animation, such as start, repeat, and end. 25817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 25917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * @param listener the listener to be added to the current set of listeners for this animation. 26017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 261a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public void addListener(AnimatorListener listener) { 262a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase if (mListeners == null) { 263a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase mListeners = new ArrayList<AnimatorListener>(); 26417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 265a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase mListeners.add(listener); 26617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 26717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 26817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 269a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * Removes a listener from the set listening to this animation. 27017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 271a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * @param listener the listener to be removed from the current set of listeners for this 272a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * animation. 27317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 274a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public void removeListener(AnimatorListener listener) { 275a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase if (mListeners == null) { 27617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase return; 27717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 278a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase mListeners.remove(listener); 279a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase if (mListeners.size() == 0) { 280a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase mListeners = null; 28117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 28217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 28317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 28417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 285a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * Gets the set of {@link android.animation.Animator.AnimatorListener} objects that are currently 286a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * listening for events on this <code>Animator</code> object. 28717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 288a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * @return ArrayList<AnimatorListener> The set of listeners. 28917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 290a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public ArrayList<AnimatorListener> getListeners() { 291a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase return mListeners; 29217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 29317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 29417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 2958aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * Adds a pause listener to this animator. 2968aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * 2978aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @param listener the listener to be added to the current set of pause listeners 2988aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * for this animation. 2998aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase */ 3008aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase public void addPauseListener(AnimatorPauseListener listener) { 3018aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase if (mPauseListeners == null) { 3028aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase mPauseListeners = new ArrayList<AnimatorPauseListener>(); 3038aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 3048aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase mPauseListeners.add(listener); 3058aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 3068aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase 3078aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase /** 3088aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * Removes a pause listener from the set listening to this animation. 3098aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * 3108aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @param listener the listener to be removed from the current set of pause 3118aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * listeners for this animation. 3128aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase */ 3138aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase public void removePauseListener(AnimatorPauseListener listener) { 3148aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase if (mPauseListeners == null) { 3158aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase return; 3168aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 3178aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase mPauseListeners.remove(listener); 3188aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase if (mPauseListeners.size() == 0) { 3198aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase mPauseListeners = null; 3208aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 3218aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 3228aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase 3238aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase /** 324d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * Removes all {@link #addListener(android.animation.Animator.AnimatorListener) listeners} 325d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * and {@link #addPauseListener(android.animation.Animator.AnimatorPauseListener) 326d82c8ac4db7091d2e976af4c89a1734465d20cd2Chet Haase * pauseListeners} from this object. 327602e4d3824bf8b9cb9f817375d195b969712176aChet Haase */ 328a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public void removeAllListeners() { 32917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase if (mListeners != null) { 330a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase mListeners.clear(); 331a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase mListeners = null; 33217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 3338aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase if (mPauseListeners != null) { 3348aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase mPauseListeners.clear(); 3358aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase mPauseListeners = null; 3368aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 33717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 33817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 339d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar /** 340d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * Return a mask of the configuration parameters for which this animator may change, requiring 341d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * that it should be re-created from Resources. The default implementation returns whatever 342d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * value was provided through setChangingConfigurations(int) or 0 by default. 343d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * 344d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * @return Returns a mask of the changing configuration parameters, as defined by 345d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * {@link android.content.pm.ActivityInfo}. 346d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * @see android.content.pm.ActivityInfo 347d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * @hide 348d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar */ 349ac85f90466dd60d2af8ffc3942d503a0de606726Alan Viverette public @Config int getChangingConfigurations() { 350d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar return mChangingConfigurations; 351d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar } 352d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 353d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar /** 354d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * Set a mask of the configuration parameters for which this animator may change, requiring 355d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * that it be re-created from resource. 356d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * 357d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * @param configs A mask of the changing configuration parameters, as 358d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * defined by {@link android.content.pm.ActivityInfo}. 359d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * 360d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * @see android.content.pm.ActivityInfo 361d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * @hide 362d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar */ 363ac85f90466dd60d2af8ffc3942d503a0de606726Alan Viverette public void setChangingConfigurations(@Config int configs) { 364d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar mChangingConfigurations = configs; 365d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar } 366d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 367d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar /** 368d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * Sets the changing configurations value to the union of the current changing configurations 369d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * and the provided configs. 370d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * This method is called while loading the animator. 371d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * @hide 372d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar */ 373ac85f90466dd60d2af8ffc3942d503a0de606726Alan Viverette public void appendChangingConfigurations(@Config int configs) { 374d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar mChangingConfigurations |= configs; 375d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar } 376d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 377d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar /** 378d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * Return a {@link android.content.res.ConstantState} instance that holds the shared state of 379d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * this Animator. 380d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * <p> 381d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * This constant state is used to create new instances of this animator when needed, instead 382d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * of re-loading it from resources. Default implementation creates a new 383d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * {@link AnimatorConstantState}. You can override this method to provide your custom logic or 384d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * return null if you don't want this animator to be cached. 385d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * 386d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * @return The ConfigurationBoundResourceCache.BaseConstantState associated to this Animator. 387d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * @see android.content.res.ConstantState 388d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * @see #clone() 389d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * @hide 390d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar */ 391d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar public ConstantState<Animator> createConstantState() { 392d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar return new AnimatorConstantState(this); 393d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar } 394d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 3955c7649857246333572eb332b505ad617365ef5faChet Haase @Override 396a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public Animator clone() { 397a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase try { 398a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase final Animator anim = (Animator) super.clone(); 399a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase if (mListeners != null) { 400d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar anim.mListeners = new ArrayList<AnimatorListener>(mListeners); 401673e42fafd4088970ec95e1f13c61dc83132c74eChet Haase } 4028aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase if (mPauseListeners != null) { 403d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar anim.mPauseListeners = new ArrayList<AnimatorPauseListener>(mPauseListeners); 4048aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 405a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase return anim; 406a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase } catch (CloneNotSupportedException e) { 407a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase throw new AssertionError(); 408673e42fafd4088970ec95e1f13c61dc83132c74eChet Haase } 4095c7649857246333572eb332b505ad617365ef5faChet Haase } 4105c7649857246333572eb332b505ad617365ef5faChet Haase 4115c7649857246333572eb332b505ad617365ef5faChet Haase /** 412a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * This method tells the object to use appropriate information to extract 413a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * starting values for the animation. For example, a AnimatorSet object will pass 414a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * this call to its child objects to tell them to set up the values. A 415a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * ObjectAnimator object will use the information it has about its target object 416a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * and PropertyValuesHolder objects to get the start values for its properties. 417f76a50ce8fdc6aea22cabc77b2977a1a15a79630Ken Wakasa * A ValueAnimator object will ignore the request since it does not have enough 418a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * information (such as a target object) to gather these values. 4195c7649857246333572eb332b505ad617365ef5faChet Haase */ 420a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public void setupStartValues() { 4215c7649857246333572eb332b505ad617365ef5faChet Haase } 4225c7649857246333572eb332b505ad617365ef5faChet Haase 4235c7649857246333572eb332b505ad617365ef5faChet Haase /** 424a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * This method tells the object to use appropriate information to extract 425a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * ending values for the animation. For example, a AnimatorSet object will pass 426a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * this call to its child objects to tell them to set up the values. A 427a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * ObjectAnimator object will use the information it has about its target object 428a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * and PropertyValuesHolder objects to get the start values for its properties. 429f76a50ce8fdc6aea22cabc77b2977a1a15a79630Ken Wakasa * A ValueAnimator object will ignore the request since it does not have enough 430a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * information (such as a target object) to gather these values. 43117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 432a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public void setupEndValues() { 43317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 43417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 43517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 436a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * Sets the target object whose property will be animated by this animation. Not all subclasses 437a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * operate on target objects (for example, {@link ValueAnimator}, but this method 438a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * is on the superclass for the convenience of dealing generically with those subclasses 439a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * that do handle targets. 440e60a693d847a160b7a0d70046eb1d0e6d2cb4f10Chet Haase * <p> 441e60a693d847a160b7a0d70046eb1d0e6d2cb4f10Chet Haase * <strong>Note:</strong> The target is stored as a weak reference internally to avoid leaking 442e60a693d847a160b7a0d70046eb1d0e6d2cb4f10Chet Haase * resources by having animators directly reference old targets. Therefore, you should 443e60a693d847a160b7a0d70046eb1d0e6d2cb4f10Chet Haase * ensure that animator targets always have a hard reference elsewhere. 44417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 445a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * @param target The object being animated 44617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 447e60a693d847a160b7a0d70046eb1d0e6d2cb4f10Chet Haase public void setTarget(@Nullable Object target) { 4487bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui } 4497bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui 4507bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui // Hide reverse() and canReverse() for now since reverse() only work for simple 4517bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui // cases, like we don't support sequential, neither startDelay. 4527bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui // TODO: make reverse() works for all the Animators. 4537bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui /** 4547bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui * @hide 4557bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui */ 4567bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui public boolean canReverse() { 4577bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui return false; 4587bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui } 4597bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui 4607bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui /** 4617bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui * @hide 4627bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui */ 4637bc6a3f023ca3e1dde91fc97b6036dee3ba538a2ztenghui public void reverse() { 464291161ac3815fb853fd6af21055d60f57a869608John Reck throw new IllegalStateException("Reverse is not supported"); 46517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 46617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 46717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 468a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * <p>An animation listener receives notifications from an animation. 469a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * Notifications indicate animation related events, such as the end or the 470a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * repetition of the animation.</p> 47117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 472a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public static interface AnimatorListener { 473a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase /** 474a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * <p>Notifies the start of the animation.</p> 475a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * 476a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * @param animation The started animation. 477a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase */ 478a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase void onAnimationStart(Animator animation); 47917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 480a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase /** 481a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * <p>Notifies the end of the animation. This callback is not invoked 482a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * for animations with repeat count set to INFINITE.</p> 483a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * 484a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * @param animation The animation which reached its end. 485a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase */ 486a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase void onAnimationEnd(Animator animation); 48717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 488a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase /** 489a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * <p>Notifies the cancellation of the animation. This callback is not invoked 490a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * for animations with repeat count set to INFINITE.</p> 491a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * 492a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * @param animation The animation which was canceled. 493a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase */ 494a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase void onAnimationCancel(Animator animation); 49549afa5bc100e5d4c069fea980dd6b09501f56397Chet Haase 49617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 497a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * <p>Notifies the repetition of the animation.</p> 49817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 49917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * @param animation The animation which was repeated. 50017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 501a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase void onAnimationRepeat(Animator animation); 50217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 5038aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase 5048aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase /** 5058aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * A pause listener receives notifications from an animation when the 5068aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * animation is {@link #pause() paused} or {@link #resume() resumed}. 5078aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * 5088aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @see #addPauseListener(AnimatorPauseListener) 5098aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase */ 5108aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase public static interface AnimatorPauseListener { 5118aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase /** 5128aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * <p>Notifies that the animation was paused.</p> 5138aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * 5148aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @param animation The animaton being paused. 5158aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @see #pause() 5168aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase */ 5178aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase void onAnimationPause(Animator animation); 5188aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase 5198aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase /** 5208aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * <p>Notifies that the animation was resumed, after being 5218aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * previously paused.</p> 5228aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * 5238aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @param animation The animation being resumed. 5248aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase * @see #resume() 5258aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase */ 5268aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase void onAnimationResume(Animator animation); 5278aa1ffb0ed292891030992c65df4e5dc8bd37524Chet Haase } 528c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck 529c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck /** 530c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * <p>Whether or not the Animator is allowed to run asynchronously off of 531c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * the UI thread. This is a hint that informs the Animator that it is 532c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * OK to run the animation off-thread, however the Animator may decide 533c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * that it must run the animation on the UI thread anyway. 534c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * 535c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * <p>Regardless of whether or not the animation runs asynchronously, all 536c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * listener callbacks will be called on the UI thread.</p> 537c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * 538c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * <p>To be able to use this hint the following must be true:</p> 539c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * <ol> 540c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * <li>The animator is immutable while {@link #isStarted()} is true. Requests 541c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * to change duration, delay, etc... may be ignored.</li> 542c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * <li>Lifecycle callback events may be asynchronous. Events such as 543c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * {@link Animator.AnimatorListener#onAnimationEnd(Animator)} or 544c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * {@link Animator.AnimatorListener#onAnimationRepeat(Animator)} may end up delayed 545c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * as they must be posted back to the UI thread, and any actions performed 546c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * by those callbacks (such as starting new animations) will not happen 547c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * in the same frame.</li> 548c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * <li>State change requests ({@link #cancel()}, {@link #end()}, {@link #reverse()}, etc...) 549c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * may be asynchronous. It is guaranteed that all state changes that are 550c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * performed on the UI thread in the same frame will be applied as a single 551c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * atomic update, however that frame may be the current frame, 552c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * the next frame, or some future frame. This will also impact the observed 553c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * state of the Animator. For example, {@link #isStarted()} may still return true 554c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * after a call to {@link #end()}. Using the lifecycle callbacks is preferred over 555c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * queries to {@link #isStarted()}, {@link #isRunning()}, and {@link #isPaused()} 556c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * for this reason.</li> 557c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * </ol> 558c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck * @hide 559c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck */ 560c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck public void setAllowRunningAsynchronously(boolean mayRunAsync) { 561c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck // It is up to subclasses to support this, if they can. 562c01bd1167a1b08d59557f214ddc48cf24d3b8d0aJohn Reck } 563d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 564d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar /** 565d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * Creates a {@link ConstantState} which holds changing configurations information associated 566d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * with the given Animator. 567d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * <p> 568d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar * When {@link #newInstance()} is called, default implementation clones the Animator. 569d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar */ 570d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar private static class AnimatorConstantState extends ConstantState<Animator> { 571d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 572d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar final Animator mAnimator; 573ac85f90466dd60d2af8ffc3942d503a0de606726Alan Viverette @Config int mChangingConf; 574d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 575d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar public AnimatorConstantState(Animator animator) { 576d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar mAnimator = animator; 577d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar // ensure a reference back to here so that constante state is not gc'ed. 578d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar mAnimator.mConstantState = this; 579d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar mChangingConf = mAnimator.getChangingConfigurations(); 580d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar } 581d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 582d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar @Override 583ac85f90466dd60d2af8ffc3942d503a0de606726Alan Viverette public @Config int getChangingConfigurations() { 584d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar return mChangingConf; 585d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar } 586d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar 587d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar @Override 588d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar public Animator newInstance() { 589d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar final Animator clone = mAnimator.clone(); 590d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar clone.mConstantState = this; 591d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar return clone; 592d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar } 593d422dc358f0100106dc07d7b903201eb9b043b11Yigit Boyar } 594a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase} 595