From 5a5e54f124ba6dda1d2bfcbe3ae49c91c5e8a095 Mon Sep 17 00:00:00 2001 From: Joan Date: Tue, 18 Apr 2017 09:44:38 +0800 Subject: [PATCH 1/7] added formats parameter- a jsonarray wherein the user can list all the barcode formats he/she wants to limit the scan to --- csZBar | 1 + 1 file changed, 1 insertion(+) create mode 160000 csZBar diff --git a/csZBar b/csZBar new file mode 160000 index 0000000..fc5dcc3 --- /dev/null +++ b/csZBar @@ -0,0 +1 @@ +Subproject commit fc5dcc300b08d59aef51b15172720efefe873a96 From a3e5ebb9a54863dd13bbac704d0ac52b6c3b2b57 Mon Sep 17 00:00:00 2001 From: Joan Date: Tue, 18 Apr 2017 09:50:45 +0800 Subject: [PATCH 2/7] added public method on ZBarcodeFormat getFormatByName() --- android/ZBarcodeFormat.java | 11 +++++++++++ csZBar | 1 - 2 files changed, 11 insertions(+), 1 deletion(-) delete mode 160000 csZBar diff --git a/android/ZBarcodeFormat.java b/android/ZBarcodeFormat.java index 1871853..9cbe4ff 100644 --- a/android/ZBarcodeFormat.java +++ b/android/ZBarcodeFormat.java @@ -69,4 +69,15 @@ public static ZBarcodeFormat getFormatById(int id) { } return ZBarcodeFormat.NONE; } + + //new method to get the format by name + public static ZBarcodeFormat getFormatByName(String name){ + for (ZBarcodeFormat format : ALL_FORMATS){ + if(format.getName() == name) { + return format; + } + } + return ZBarcodeFormat.NONE; + } + } \ No newline at end of file diff --git a/csZBar b/csZBar deleted file mode 160000 index fc5dcc3..0000000 --- a/csZBar +++ /dev/null @@ -1 +0,0 @@ -Subproject commit fc5dcc300b08d59aef51b15172720efefe873a96 From e07826d251c1a8c10b23a784365c5e088fb842f3 Mon Sep 17 00:00:00 2001 From: Joan Date: Tue, 18 Apr 2017 09:52:54 +0800 Subject: [PATCH 3/7] added parameter - formats - array containing list of formats to limit the scan to --- android/ZBarScannerActivity.java | 36 +++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/android/ZBarScannerActivity.java b/android/ZBarScannerActivity.java index 9f23fa2..0ff6173 100644 --- a/android/ZBarScannerActivity.java +++ b/android/ZBarScannerActivity.java @@ -4,6 +4,7 @@ import java.lang.RuntimeException; import org.json.JSONException; import org.json.JSONObject; +import org.json.JSONArray; import android.Manifest; import android.app.Activity; @@ -141,15 +142,36 @@ private void setUpCamera() { whichCamera = params.optString("camera"); flashMode = params.optString("flash"); + //new parameter formats - list of formats to scan + JSONArray formats = params.optJSONArray("formats"); + + // Initiate instance variables autoFocusHandler = new Handler(); scanner = new ImageScanner(); scanner.setConfig(0, Config.X_DENSITY, 3); scanner.setConfig(0, Config.Y_DENSITY, 3); + // Set the config for barcode formats - for(ZBarcodeFormat format : getFormats()) { - scanner.setConfig(format.getId(), Config.ENABLE, 1); + if (formats.length){ + + //disable all + for(ZBarcodeFormat format : getFormats()) { + scanner.setConfig(format.getId(), Config.ENABLE, 0); + } + + //enable only those that are listed + for (String format_name : formats){ + ZBarcodeFormat format = ZBarcodeFormat.getFormatByName(format_name); + scanner.setConfig(format.getId(), Config.ENABLE, 1); + } + + } else { + // no format specified, read all + for(ZBarcodeFormat format : getFormats()) { + scanner.setConfig(format.getId(), Config.ENABLE, 1); + } } // Set content view @@ -334,7 +356,7 @@ public void onConfigurationChanged(Configuration newConfig) } public void toggleFlash(View view) { - camera.startPreview(); + camera.startPreview(); android.hardware.Camera.Parameters camParams = camera.getParameters(); //If the flash is set to off try { @@ -346,7 +368,7 @@ public void toggleFlash(View view) { } - try { + try { // camera.setParameters(camParams); camera.setPreviewDisplay(holder); camera.setPreviewCallback(previewCb); @@ -366,8 +388,8 @@ public void toggleFlash(View view) { } catch(RuntimeException e) { Log.d("csZBar", (new StringBuilder("Unsupported camera parameter reported for flash mode: ")).append(flashMode).toString()); } catch (IOException e) { - Log.d("csZBar", (new StringBuilder("Wrong holder data")).append(flashMode).toString()); - } + Log.d("csZBar", (new StringBuilder("Wrong holder data")).append(flashMode).toString()); + } } // Continuously auto-focus ----------------------------------------- // For API Level < 14 @@ -532,7 +554,7 @@ private void tryStartPreview () { camParams.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); camera.setParameters(camParams); } catch (Exception e) { - // TODO: don't swallow + // TODO: don't swallow } camera.setPreviewDisplay(holder); From f96be3955cdd25e0b4812524958ceb456cf38a33 Mon Sep 17 00:00:00 2001 From: Joan Date: Tue, 18 Apr 2017 14:17:51 +0800 Subject: [PATCH 4/7] added parameter is javascript example, fixed method getFormatByName and format enabling --- README.md | 1 + android/ZBarScannerActivity.java | 16 +++++++++++++--- android/ZBarcodeFormat.java | 3 ++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c219dab..9140a21 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Arguments: camera: "front" || "back" // defaults to "back" flash: "on" || "off" || "auto" // defaults to "auto". See Quirks drawSight: true || false //defaults to true, create a red sight/line in the center of the scanner view. + formats: ["QRCODE","CODE128"] //limit scan to formats listed, leave blank if no restriction is desired. } ``` diff --git a/android/ZBarScannerActivity.java b/android/ZBarScannerActivity.java index 0ff6173..6e8eacf 100644 --- a/android/ZBarScannerActivity.java +++ b/android/ZBarScannerActivity.java @@ -162,9 +162,19 @@ private void setUpCamera() { } //enable only those that are listed - for (String format_name : formats){ - ZBarcodeFormat format = ZBarcodeFormat.getFormatByName(format_name); - scanner.setConfig(format.getId(), Config.ENABLE, 1); + int len = formats.length(); + for (int i=0;i Date: Tue, 18 Apr 2017 14:32:45 +0800 Subject: [PATCH 5/7] bug fix --- android/ZBarScannerActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/ZBarScannerActivity.java b/android/ZBarScannerActivity.java index 6e8eacf..f5d5f36 100644 --- a/android/ZBarScannerActivity.java +++ b/android/ZBarScannerActivity.java @@ -154,7 +154,7 @@ private void setUpCamera() { // Set the config for barcode formats - if (formats.length){ + if (formats.length()){ //disable all for(ZBarcodeFormat format : getFormats()) { From 541001e7fb9fea4d7ac8af636115f465344d564d Mon Sep 17 00:00:00 2001 From: Joan Date: Tue, 18 Apr 2017 14:36:38 +0800 Subject: [PATCH 6/7] bug fix --- android/ZBarScannerActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/ZBarScannerActivity.java b/android/ZBarScannerActivity.java index f5d5f36..c1af75d 100644 --- a/android/ZBarScannerActivity.java +++ b/android/ZBarScannerActivity.java @@ -154,7 +154,7 @@ private void setUpCamera() { // Set the config for barcode formats - if (formats.length()){ + if (formats.length() > 0){ //disable all for(ZBarcodeFormat format : getFormats()) { From fdf6f1aa1ab507f415092ef31a8c1dc15aad73d4 Mon Sep 17 00:00:00 2001 From: Joan Date: Tue, 18 Apr 2017 14:44:29 +0800 Subject: [PATCH 7/7] set default value for formats to empty array --- www/zbar.js | 1 + 1 file changed, 1 insertion(+) diff --git a/www/zbar.js b/www/zbar.js index edadc91..9982fb9 100644 --- a/www/zbar.js +++ b/www/zbar.js @@ -14,6 +14,7 @@ ZBar.prototype = { if(params.text_instructions === undefined) params.text_instructions = "Please point your camera at the QR code."; if(params.camera != "front") params.camera = "back"; if(params.flash != "on" && params.flash != "off") params.flash = "auto"; + if(!params.formats) params.formats = []; exec(success, failure, 'CsZBar', 'scan', [params]); },