Safer check for Build SDK; restrict Behold II workaround to Cupcake, per Samsung
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Wed, 26 May 2010 07:01:58 +0000 (07:01 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Wed, 26 May 2010 07:01:58 +0000 (07:01 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@1390 59b500cc-1b3d-0410-9834-0bbf25fbcc57

android/src/com/google/zxing/client/android/camera/CameraConfigurationManager.java
android/src/com/google/zxing/client/android/camera/CameraManager.java

index d0257ca..cb8daa3 100644 (file)
@@ -181,7 +181,9 @@ final class CameraConfigurationManager {
   private void setFlash(Camera.Parameters parameters) {
     // FIXME: This is a hack to turn the flash off on the Samsung Galaxy.
     // And this is a hack-hack to work around a different value on the Behold II
-    if (Build.MODEL.contains("Behold II")) {
+    // Restrict Behold II check to Cupcake, per Samsung's advice
+    if (Build.MODEL.contains("Behold II") &&
+        CameraManager.SDK_INT == Build.VERSION_CODES.CUPCAKE) {
       parameters.set("flash-value", 1);
     } else {
       parameters.set("flash-value", 2);
index 7824da4..53c11ba 100755 (executable)
@@ -50,6 +50,18 @@ public final class CameraManager {
 
   private static CameraManager cameraManager;
 
+  static final int SDK_INT; // Later we can use Build.VERSION.SDK_INT
+  static {
+    int sdkInt;
+    try {
+      sdkInt = Integer.parseInt(Build.VERSION.SDK);
+    } catch (NumberFormatException nfe) {
+      // Just to be safe
+      sdkInt = 10000;
+    }
+    SDK_INT = sdkInt;
+  }
+
   private final Context context;
   private final CameraConfigurationManager configManager;
   private Camera camera;
@@ -95,7 +107,7 @@ public final class CameraManager {
     // Camera.setPreviewCallback() on 1.5 and earlier. For Donut and later, we need to use
     // the more efficient one shot callback, as the older one can swamp the system and cause it
     // to run out of memory. We can't use SDK_INT because it was introduced in the Donut SDK.
-    useOneShotPreviewCallback = Integer.parseInt(Build.VERSION.SDK) > Build.VERSION_CODES.CUPCAKE;
+    useOneShotPreviewCallback = SDK_INT > Build.VERSION_CODES.CUPCAKE;
 
     previewCallback = new PreviewCallback(configManager, useOneShotPreviewCallback);
     autoFocusCallback = new AutoFocusCallback();