More reckless refactoring and code style tweaks -- mostly adding braces around condit...
[zxing.git] / android / src / com / google / zxing / client / android / DecodeThread.java
index 6146e9b..5835ecf 100755 (executable)
@@ -28,7 +28,6 @@ import com.google.zxing.MultiFormatReader;
 import com.google.zxing.ReaderException;
 import com.google.zxing.Result;
 
-import java.util.Date;
 import java.util.Hashtable;
 import java.util.Vector;
 
@@ -40,8 +39,8 @@ final class DecodeThread extends Thread {
   public static final String BARCODE_BITMAP = "barcode_bitmap";
 
   public Handler mHandler;
-  private CaptureActivity mActivity;
-  private MultiFormatReader mMultiFormatReader;
+  private final CaptureActivity mActivity;
+  private final MultiFormatReader mMultiFormatReader;
 
   DecodeThread(CaptureActivity activity, String mode) {
     mActivity = activity;
@@ -76,6 +75,7 @@ final class DecodeThread extends Thread {
   public void run() {
     Looper.prepare();
     mHandler = new Handler() {
+      @Override
       public void handleMessage(Message message) {
         switch (message.what) {
           case R.id.decode:
@@ -124,8 +124,22 @@ final class DecodeThread extends Thread {
     mMultiFormatReader.setHints(hints);
   }
 
+  /**
+   * Instead of calling setHints(null), which would allow new formats like ITF to sneak in, we
+   * explicitly set which formats are available.
+   */
   private void setDecodeAllMode() {
-    mMultiFormatReader.setHints(null);
+    Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>(3);
+    Vector<BarcodeFormat> vector = new Vector<BarcodeFormat>();
+    vector.addElement(BarcodeFormat.UPC_A);
+    vector.addElement(BarcodeFormat.UPC_E);
+    vector.addElement(BarcodeFormat.EAN_13);
+    vector.addElement(BarcodeFormat.EAN_8);
+    vector.addElement(BarcodeFormat.CODE_39);
+    vector.addElement(BarcodeFormat.CODE_128);
+    vector.addElement(BarcodeFormat.QR_CODE);
+    hints.put(DecodeHintType.POSSIBLE_FORMATS, vector);
+    mMultiFormatReader.setHints(hints);
   }
 
   /**
@@ -137,7 +151,7 @@ final class DecodeThread extends Thread {
    * @param height The height of the preview frame.
    */
   private void decode(byte[] data, int width, int height) {
-    Date startDate = new Date();
+    long start = System.currentTimeMillis();
     boolean success;
     Result rawResult = null;
     YUVMonochromeBitmapSource source = new YUVMonochromeBitmapSource(data, width, height,
@@ -148,18 +162,18 @@ final class DecodeThread extends Thread {
     } catch (ReaderException e) {
       success = false;
     }
-    Date endDate = new Date();
+    long end = System.currentTimeMillis();
 
     if (success) {
       Message message = Message.obtain(mActivity.mHandler, R.id.decode_succeeded, rawResult);
-      message.arg1 = (int) (endDate.getTime() - startDate.getTime());
+      message.arg1 = (int) (end - start);
       Bundle bundle = new Bundle();
       bundle.putParcelable(BARCODE_BITMAP, source.renderToBitmap());
       message.setData(bundle);
       message.sendToTarget();
     } else {
       Message message = Message.obtain(mActivity.mHandler, R.id.decode_failed);
-      message.arg1 = (int) (endDate.getTime() - startDate.getTime());
+      message.arg1 = (int) (end - start);
       message.sendToTarget();
     }
   }