Tweak to compile with Android 1.5 but still work in 1.1
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Wed, 15 Apr 2009 09:58:54 +0000 (09:58 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Wed, 15 Apr 2009 09:58:54 +0000 (09:58 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@908 59b500cc-1b3d-0410-9834-0bbf25fbcc57

androidtest/src/com/google/zxing/client/androidtest/CameraManager.java
androidtest/src/com/google/zxing/client/androidtest/CameraTestActivity.java

index 049aefc..723a021 100755 (executable)
@@ -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();
     }
   }
index 84ce1f8..0ea89ac 100755 (executable)
@@ -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();
   }