package net.cs76.lectures.intents08;

import net.cs76.lectures.intents08.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

/* ShowImage.java
 * A new activity that accepts, via the Intent bundle,
 * an ID representing the image to display full-screen
 * to the user.
 */
public class ShowImage extends Activity implements OnClickListener {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        setContentView(R.layout.single_photo);

        // find our ImageView in the layout
        ImageView img = (ImageView)findViewById(R.id.single_image);

        // retrieve the set of data passed to us by the Intent
        Bundle extras = getIntent().getExtras();

        // and retrieve the imageToDisplay ID from the extras bundle
        int resource = (int)extras.getLong("imageToDisplay");

        // set the ImageView to display the specified resource ID
        img.setImageResource(resource);

        // close the Activity when a user taps/clicks on the image.
        img.setOnClickListener(this);
	}
	
	/*
	 * finishes (closes) the activity when the user clicks on the image
	 */
	public void onClick(View v) {
		finish();
	}
}
