Android Open Source - NineOldAndroids Time Animator






From Project

Back to project page NineOldAndroids.

License

The source code is released under:

Apache License

If you think the Android project NineOldAndroids listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.nineoldandroids.animation;
/* w w w.j a v a2  s.  co m*/
/**
 * This class provides a simple callback mechanism to listeners that is synchronized with other
 * animators in the system. There is no duration, interpolation, or object value-setting
 * with this Animator. Instead, it is simply started and proceeds to send out events on every
 * animation frame to its TimeListener (if set), with information about this animator,
 * the total elapsed time, and the time since the last animation frame.
 *
 * @hide
 */
public class TimeAnimator extends ValueAnimator {

    private TimeListener mListener;
    private long mPreviousTime = -1;

    @Override
    boolean animationFrame(long currentTime) {
        if (mPlayingState == STOPPED) {
            mPlayingState = RUNNING;
            if (mSeekTime < 0) {
                mStartTime = currentTime;
            } else {
                mStartTime = currentTime - mSeekTime;
                // Now that we're playing, reset the seek time
                mSeekTime = -1;
            }
        }
        if (mListener != null) {
            long totalTime = currentTime - mStartTime;
            long deltaTime = (mPreviousTime < 0) ? 0 : (currentTime - mPreviousTime);
            mPreviousTime = currentTime;
            mListener.onTimeUpdate(this, totalTime, deltaTime);
        }
        return false;
    }

    /**
     * Sets a listener that is sent update events throughout the life of
     * an animation.
     *
     * @param listener the listener to be set.
     */
    public void setTimeListener(TimeListener listener) {
        mListener = listener;
    }

    @Override
    void animateValue(float fraction) {
        // Noop
    }

    @Override
    void initAnimation() {
        // noop
    }

    /**
     * Implementors of this interface can set themselves as update listeners
     * to a <code>TimeAnimator</code> instance to receive callbacks on every animation
     * frame to receive the total time since the animator started and the delta time
     * since the last frame. The first time the listener is called, totalTime and
     * deltaTime should both be zero.
     *
     * @hide
     */
    public static interface TimeListener {
        /**
         * <p>Notifies listeners of the occurrence of another frame of the animation,
         * along with information about the elapsed time.</p>
         *
         * @param animation The animator sending out the notification.
         * @param totalTime The
         */
        void onTimeUpdate(TimeAnimator animation, long totalTime, long deltaTime);

    }
}




Java Source Code List

com.jakewharton.nineoldandroids.sample.Demos.java
com.jakewharton.nineoldandroids.sample.Toggles.java
com.jakewharton.nineoldandroids.sample.VPADemo.java
com.jakewharton.nineoldandroids.sample.apidemos.AnimationCloning.java
com.jakewharton.nineoldandroids.sample.apidemos.AnimationLoading.java
com.jakewharton.nineoldandroids.sample.apidemos.AnimationSeeking.java
com.jakewharton.nineoldandroids.sample.apidemos.AnimatorEvents.java
com.jakewharton.nineoldandroids.sample.apidemos.BouncingBalls.java
com.jakewharton.nineoldandroids.sample.apidemos.CustomEvaluator.java
com.jakewharton.nineoldandroids.sample.apidemos.MultiPropertyAnimation.java
com.jakewharton.nineoldandroids.sample.apidemos.ReversingAnimation.java
com.jakewharton.nineoldandroids.sample.apidemos.ShapeHolder.java
com.jakewharton.nineoldandroids.sample.droidflakes.Droidflakes.java
com.jakewharton.nineoldandroids.sample.droidflakes.FlakeView.java
com.jakewharton.nineoldandroids.sample.droidflakes.Flake.java
com.jakewharton.nineoldandroids.sample.pathanimation.AnimatorPath.java
com.jakewharton.nineoldandroids.sample.pathanimation.PathAnimationActivity.java
com.jakewharton.nineoldandroids.sample.pathanimation.PathEvaluator.java
com.jakewharton.nineoldandroids.sample.pathanimation.PathPoint.java
com.nineoldandroids.animation.AnimatorInflater.java
com.nineoldandroids.animation.AnimatorListenerAdapter.java
com.nineoldandroids.animation.AnimatorSet.java
com.nineoldandroids.animation.Animator.java
com.nineoldandroids.animation.ArgbEvaluator.java
com.nineoldandroids.animation.FloatEvaluator.java
com.nineoldandroids.animation.FloatKeyframeSet.java
com.nineoldandroids.animation.IntEvaluator.java
com.nineoldandroids.animation.IntKeyframeSet.java
com.nineoldandroids.animation.KeyframeSet.java
com.nineoldandroids.animation.Keyframe.java
com.nineoldandroids.animation.ObjectAnimator.java
com.nineoldandroids.animation.PreHoneycombCompat.java
com.nineoldandroids.animation.PropertyValuesHolder.java
com.nineoldandroids.animation.TimeAnimator.java
com.nineoldandroids.animation.TypeEvaluator.java
com.nineoldandroids.animation.ValueAnimator.java
com.nineoldandroids.util.FloatProperty.java
com.nineoldandroids.util.IntProperty.java
com.nineoldandroids.util.NoSuchPropertyException.java
com.nineoldandroids.util.Property.java
com.nineoldandroids.util.ReflectiveProperty.java
com.nineoldandroids.view.ViewHelper.java
com.nineoldandroids.view.ViewPropertyAnimatorHC.java
com.nineoldandroids.view.ViewPropertyAnimatorICS.java
com.nineoldandroids.view.ViewPropertyAnimatorPreHC.java
com.nineoldandroids.view.ViewPropertyAnimator.java
com.nineoldandroids.view.animation.AnimatorProxy.java