import com.google.zxing.ReaderException;
import com.google.zxing.Result;
-import java.util.Date;
import java.util.Hashtable;
import java.util.Vector;
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;
public void run() {
Looper.prepare();
mHandler = new Handler() {
+ @Override
public void handleMessage(Message message) {
switch (message.what) {
case R.id.decode:
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);
}
/**
* @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,
} 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();
}
}