package com.appsolut.example.animation;



import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class Animation extends Activity {

	/**
	 * Reference to the ImageView which will display the animation.
	 */
	ImageView animation;
	Button Start;
	Button Stop;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Start=(Button)findViewById(R.id.btnStart);
        Stop=(Button)findViewById(R.id.btnStop);
       animation = (ImageView)findViewById(R.id.imageAnimation);
        
        animation.setBackgroundResource(R.drawable.animation);		// the frame-by-frame animation defined as a xml file within the drawable folder
      final   AnimationDrawable frameAnimation = (AnimationDrawable) animation.getBackground();
        /*
         * NOTE: It's not possible to start the animation during the onCreate.
         * 
         */
        
        Start.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				frameAnimation.start();  //Start the Animation
			}
		});
        
        
        Stop.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				frameAnimation.stop();  // Stop the Animation
			}
		});
    }
    
   
    
   
    
}