Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between AnimationListener and AnimatorListener?

I would like to use the AnimatorListenerAdapter, specified here:

http://developer.android.com/reference/android/animation/AnimatorListenerAdapter.html

But, it implements the AnimatorListener interface. On a View, such as an ImageView, there is a method called setAnimationListener(), but it takes, as a parameter, an AnimationListener. There doesn't seem to be an associated AnimationListenerAdapter available.

My question is what is the difference between AnimatorListener and AnimationListener, and why do the two separate interfaces exist? It seems like they both provide the same functionality. The only difference I can see is that one of them was introduced in a later API version.

like image 336
jwir3 Avatar asked Dec 18 '13 22:12

jwir3


2 Answers

AnimationListener is for the old style View animations, while AnimatorListener is for the new (as of 3.0) Animator APIs.

All AnimatorListenerAdapter does is implement the AnimatorListener interface with no functionality. You can easily create your own AnimationListenerAdapter in the same way by creating a public non-final class which implements AnimationListener with no functionality.

like image 94
Kevin Coppock Avatar answered Oct 27 '22 14:10

Kevin Coppock


For lazy people as us :

import android.view.animation.Animation

/**
 * Adapter to reduce code implementation of Animation.AnimationListener when there are unused
 * functions.
 */
open class AnimationListenerAdapter: Animation.AnimationListener {

    /**
     *
     * Notifies the start of the animation.
     *
     * @param animation The started animation.
     */
    override fun onAnimationStart(animation: Animation) {

    }

    /**
     *
     * Notifies the end of the animation. This callback is not invoked
     * for animations with repeat count set to INFINITE.
     *
     * @param animation The animation which reached its end.
     */
    override fun onAnimationEnd(animation: Animation) {

    }

    /**
     *
     * Notifies the repetition of the animation.
     *
     * @param animation The animation which was repeated.
     */
    override fun onAnimationRepeat(animation: Animation) {

    }

}

like image 32
htafoya Avatar answered Oct 27 '22 16:10

htafoya