// Path: src/com/koonen/utils/StreamUtils.java
// public class StreamUtils {
// 	private static final String TAG = "StreamUtils";
// 
// 	private static final int IO_BUFFER_SIZE = 1024 * 8;
// 
// 	/**
// 	 * Copy the content of the input stream into the output stream, using a
// 	 * temporary byte array buffer whose size is defined by
// 	 * {@link #IO_BUFFER_SIZE}.
// 	 * 
// 	 * @param in
// 	 *            The input stream to copy from.
// 	 * @param out
// 	 *            The output stream to copy to.
// 	 * 
// 	 * @throws IOException
// 	 *             If any error occurs during the copy.
// 	 */
// 	public static void copy(InputStream in, OutputStream out)
// 			throws IOException {
// 		byte[] b = new byte[IO_BUFFER_SIZE];
// 		int read;
// 		while ((read = in.read(b)) != -1) {
// 			out.write(b, 0, read);
// 		}
// 	}
// 
// 	/**
// 	 * Closes the specified stream.
// 	 * 
// 	 * @param stream
// 	 *            The stream to close.
// 	 */
// 	public static void closeStream(Closeable stream) {
// 		if (stream != null) {
// 			try {
// 				stream.close();
// 			} catch (IOException e) {
// 				android.util.Log.e(TAG, "Could not close stream", e);
// 			}
// 		}
// 	}
// 
// 	// TODO: refactore
// 	public static boolean saveBitmap(Context context, Bitmap bitmap,
// 			String filePath) {
// 		boolean result = false;
// 		try {
// 			FileOutputStream fos = context.openFileOutput(filePath,
// 					Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE);
// 
// 			bitmap.compress(CompressFormat.JPEG, 100, fos);
// 
// 			fos.flush();
// 			fos.close();
// 			result = true;
// 		} catch (Exception e) {
// 			Log.e(TAG, e.toString());
// 		}
// 		return result;
// 	}
// }


import java.util.concurrent.Semaphore;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.hardware.Camera;
import android.hardware.Camera.PictureCallback;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.Window;
import com.koonen.utils.StreamUtils;
		// Create our Preview view and set it as the content of our activity.
		mPreview = new Preview(this);
		setContentView(mPreview);
	}

	private static final int MENU_ITEM_TAKE_PICTURE = 1;

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		menu.add(0, MENU_ITEM_TAKE_PICTURE, 0, R.string.camera_take_picture);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case MENU_ITEM_TAKE_PICTURE:
			Thread thread = new Thread(new Runnable() {

				@Override
				public void run() {
					mPreview.setTakePicture(true);
					mPreview.takePicture();
					try {
						mPreview.getSemaphore().acquire();
					} catch (InterruptedException e) {

					}
					Bitmap bitmap = mPreview.getPicture();
// Path: src/com/koonen/utils/StreamUtils.java
// public class StreamUtils {
// 	private static final String TAG = "StreamUtils";
// 
// 	private static final int IO_BUFFER_SIZE = 1024 * 8;
// 
// 	/**
// 	 * Copy the content of the input stream into the output stream, using a
// 	 * temporary byte array buffer whose size is defined by
// 	 * {@link #IO_BUFFER_SIZE}.
// 	 * 
// 	 * @param in
// 	 *            The input stream to copy from.
// 	 * @param out
// 	 *            The output stream to copy to.
// 	 * 
// 	 * @throws IOException
// 	 *             If any error occurs during the copy.
// 	 */
// 	public static void copy(InputStream in, OutputStream out)
// 			throws IOException {
// 		byte[] b = new byte[IO_BUFFER_SIZE];
// 		int read;
// 		while ((read = in.read(b)) != -1) {
// 			out.write(b, 0, read);
// 		}
// 	}
// 
// 	/**
// 	 * Closes the specified stream.
// 	 * 
// 	 * @param stream
// 	 *            The stream to close.
// 	 */
// 	public static void closeStream(Closeable stream) {
// 		if (stream != null) {
// 			try {
// 				stream.close();
// 			} catch (IOException e) {
// 				android.util.Log.e(TAG, "Could not close stream", e);
// 			}
// 		}
// 	}
// 
// 	// TODO: refactore
// 	public static boolean saveBitmap(Context context, Bitmap bitmap,
// 			String filePath) {
// 		boolean result = false;
// 		try {
// 			FileOutputStream fos = context.openFileOutput(filePath,
// 					Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE);
// 
// 			bitmap.compress(CompressFormat.JPEG, 100, fos);
// 
// 			fos.flush();
// 			fos.close();
// 			result = true;
// 		} catch (Exception e) {
// 			Log.e(TAG, e.toString());
// 		}
// 		return result;
// 	}
// }


// Path: src/com/koonen/photostream/CameraPreviewActivity.java
import java.util.concurrent.Semaphore;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.hardware.Camera;
import android.hardware.Camera.PictureCallback;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.Window;
import com.koonen.utils.StreamUtils;

		// Create our Preview view and set it as the content of our activity.
		mPreview = new Preview(this);
		setContentView(mPreview);
	}

	private static final int MENU_ITEM_TAKE_PICTURE = 1;

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		menu.add(0, MENU_ITEM_TAKE_PICTURE, 0, R.string.camera_take_picture);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case MENU_ITEM_TAKE_PICTURE:
			Thread thread = new Thread(new Runnable() {

				@Override
				public void run() {
					mPreview.setTakePicture(true);
					mPreview.takePicture();
					try {
						mPreview.getSemaphore().acquire();
					} catch (InterruptedException e) {

					}
					Bitmap bitmap = mPreview.getPicture();
					StreamUtils.saveBitmap(CameraPreviewActivity.this, bitmap,