Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set animation listener to Activity animations

Tags:

I am using overridePendingTransition method to perform custom Activity animations.

I would like to know when the animation ends ( a callback/listener ).

Is there any direct way of achieving this, if not please suggest me some work around.

like image 750
akc Avatar asked Aug 02 '10 08:08

akc


1 Answers

I use this method to start any animation (resID of the animation XML). If nextPuzzleOnEnd is true, the method "nextPuzzle" is called when the animation has finished.

The method is part of my puzzle-apps and I use it to display any success animation and afterwards (after anim has finished) continue with the next puzzle.

 /*
 * start animation (any view)
 */
 private void startAnimation(View v, int resId, Boolean nextPuzzleOnEnd){
    Animation anim;

    if(v!=null){    // can be null, after change of orientation
            anim = AnimationUtils.loadAnimation(this.getContext(),resId);
            anim.setFillAfter(false);
            v.setAnimation(anim);
            if( nextPuzzleOnEnd ){
                anim.setAnimationListener(new AnimationListener() {
                    public void onAnimationStart(Animation anim)
                    {
                    };
                    public void onAnimationRepeat(Animation anim)
                    {
                    };
                    public void onAnimationEnd(Animation anim)
                    {
                        nextPuzzle();
                    };
                });                     
            }
            v.startAnimation(anim);                 
    }
  }
like image 138
Michael Biermann Avatar answered Oct 25 '22 00:10

Michael Biermann