Skip to content

Commit

Permalink
Fix symbology selection for camera #158
Browse files Browse the repository at this point in the history
Version 2.1.0 reworked the way symbologies were selected, but that
change was poorly implemented for the camera which means only the
default CODE_128 symbology was recognized, everything else was ignored,
which means most barcodes could not be read by the camera scanner.
  • Loading branch information
DaSpood committed Apr 5, 2024
1 parent 922b66e commit 913d887
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.enioka.scanner.camera.CameraBarcodeScanView;
import com.enioka.scanner.camera.CameraReader;
import com.enioka.scanner.data.Barcode;
import com.enioka.scanner.data.BarcodeType;
import com.enioka.scanner.helpers.Common;
import com.enioka.scanner.sdk.camera.CameraBarcodeScanViewScanner;
import com.enioka.scanner.service.ScannerClient;
Expand All @@ -43,7 +44,10 @@
import com.enioka.scanner.service.ScannerServiceBinderHelper;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
* A helper activity which implements all scan functions: laser, camera, HID.<br><br>Basic usage is trivial : just inherit this class, and that's all.<br>
Expand Down Expand Up @@ -370,7 +374,16 @@ private void initCameraScanner() {
return;
}

cameraScanner = new CameraBarcodeScanViewScanner(cameraView, new ScannerDataCallbackProxy((s, data) -> ScannerCompatActivity.this.onData(data)), new ScannerStatusCallbackProxy(this));
final Set<BarcodeType> symbologies = new HashSet<>();
if (getIntent().getExtras() != null && getIntent().getExtras().getStringArray(ScannerServiceApi.EXTRA_SYMBOLOGY_SELECTION) != null) {
for (final String symbology : Objects.requireNonNull(getIntent().getExtras().getStringArray(ScannerServiceApi.EXTRA_SYMBOLOGY_SELECTION))) {
symbologies.add(BarcodeType.valueOf(symbology));
}
}
if (symbologies.isEmpty()) {
symbologies.add(BarcodeType.CODE128);
}
cameraScanner = new CameraBarcodeScanViewScanner(cameraView, new ScannerDataCallbackProxy((s, data) -> ScannerCompatActivity.this.onData(data)), new ScannerStatusCallbackProxy(this), symbologies);

if (findViewById(R.id.scanner_text_last_scan) != null) {
((TextView) findViewById(R.id.scanner_text_last_scan)).setText(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ public class CameraBarcodeScanViewScanner implements Scanner, Scanner.WithBeepSu
private ScannerDataCallbackProxy dataDb;
private final ScannerStatusCallback statusCallback;

public CameraBarcodeScanViewScanner(CameraBarcodeScanView cameraBarcodeScanView, ScannerDataCallbackProxy mHandler, final ScannerStatusCallbackProxy statusCallback) {
public CameraBarcodeScanViewScanner(CameraBarcodeScanView cameraBarcodeScanView, ScannerDataCallbackProxy mHandler, final ScannerStatusCallbackProxy statusCallback, final Set<BarcodeType> symbologySelection) {
this.dataDb = mHandler;

this.scanner = cameraBarcodeScanView;

scanner.setResultHandler(this);
scanner.setTorch(false);
for(BarcodeType symbology: symbologySelection) {
scanner.addSymbology(symbology);
}

this.statusCallback = statusCallback;
this.statusCallback.onStatusChanged(this, ScannerStatusCallback.Status.CONNECTED);
Expand All @@ -60,9 +62,6 @@ public void handleScanResult(String code, BarcodeType barcodeType) {
@Override
public void initialize(final Context applicationContext, final ScannerInitCallbackProxy initCallback, final ScannerDataCallbackProxy dataCallback, final ScannerStatusCallbackProxy statusCallback, final Mode mode, final Set<BarcodeType> symbologySelection) {
// Do nothing. The camera view implementation is special, as it is built directly and not through the LaserScanner.
for (BarcodeType symbology : symbologySelection) {
scanner.addSymbology(symbology);
}
initCallback.onConnectionSuccessful(this);
}

Expand Down

0 comments on commit 913d887

Please sign in to comment.