0
 public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.genie_out);



        genie = (ImageView) findViewById(R.id.genieout);
        startService(new Intent(this, MyService2.class));
        SceneAnimation come = new SceneAnimation(genie, comingout,     durationcomingout);
        SceneAnimation circled = new SceneAnimation(genie, circle,durationcircle);

       come.play(1);



       circled.play(1);


    }

There is one ImageView and it takes the whole screen, i want to figure how to wait until come.play(1) is done to play circle.play(1), like this circle plays first and then come plays out the rest of itself because come is a longer animation, i would like to know this also because i have more services i would like to start and stop along the way too, thank you for your time

class SceneAnimation {
public int x;
public ImageView mImageView;
public int[] mFrameRess;
public int[] mDurations;
public int mDuration;

public int mLastFrameNo;
public long mBreakDelay;


 public SceneAnimation(ImageView pImageView, int[] pFrameRess, int[] pDurations)
 {

    mImageView = pImageView;
    mFrameRess = pFrameRess;
    mDurations = pDurations;
    mLastFrameNo = pFrameRess.length - 1;

    play(1);
}

public SceneAnimation(ImageView pImageView, int[] pFrameRess, int pDuration){
    mImageView = pImageView;
    mFrameRess = pFrameRess;
    mDuration = pDuration;
    mLastFrameNo = pFrameRess.length - 1;

    mImageView.setImageResource(mFrameRess[0]);

    playConstant(1);
}

public SceneAnimation(ImageView pImageView, int[] pFrameRess, int pDuration, long pBreakDelay){            
    mImageView = pImageView;
    mFrameRess = pFrameRess;
    mDuration = pDuration;
    mLastFrameNo = pFrameRess.length - 1;
    mBreakDelay = pBreakDelay;

    mImageView.setImageResource(mFrameRess[0]);
    playConstant(1);
}


   public void play(final int pFrameNo)
{


    mImageView.postDelayed(new Runnable(){
        public void run() {


            mImageView.setImageResource(mFrameRess[pFrameNo]);
            if(pFrameNo == mLastFrameNo)
                {
                return;}
            else
                play(pFrameNo + 1);
        }
    }, mDurations[pFrameNo]);
}


public void playConstant(final int pFrameNo){
    mImageView.postDelayed(new Runnable(){
        public void run() {                    
            mImageView.setImageResource(mFrameRess[pFrameNo]);

            if(pFrameNo == mLastFrameNo)
                playConstant(0);
            else
                playConstant(pFrameNo + 1);
        }
    }, pFrameNo==mLastFrameNo && mBreakDelay>0 ? mBreakDelay : mDuration);
}



};
JRowan
  • 6,824
  • 8
  • 40
  • 59
  • You probably should use `AnimationListener`. set the animtionlistener to the first animation and at `onAnimationEnd`, start the second animation. – Wenhui Nov 18 '12 at 02:19
  • its not an animation class the AnimationListener wont know when the end is, ill put on the code to SceneAnimation i dont know how to make AnimationListener run through the class, maybe you can help – JRowan Nov 18 '12 at 12:32
  • I might be wrong, but SceneAnimation looks like Frame Animation. Have you considered using [`AnimationDrawable`](http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html), that supports frame by frame animation. Otherwise, you can provide your own animation listener. I will post the answer below. – Wenhui Nov 19 '12 at 01:33

1 Answers1

1

Here is one way to implement your own AnimationListener

package com.example.intentfiletersample;

import android.widget.ImageView;

class SceneAnimation {
public int x;
public ImageView mImageView;
public int[] mFrameRess;
public int[] mDurations;
public int mDuration;

public int mLastFrameNo;
public long mBreakDelay;

private AnimationListener mAnimationListener;

public SceneAnimation( ImageView pImageView, int[] pFrameRess, int[] pDurations ) {

    mImageView = pImageView;
    mFrameRess = pFrameRess;
    mDurations = pDurations;
    mLastFrameNo = pFrameRess.length - 1;

    play( 1 );
}

public SceneAnimation( ImageView pImageView, int[] pFrameRess, int pDuration ) {
    mImageView = pImageView;
    mFrameRess = pFrameRess;
    mDuration = pDuration;
    mLastFrameNo = pFrameRess.length - 1;

    mImageView.setImageResource( mFrameRess[0] );

    playConstant( 1 );
}

public SceneAnimation( ImageView pImageView, int[] pFrameRess, int pDuration, long pBreakDelay ) {
    mImageView = pImageView;
    mFrameRess = pFrameRess;
    mDuration = pDuration;
    mLastFrameNo = pFrameRess.length - 1;
    mBreakDelay = pBreakDelay;

    mImageView.setImageResource( mFrameRess[0] );
    playConstant( 1 );
}

public void setAnimationListener(AnimationListener listener){
    this.mAnimationListener = listener;
}

public void play( final int pFrameNo ) {

    mImageView.postDelayed( new Runnable() {
        public void run() {

            mImageView.setImageResource( mFrameRess[pFrameNo] );
            if ( pFrameNo == mLastFrameNo ) {
                return;
            } else
                play( pFrameNo + 1 );

            // Callback when animation ends.
            if( mAnimationListener != null ){
                mAnimationListener.onAnimationEnd();
            }
        }
    }, mDurations[pFrameNo] );
}

public void playConstant( final int pFrameNo ) {
    mImageView.postDelayed( new Runnable() {
        public void run() {
            mImageView.setImageResource( mFrameRess[pFrameNo] );

            if ( pFrameNo == mLastFrameNo )
                playConstant( 0 );
            else
                playConstant( pFrameNo + 1 );

            // Callback when animation ends.
            if( mAnimationListener != null ){
                mAnimationListener.onAnimationEnd();
            }
        }
    }, pFrameNo == mLastFrameNo && mBreakDelay > 0 ? mBreakDelay : mDuration );
}


public static interface AnimationListener {
    public void onAnimationEnd();
    // You can add onAnimationStart(), and do the same thing like onAnimationEnd.
}
};

It is always recommended that you first go through the Animation API comes with Android sdk, see if one that fits you before implementing your own.

HOPE THIS HELP.

Wenhui
  • 648
  • 4
  • 13
  • thank you this is the solution i was looking for,i didnt try yet but im going to right now, i had to make this class because animationdrawable kept exceeding VM budget i have about 80 full frames, im gona try right now – JRowan Nov 19 '12 at 02:51
  • you saved me from the last 48hrs straight researching a solution, thank you so much, do you use != null to set onAnimationRepeat()? thank you again so much, im going to go delete all my other questions about this now it was my first time setting up the AnimationListener – JRowan Nov 19 '12 at 03:30
  • 1
    I am glad that this works for you. There might be something wrong on your code when you are using AniamtionDrawable and get OOM error. It is always good habit to check if `mAnimation!=null` to avoid NPE, you can do the same thing to `onAimationRepeat()`, just place the call to the appropriate place. – Wenhui Nov 19 '12 at 03:51