Skip to content

Commit

Permalink
Added a mixed scan mode to enable scanning inverted and normal barcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
alpbak committed Sep 14, 2017
1 parent eaeddd2 commit cf4c0dc
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
6 changes: 6 additions & 0 deletions sample/src/main/java/example/zxing/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ public void scanBarcodeInverted(View view){
integrator.initiateScan();
}

public void scanMixedBarcodes(View view){
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.addExtra(Intents.Scan.MIXED_SCAN, true);
integrator.initiateScan();
}

public void scanBarcodeCustomLayout(View view) {
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.setCaptureActivity(AnyOrientationCaptureActivity.class);
Expand Down
7 changes: 7 additions & 0 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
android:text="Scan Inverted"
android:onClick="scanBarcodeInverted"/>

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="scanMixedBarcodes"
android:text="Scan Mixed Barcodes" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ public static final class Scan {
*/
public static final String INVERTED_SCAN = "INVERTED_SCAN";

/***
* Scan for inverted and normal badcodes at the same time.
*/
public static final String MIXED_SCAN = "MIXED_SCAN";

private Scan() {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,16 @@ public void initializeFromIntent(Intent intent) {
// Check to see if the scan should be inverted.
boolean inverted = intent.getBooleanExtra(Intents.Scan.INVERTED_SCAN, false);

//Check if the scan should include inverted and normal barcodes
boolean mixedScan = intent.getBooleanExtra(Intents.Scan.MIXED_SCAN, false);

String characterSet = intent.getStringExtra(Intents.Scan.CHARACTER_SET);

MultiFormatReader reader = new MultiFormatReader();
reader.setHints(decodeHints);

barcodeView.setCameraSettings(settings);
barcodeView.setDecoderFactory(new DefaultDecoderFactory(decodeFormats, decodeHints, characterSet, inverted));
barcodeView.setDecoderFactory(new DefaultDecoderFactory(decodeFormats, decodeHints, characterSet, inverted, mixedScan));
}

public void setStatusText(String text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ public class DefaultDecoderFactory implements DecoderFactory {
private Map<DecodeHintType, ?> hints;
private String characterSet;
private boolean inverted;
private boolean mixedScan;

public DefaultDecoderFactory() {
}

public DefaultDecoderFactory(Collection<BarcodeFormat> decodeFormats, Map<DecodeHintType, ?> hints, String characterSet, boolean inverted) {
public DefaultDecoderFactory(Collection<BarcodeFormat> decodeFormats, Map<DecodeHintType, ?> hints, String characterSet, boolean inverted, boolean mixedScan) {
this.decodeFormats = decodeFormats;
this.hints = hints;
this.characterSet = characterSet;
this.inverted = inverted;
this.mixedScan = mixedScan;
}

@Override
Expand All @@ -48,7 +50,10 @@ public Decoder createDecoder(Map<DecodeHintType, ?> baseHints) {
MultiFormatReader reader = new MultiFormatReader();
reader.setHints(hints);

return inverted ? new InvertedDecoder(reader) : new Decoder(reader);
if (mixedScan)
return new MixedDecoder(reader);
else
return inverted ? new InvertedDecoder(reader) : new Decoder(reader);

}
}

0 comments on commit cf4c0dc

Please sign in to comment.