package com.example.dancingbear;

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

public class MainActivity extends Activity {
	
	AnimationDrawable bearAnimation;	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		final ImageView bearAnimHolder = (ImageView) findViewById(R.id.imageView1); 
		bearAnimHolder.setBackgroundResource(R.drawable.bear_anim);
		bearAnimHolder.post(new Runnable() {
			public void run() {
				bearAnimation = (AnimationDrawable) bearAnimHolder.getBackground();
			}
		} );
		
		  final MediaPlayer mp=MediaPlayer.create(getApplicationContext(), R.raw.bear);
		    
		    
		    Button ok=(Button)findViewById(R.id.button1);
		    ok.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					
					mp.start();
					
				}
			});
	}

	public boolean onTouchEvent(MotionEvent event) {   
		if (event.getAction() == MotionEvent.ACTION_DOWN) {     
			bearAnimation.start();     
			return true;   }   
		return super.onTouchEvent(event); }
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
