Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to listen for animation end in AnimatedVectorDrawables

Tags:

I have created an AnimatedVectorDrawable, it works pretty well, now I am looking for a way to change the animation or hide the view after it finishes. I was hoping there was a listener but it doesn't look like there is. Can someone help?

EDIT

So I found a workaround, but not a very elegant way. What I did was create a thread and poll if the animation is running.

new Runnable() {     public void run() {         while(mLoop) {             if(mAnimatedVectorDrawable.isRunning()) {                 Thread.sleep(mPollingInterval);             } else {                 mLoop = false;                 // TODO what ever             }         }     } }; 

If somebody finds a better solution, please share.

like image 461
Naveen Dissanayake Avatar asked Mar 02 '15 14:03

Naveen Dissanayake


1 Answers

Not tried this yet but Android 6.0 has a registerAnimationCallback method from the Animatable2 interface for this

Edit: yep this works in Android 6.0 emulator:

mAnimatedVectorDrawable.registerAnimationCallback (new Animatable2.AnimationCallback(){     public void onAnimationEnd(Drawable drawable){         //Do something     } } 

Edit2: looks like they haven't added support for this in the AnimatedVectorDrawableCompat from support lib 23.2+ :(

Edit3: it looks like this got added in support lib 25.3.0

Thanks Carson!

like image 87
Mark Avatar answered Sep 25 '22 07:09

Mark