package com.tommymacwilliam.androidwalkthroughapp3;

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.ImageView;
import android.widget.Toast;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class AndroidWalkthroughApp3 extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        try {
        	// load large image from resources
        	Bitmap background = BitmapFactory.decodeResource(this.getResources(), R.drawable.puzzle_0);
        	// create cropped image from loaded image
        	Bitmap cropped = Bitmap.createBitmap(background, 0, 0, 100, 100);
        	// no longer need larger image
        	background.recycle();
        	
        	// create ImageView to display image
        	ImageView imageView = new ImageView(this);
        	imageView.setImageBitmap(cropped);
        	
        	// add ImageView to root layout
        	LinearLayout root = (LinearLayout)this.findViewById(R.id.root_layout);
        	root.addView(imageView);
        	
        	int screenWidth = this.getResources().getDisplayMetrics().widthPixels;
        	Toast.makeText(this, String.valueOf(screenWidth), Toast.LENGTH_LONG).show();
        }
        catch (OutOfMemoryError e) {
        	// uh oh.
        }
    }
}