I'm thinking about exposing the Animator.AnimatorListener
callbacks on the YoYo
class.
By doing this, we allow granular handling of animation events
YoYo.with(Techniques.FadeIn)
.onStart( )
.onCancel( )
.onEnd( )
.onRepeat( )
.playOn(View)
Each of this methods should take a single method interface. For example:
interface AnimatorCallback {
public void call( Animator animator);
}
By doing this, you can subscribe to the event you like, without having to implement the full Animator.AnimatorListener
interface yourself.
Internally, YoYo
will have to instantiate an Animator.AnimatorListener
if any of this methods is called, and the created instance will then call all the added AnimatorCallback
's
So we go from this
YoYo.with(Techniques.FadeIn)
.withListener( new Animator.AnimatorListener {
@Override
public void onAnimationStart(Animator animation) {
Log.d(TAG, "Animation started");
}
@Override
public void onAnimationEnd(Animator animation) {
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
})
.playOn(view)
to this
YoYo.with(Techniques.FadeIn)
.onStart( new AnimatorCallback() {
public void call( Animator anim){
Log.d(TAG, "Animation started");
}
})
.playOn(view)
Also, by AnimatorCallback
being a single method interface, we can eliminate the boilerplate if we use retrolambda (you should!) like the following:
YoYo.with(Techniques.FadeIn)
.onStart( anim -> Log.d(TAG, "Animation started") )
.playOn(View)
What do you guys think? I'm willing to work on this and provide a pull request if you think is a good idea.
Thanks
Robert