Tweak to compile with Android 1.5 but still work in 1.1

git-svn-id: https://zxing.googlecode.com/svn/trunk@908 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2009-04-15 09:58:54 +00:00
parent 02f779cbee
commit f908920992
2 changed files with 13 additions and 4 deletions

View file

@ -26,6 +26,8 @@ import android.view.Display;
import android.view.SurfaceHolder;
import android.view.WindowManager;
import java.io.IOException;
/**
* This object wraps the Camera service object and expects to be the only one talking to it. The
* implementation encapsulates the steps needed to take preview-sized images, which are used for
@ -46,7 +48,7 @@ final class CameraManager {
private int mAutoFocusMessage;
private boolean mPreviewing;
public static void init(Context context) {
public static synchronized void init(Context context) {
if (mCameraManager == null) {
mCameraManager = new CameraManager(context);
mCameraManager.getScreenResolution();
@ -63,11 +65,11 @@ final class CameraManager {
mPreviewing = false;
}
public void openDriver(SurfaceHolder holder) {
public void openDriver(SurfaceHolder holder) throws IOException {
// "throws IOException added to accommodate Android 1.5
if (mCamera == null) {
mCamera = Camera.open();
mCamera.setPreviewDisplay(holder);
setCameraParameters();
}
}

View file

@ -27,6 +27,8 @@ import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;
import java.io.IOException;
public final class CameraTestActivity extends Activity implements SurfaceHolder.Callback {
private SaveThread mSaveThread;
@ -109,7 +111,12 @@ public final class CameraTestActivity extends Activity implements SurfaceHolder.
}
public void surfaceCreated(SurfaceHolder holder) {
CameraManager.get().openDriver(holder);
try {
CameraManager.get().openDriver(holder);
} catch (IOException ioe) {
// IOException clause added for Android 1.5
throw new RuntimeException(ioe);
}
CameraManager.get().startPreview();
}