package toyo.jungle.magicdoodoo;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        final ImageView maimuta = (ImageView) findViewById(R.id.imageView1);
        final ImageView frunza = (ImageView) findViewById(R.id.imageView2);
        final ImageView frunza2 = (ImageView) findViewById(R.id.imageView3);
        
		final Animation maimutaAnimation = AnimationUtils.loadAnimation(this, R.anim.rotate);
		maimuta.startAnimation(maimutaAnimation);
		
		final Animation frunzaAnimation = AnimationUtils.loadAnimation(this, R.anim.frunza);
		frunza.startAnimation(frunzaAnimation);
		
		final Animation frunza2Animation = AnimationUtils.loadAnimation(this, R.anim.frunza2);
		frunza2.startAnimation(frunza2Animation);
		
		final MediaPlayer mp=MediaPlayer.create(getApplicationContext(), R.raw.wahwah);
		
		maimuta.setOnClickListener (new ImageView.OnClickListener(){
			@Override
			public void onClick(View v) {
				//maimuta.clearAnimation(); 
				maimuta.setImageDrawable(null);				
				animate();	
				mp.start();	
			}});
	    }

	private void animate(){
        ImageView imgView = (ImageView)findViewById(R.id.imageView1);
        imgView.setVisibility(View.VISIBLE);
        imgView.setBackgroundResource(R.drawable.animation);
        AnimationDrawable frameAnimation = (AnimationDrawable) imgView.getBackground();
   
        if(frameAnimation.isRunning()) {
            frameAnimation.stop();
            frameAnimation.start();
        }
        else{
            frameAnimation.stop();
            frameAnimation.start();
        }
    }
}

