/** * Constructs and returns a ValueAnimator that animates between Object values. A single * value implies that that value is the one being animated to. However, this is not typically * useful in a ValueAnimator object because there is no way for the object to determine the * starting value for the animation (unlike ObjectAnimator, which can derive that value * from the target object and property being animated). Therefore, there should typically * be two or more values. * * <p>Since ValueAnimator does not know how to animate between arbitrary Objects, this * factory method also takes a TypeEvaluator object that the ValueAnimator will use * to perform that interpolation. * * @param evaluator A TypeEvaluator that will be called on each animation frame to * provide the ncessry interpolation between the Object values to derive the animated * value. * @param values A set of values that the animation will animate between over time. * @return A ValueAnimator object that is set up to animate between the given values. */ public static ValueAnimator ofObject(TypeEvaluator evaluator, Object... values) { ValueAnimator anim = new ValueAnimator(); anim.setObjectValues(values); anim.setEvaluator(evaluator); return anim; }
@Override public void end() { if (!sAnimations.get().contains(this) && !sPendingAnimations.get().contains(this)) { // Special case if the animation has not yet started; get it ready for ending mStartedDelay = false; startAnimation(); } else if (!mInitialized) { initAnimation(); } // The final value set on the target varies, depending on whether the animation // was supposed to repeat an odd number of times if (mRepeatCount > 0 && (mRepeatCount & 0x01) == 1) { animateValue(0f); } else { animateValue(1f); } endAnimation(); }
/** * Sets the position of the animation to the specified point in time. This time should * be between 0 and the total duration of the animation, including any repetition. If * the animation has not yet been started, then it will not advance forward after it is * set to this time; it will simply set the time to this value and perform any appropriate * actions based on that time. If the animation is already running, then setCurrentPlayTime() * will set the current playing time to this value and continue playing from that point. * * @param playTime The time, in milliseconds, to which the animation is advanced or rewound. */ public void setCurrentPlayTime(long playTime) { initAnimation(); long currentTime = AnimationUtils.currentAnimationTimeMillis(); if (mPlayingState != RUNNING) { mSeekTime = playTime; mPlayingState = SEEKED; } mStartTime = currentTime - playTime; animationFrame(currentTime); }
/** * Constructs and returns a ValueAnimator that animates between the values * specified in the PropertyValuesHolder objects. * * @param values A set of PropertyValuesHolder objects whose values will be animated * between over time. * @return A ValueAnimator object that is set up to animate between the given values. */ public static ValueAnimator ofPropertyValuesHolder(PropertyValuesHolder... values) { ValueAnimator anim = new ValueAnimator(); anim.setValues(values); return anim; } /**
/** * Constructs and returns a ValueAnimator that animates between int values. A single * value implies that that value is the one being animated to. However, this is not typically * useful in a ValueAnimator object because there is no way for the object to determine the * starting value for the animation (unlike ObjectAnimator, which can derive that value * from the target object and property being animated). Therefore, there should typically * be two or more values. * * @param values A set of values that the animation will animate between over time. * @return A ValueAnimator object that is set up to animate between the given values. */ public static ValueAnimator ofInt(int... values) { ValueAnimator anim = new ValueAnimator(); anim.setIntValues(values); return anim; }
/** * Constructs and returns a ValueAnimator that animates between float values. A single * value implies that that value is the one being animated to. However, this is not typically * useful in a ValueAnimator object because there is no way for the object to determine the * starting value for the animation (unlike ObjectAnimator, which can derive that value * from the target object and property being animated). Therefore, there should typically * be two or more values. * * @param values A set of values that the animation will animate between over time. * @return A ValueAnimator object that is set up to animate between the given values. */ public static ValueAnimator ofFloat(float... values) { ValueAnimator anim = new ValueAnimator(); anim.setFloatValues(values); return anim; }
mDelayAnim = ValueAnimator.ofFloat(0f, 1f); mDelayAnim.setDuration(mStartDelay); mDelayAnim.addListener(new AnimatorListenerAdapter() { boolean canceled = false; public void onAnimationCancel(Animator anim) { mDelayAnim.start();
if (mStartDelay == 0) { setCurrentPlayTime(getCurrentPlayTime()); mPlayingState = STOPPED; mRunning = true;
/** * Called internally to start an animation by adding it to the active animations list. Must be * called on the UI thread. */ private void startAnimation() { initAnimation(); sAnimations.get().add(this); if (mStartDelay > 0 && mListeners != null) { // Listeners were already notified in start() if startDelay is 0; this is // just for delayed animations ArrayList<AnimatorListener> tmpListeners = (ArrayList<AnimatorListener>) mListeners.clone(); int numListeners = tmpListeners.size(); for (int i = 0; i < numListeners; ++i) { tmpListeners.get(i).onAnimationStart(this); } } }
/** * This method is called with the elapsed fraction of the animation during every * animation frame. This function turns the elapsed fraction into an interpolated fraction * and then into an animated value (from the evaluator. The function is called mostly during * animation updates, but it is also called when the <code>end()</code> * function is called, to set the final value on the property. * * <p>Overrides of this method must call the superclass to perform the calculation * of the animated value.</p> * * @param fraction The elapsed fraction of the animation. */ @Override void animateValue(float fraction) { super.animateValue(fraction); int numValues = mValues.length; for (int i = 0; i < numValues; ++i) { mValues[i].setAnimatedValue(mTarget); } }
@Override public ObjectAnimator clone() { final ObjectAnimator anim = (ObjectAnimator) super.clone(); return anim; }
@Override public void cancel() { // Only cancel if the animation is actually running or has been started and is about // to run if (mPlayingState != STOPPED || sPendingAnimations.get().contains(this) || sDelayedAnims.get().contains(this)) { // Only notify listeners if the animator has actually started if (mRunning && mListeners != null) { ArrayList<AnimatorListener> tmpListeners = (ArrayList<AnimatorListener>) mListeners.clone(); for (AnimatorListener listener : tmpListeners) { listener.onAnimationCancel(this); } } endAnimation(); } }
mDelayAnim.cancel();
while (i < numAnims) { ValueAnimator anim = animations.get(i); if (anim.animationFrame(currentTime)) { endingAnims.add(anim);
mDelayAnim = ValueAnimator.ofFloat(0f, 1f); mDelayAnim.setDuration(mStartDelay); mDelayAnim.addListener(new AnimatorListenerAdapter() { boolean canceled = false; public void onAnimationCancel(Animator anim) { mDelayAnim.start();
/** * Constructs and returns a ValueAnimator that animates between the values * specified in the PropertyValuesHolder objects. * * @param values A set of PropertyValuesHolder objects whose values will be animated * between over time. * @return A ValueAnimator object that is set up to animate between the given values. */ public static ValueAnimator ofPropertyValuesHolder(PropertyValuesHolder... values) { ValueAnimator anim = new ValueAnimator(); anim.setValues(values); return anim; } /**
/** * Constructs and returns a ValueAnimator that animates between int values. A single * value implies that that value is the one being animated to. However, this is not typically * useful in a ValueAnimator object because there is no way for the object to determine the * starting value for the animation (unlike ObjectAnimator, which can derive that value * from the target object and property being animated). Therefore, there should typically * be two or more values. * * @param values A set of values that the animation will animate between over time. * @return A ValueAnimator object that is set up to animate between the given values. */ public static ValueAnimator ofInt(int... values) { ValueAnimator anim = new ValueAnimator(); anim.setIntValues(values); return anim; }
/** * Constructs and returns a ValueAnimator that animates between float values. A single * value implies that that value is the one being animated to. However, this is not typically * useful in a ValueAnimator object because there is no way for the object to determine the * starting value for the animation (unlike ObjectAnimator, which can derive that value * from the target object and property being animated). Therefore, there should typically * be two or more values. * * @param values A set of values that the animation will animate between over time. * @return A ValueAnimator object that is set up to animate between the given values. */ public static ValueAnimator ofFloat(float... values) { ValueAnimator anim = new ValueAnimator(); anim.setFloatValues(values); return anim; }