From 2b738063ef6180a97638e407c0b3ebc49388dc5b Mon Sep 17 00:00:00 2001 From: Nick German Date: Mon, 13 Apr 2015 10:27:24 +1000 Subject: [PATCH] renamed BarcodeFormat to ZBarcodeFormat, fixed indentation and added sdk check for continuous focus --- android/ZBarScannerActivity.java | 19 +++++---- android/ZBarcodeFormat.java | 72 ++++++++++++++++++++++++++++++++ package.json | 25 ----------- plugin.xml | 2 +- 4 files changed, 84 insertions(+), 34 deletions(-) create mode 100644 android/ZBarcodeFormat.java delete mode 100644 package.json diff --git a/android/ZBarScannerActivity.java b/android/ZBarScannerActivity.java index 2276525..37fc9a0 100644 --- a/android/ZBarScannerActivity.java +++ b/android/ZBarScannerActivity.java @@ -38,9 +38,9 @@ import net.sourceforge.zbar.Config; public class ZBarScannerActivity extends Activity implements SurfaceHolder.Callback { - //for barcode types - private Collection mFormats = null; - + //for barcode types + private Collection mFormats = null; + // Config ---------------------------------------------------------- private static int autoFocusInterval = 500; // Interval between AFcallback and next AF attempt. @@ -102,7 +102,8 @@ implements SurfaceHolder.Callback { scanner.setConfig(0, Config.X_DENSITY, 3); scanner.setConfig(0, Config.Y_DENSITY, 3); - for(BarcodeFormat format : getFormats()) { + // Set the config for barcode formats + for(ZBarcodeFormat format : getFormats()) { scanner.setConfig(format.getId(), Config.ENABLE, 1); } @@ -184,8 +185,10 @@ implements SurfaceHolder.Callback { } else { camParams.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO); } - camParams.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); - + if (android.os.Build.VERSION.SDK_INT >= 14) { + camParams.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); + } + try { camera.setParameters(camParams); } catch (RuntimeException e) { Log.d("csZBar", "Unsupported camera parameter reported for flash mode: "+flashMode); @@ -363,9 +366,9 @@ implements SurfaceHolder.Callback { } } - public Collection getFormats() { + public Collection getFormats() { if(mFormats == null) { - return BarcodeFormat.ALL_FORMATS; + return ZBarcodeFormat.ALL_FORMATS; } return mFormats; } diff --git a/android/ZBarcodeFormat.java b/android/ZBarcodeFormat.java new file mode 100644 index 0000000..1871853 --- /dev/null +++ b/android/ZBarcodeFormat.java @@ -0,0 +1,72 @@ +package org.cloudsky.cordovaPlugins; + +import net.sourceforge.zbar.Symbol; + +import java.util.List; +import java.util.ArrayList; + +public class ZBarcodeFormat { + private int mId; + private String mName; + + public static final ZBarcodeFormat NONE = new ZBarcodeFormat(Symbol.NONE, "NONE"); + public static final ZBarcodeFormat PARTIAL = new ZBarcodeFormat(Symbol.PARTIAL, "PARTIAL"); + public static final ZBarcodeFormat EAN8 = new ZBarcodeFormat(Symbol.EAN8, "EAN8"); + public static final ZBarcodeFormat UPCE = new ZBarcodeFormat(Symbol.UPCE, "UPCE"); + public static final ZBarcodeFormat ISBN10 = new ZBarcodeFormat(Symbol.ISBN10, "ISBN10"); + public static final ZBarcodeFormat UPCA = new ZBarcodeFormat(Symbol.UPCA, "UPCA"); + public static final ZBarcodeFormat EAN13 = new ZBarcodeFormat(Symbol.EAN13, "EAN13"); + public static final ZBarcodeFormat ISBN13 = new ZBarcodeFormat(Symbol.ISBN13, "ISBN13"); + public static final ZBarcodeFormat I25 = new ZBarcodeFormat(Symbol.I25, "I25"); + public static final ZBarcodeFormat DATABAR = new ZBarcodeFormat(Symbol.DATABAR, "DATABAR"); + public static final ZBarcodeFormat DATABAR_EXP = new ZBarcodeFormat(Symbol.DATABAR_EXP, "DATABAR_EXP"); + public static final ZBarcodeFormat CODABAR = new ZBarcodeFormat(Symbol.CODABAR, "CODABAR"); + public static final ZBarcodeFormat CODE39 = new ZBarcodeFormat(Symbol.CODE39, "CODE39"); + public static final ZBarcodeFormat PDF417 = new ZBarcodeFormat(Symbol.PDF417, "PDF417"); + public static final ZBarcodeFormat QRCODE = new ZBarcodeFormat(Symbol.QRCODE, "QRCODE"); + public static final ZBarcodeFormat CODE93 = new ZBarcodeFormat(Symbol.CODE93, "CODE93"); + public static final ZBarcodeFormat CODE128 = new ZBarcodeFormat(Symbol.CODE128, "CODE128"); + + public static final List ALL_FORMATS = new ArrayList(); + + static { + ALL_FORMATS.add(ZBarcodeFormat.PARTIAL); + ALL_FORMATS.add(ZBarcodeFormat.EAN8); + ALL_FORMATS.add(ZBarcodeFormat.UPCE); + ALL_FORMATS.add(ZBarcodeFormat.ISBN10); + ALL_FORMATS.add(ZBarcodeFormat.UPCA); + ALL_FORMATS.add(ZBarcodeFormat.EAN13); + ALL_FORMATS.add(ZBarcodeFormat.ISBN13); + ALL_FORMATS.add(ZBarcodeFormat.I25); + ALL_FORMATS.add(ZBarcodeFormat.DATABAR); + ALL_FORMATS.add(ZBarcodeFormat.DATABAR_EXP); + ALL_FORMATS.add(ZBarcodeFormat.CODABAR); + ALL_FORMATS.add(ZBarcodeFormat.CODE39); + ALL_FORMATS.add(ZBarcodeFormat.PDF417); + ALL_FORMATS.add(ZBarcodeFormat.QRCODE); + ALL_FORMATS.add(ZBarcodeFormat.CODE93); + ALL_FORMATS.add(ZBarcodeFormat.CODE128); + } + + public ZBarcodeFormat(int id, String name) { + mId = id; + mName = name; + } + + public int getId() { + return mId; + } + + public String getName() { + return mName; + } + + public static ZBarcodeFormat getFormatById(int id) { + for(ZBarcodeFormat format : ALL_FORMATS) { + if(format.getId() == id) { + return format; + } + } + return ZBarcodeFormat.NONE; + } +} \ No newline at end of file diff --git a/package.json b/package.json deleted file mode 100644 index 6135bc7..0000000 --- a/package.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "version": "1.3.0", - "name": "org.cloudsky.cordovaplugins.zbar", - "cordova_name": "ZBar barcode scanner", - "description": "Plugin to integrate with the ZBar barcode scanning library.", - "license": "Apache 2.0", - "keywords": [ - "cszbar", - "zbar", - "barcode", - "qr", - "qr code", - "scanner" - ], - "platforms": [ - "android", - "ios" - ], - "engines": [ - { - "name": "cordova", - "version": ">=3.0.0" - } - ] -} \ No newline at end of file diff --git a/plugin.xml b/plugin.xml index e9f8433..b7cfa06 100644 --- a/plugin.xml +++ b/plugin.xml @@ -44,7 +44,7 @@ #000000 - +