Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How can we backport withEndAction to older versions, with help of Nine Old Androids

Tags:

android

I'm working on something which requires about 10 animations to be played one after another, but there are some conditions to be checked at the end of each animation, so I can't use animation set or setStartDelay.

I found it very easy to do on Jelly Bean with new methods on of which is withEndAction while I was doing it as an experiment, but now I've to implement it in an App with minSdk 10.

I'm using Nine Old Android and it works great, but using setListner is very difficult and creates code that is difficult to maintain for 10 consecutive animations.

So I was thinking, creating an Adapter that inherits from nine old androids and I could add withEndAction function which executes the runnable?

Can someone guide me on how to do that, and is there any better way of doing this?

Thanks

like image 498
user1976900 Avatar asked Jan 14 '13 10:01

user1976900


2 Answers

I used setListener

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        viewPropertyAnimator.setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                doSomething();
            }
        });
    } else {
        viewPropertyAnimator.withEndAction(new Runnable() {
            @Override
            public void run() {
                doSomething();
            }
        });
    }
like image 169
Blundell Avatar answered Oct 28 '22 20:10

Blundell


You can now use ViewCompat and append any animations you want.

ViewCompat.animate(yourView).scaleY(3).withEndAction(yourRunnable).start();
like image 7
Markymark Avatar answered Oct 28 '22 22:10

Markymark