Backing out this change for the Droid on suspicion that it's interfering with at...
[zxing.git] / android / src / com / google / zxing / client / android / CaptureActivity.java
index ba5ca28..e6f6de8 100755 (executable)
@@ -19,6 +19,7 @@ package com.google.zxing.client.android;
 import com.google.zxing.BarcodeFormat;
 import com.google.zxing.Result;
 import com.google.zxing.ResultPoint;
+import com.google.zxing.client.android.camera.CameraManager;
 import com.google.zxing.client.android.history.HistoryManager;
 import com.google.zxing.client.android.result.ResultButtonListener;
 import com.google.zxing.client.android.result.ResultHandler;
@@ -112,7 +113,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
     PRODUCT_FORMATS.add(BarcodeFormat.UPC_E);
     PRODUCT_FORMATS.add(BarcodeFormat.EAN_13);
     PRODUCT_FORMATS.add(BarcodeFormat.EAN_8);
-    //PRODUCT_FORMATS.add(BarcodeFormat.RSS14);
+    PRODUCT_FORMATS.add(BarcodeFormat.RSS14);
     ONE_D_FORMATS = new Vector<BarcodeFormat>(PRODUCT_FORMATS.size() + 3);
     ONE_D_FORMATS.addAll(PRODUCT_FORMATS);
     ONE_D_FORMATS.add(BarcodeFormat.CODE_39);
@@ -250,25 +251,35 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
 
     SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
     playBeep = prefs.getBoolean(PreferencesActivity.KEY_PLAY_BEEP, true);
+    if (playBeep) {
+      // See if sound settings overrides this
+      AudioManager audioService = (AudioManager) getSystemService(AUDIO_SERVICE);
+      if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
+        playBeep = false;
+      }
+    }
     vibrate = prefs.getBoolean(PreferencesActivity.KEY_VIBRATE, false);
     copyToClipboard = prefs.getBoolean(PreferencesActivity.KEY_COPY_TO_CLIPBOARD, true);
     initBeepSound();
   }
 
   private static Vector<BarcodeFormat> parseDecodeFormats(Intent intent) {
-    return parseDecodeFormats(
-        Arrays.asList(COMMA_PATTERN.split(intent.getStringExtra(Intents.Scan.SCAN_FORMATS))),
-        intent.getStringExtra(Intents.Scan.MODE));
+    List<String> scanFormats = null;
+    String scanFormatsString = intent.getStringExtra(Intents.Scan.SCAN_FORMATS);
+    if (scanFormatsString != null) {
+      scanFormats = Arrays.asList(COMMA_PATTERN.split(scanFormatsString));
+    }
+    return parseDecodeFormats(scanFormats, intent.getStringExtra(Intents.Scan.MODE));
   }
-  
+
   private static Vector<BarcodeFormat> parseDecodeFormats(Uri inputUri) {
     List<String> formats = inputUri.getQueryParameters(Intents.Scan.SCAN_FORMATS);
-    if (formats.size() == 1){
+    if (formats != null && formats.size() == 1 && formats.get(0) != null){
       formats = Arrays.asList(COMMA_PATTERN.split(formats.get(0)));
     }
     return parseDecodeFormats(formats, inputUri.getQueryParameter(Intents.Scan.MODE));
   }
-  
+
   private static Vector<BarcodeFormat> parseDecodeFormats(List<String> scanFormats,
                                                           String decodeMode) {
     if (scanFormats != null) {
@@ -577,8 +588,8 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
           resultHandler.getDisplayContents().toString() + "&source=zxing";
       handler.sendMessageDelayed(message, INTENT_RESULT_DURATION);
     } else if (source == Source.ZXING_LINK) {
-       // Replace each occurrence of RETURN_CODE_PLACEHOLDER in the returnUrlTemplate
-       // with the scanned code. This allows both queries and REST-style URLs to work.
+      // Replace each occurrence of RETURN_CODE_PLACEHOLDER in the returnUrlTemplate
+      // with the scanned code. This allows both queries and REST-style URLs to work.
       Message message = Message.obtain(handler, R.id.launch_product_query);
       message.obj = returnUrlTemplate.replace(RETURN_CODE_PLACEHOLDER, resultHandler.getDisplayContents().toString());
       handler.sendMessageDelayed(message, INTENT_RESULT_DURATION);
@@ -661,7 +672,7 @@ public final class CaptureActivity extends Activity implements SurfaceHolder.Cal
     } catch (RuntimeException e) {
       // Barcode Scanner has seen crashes in the wild of this variety:
       // java.?lang.?RuntimeException: Fail to connect to camera service
-      Log.e(TAG, e.toString());
+      Log.w(TAG, "Unexpected error initializating camera", e);
       displayFrameworkBugMessageAndExit();
       return;
     }