Merge pull request #16 from nickgerman/master

Added continuous autofocus on Android if the API Level supports it + added explicit enabling of all ZBar barcode formats
This commit is contained in:
TJ Woon 2015-04-19 23:51:24 +08:00
commit d4d062cccc
4 changed files with 174 additions and 2 deletions

View File

@ -0,0 +1,72 @@
package org.cloudsky.cordovaPlugins;
import net.sourceforge.zbar.Symbol;
import java.util.List;
import java.util.ArrayList;
public class BarcodeFormat {
private int mId;
private String mName;
public static final BarcodeFormat NONE = new BarcodeFormat(Symbol.NONE, "NONE");
public static final BarcodeFormat PARTIAL = new BarcodeFormat(Symbol.PARTIAL, "PARTIAL");
public static final BarcodeFormat EAN8 = new BarcodeFormat(Symbol.EAN8, "EAN8");
public static final BarcodeFormat UPCE = new BarcodeFormat(Symbol.UPCE, "UPCE");
public static final BarcodeFormat ISBN10 = new BarcodeFormat(Symbol.ISBN10, "ISBN10");
public static final BarcodeFormat UPCA = new BarcodeFormat(Symbol.UPCA, "UPCA");
public static final BarcodeFormat EAN13 = new BarcodeFormat(Symbol.EAN13, "EAN13");
public static final BarcodeFormat ISBN13 = new BarcodeFormat(Symbol.ISBN13, "ISBN13");
public static final BarcodeFormat I25 = new BarcodeFormat(Symbol.I25, "I25");
public static final BarcodeFormat DATABAR = new BarcodeFormat(Symbol.DATABAR, "DATABAR");
public static final BarcodeFormat DATABAR_EXP = new BarcodeFormat(Symbol.DATABAR_EXP, "DATABAR_EXP");
public static final BarcodeFormat CODABAR = new BarcodeFormat(Symbol.CODABAR, "CODABAR");
public static final BarcodeFormat CODE39 = new BarcodeFormat(Symbol.CODE39, "CODE39");
public static final BarcodeFormat PDF417 = new BarcodeFormat(Symbol.PDF417, "PDF417");
public static final BarcodeFormat QRCODE = new BarcodeFormat(Symbol.QRCODE, "QRCODE");
public static final BarcodeFormat CODE93 = new BarcodeFormat(Symbol.CODE93, "CODE93");
public static final BarcodeFormat CODE128 = new BarcodeFormat(Symbol.CODE128, "CODE128");
public static final List<BarcodeFormat> ALL_FORMATS = new ArrayList<BarcodeFormat>();
static {
ALL_FORMATS.add(BarcodeFormat.PARTIAL);
ALL_FORMATS.add(BarcodeFormat.EAN8);
ALL_FORMATS.add(BarcodeFormat.UPCE);
ALL_FORMATS.add(BarcodeFormat.ISBN10);
ALL_FORMATS.add(BarcodeFormat.UPCA);
ALL_FORMATS.add(BarcodeFormat.EAN13);
ALL_FORMATS.add(BarcodeFormat.ISBN13);
ALL_FORMATS.add(BarcodeFormat.I25);
ALL_FORMATS.add(BarcodeFormat.DATABAR);
ALL_FORMATS.add(BarcodeFormat.DATABAR_EXP);
ALL_FORMATS.add(BarcodeFormat.CODABAR);
ALL_FORMATS.add(BarcodeFormat.CODE39);
ALL_FORMATS.add(BarcodeFormat.PDF417);
ALL_FORMATS.add(BarcodeFormat.QRCODE);
ALL_FORMATS.add(BarcodeFormat.CODE93);
ALL_FORMATS.add(BarcodeFormat.CODE128);
}
public BarcodeFormat(int id, String name) {
mId = id;
mName = name;
}
public int getId() {
return mId;
}
public String getName() {
return mName;
}
public static BarcodeFormat getFormatById(int id) {
for(BarcodeFormat format : ALL_FORMATS) {
if(format.getId() == id) {
return format;
}
}
return BarcodeFormat.NONE;
}
}

View File

@ -23,6 +23,12 @@ import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import net.sourceforge.zbar.ImageScanner;
import net.sourceforge.zbar.Image;
import net.sourceforge.zbar.Symbol;
@ -32,6 +38,9 @@ import net.sourceforge.zbar.Config;
public class ZBarScannerActivity extends Activity
implements SurfaceHolder.Callback {
//for barcode types
private Collection<ZBarcodeFormat> mFormats = null;
// Config ----------------------------------------------------------
private static int autoFocusInterval = 500; // Interval between AFcallback and next AF attempt.
@ -93,6 +102,11 @@ implements SurfaceHolder.Callback {
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);
}
// Set content view
setContentView(getResourceId("layout/cszbarscanner"));
@ -126,6 +140,7 @@ implements SurfaceHolder.Callback {
// Add preview SurfaceView to the screen
FrameLayout scannerView = (FrameLayout) findViewById(getResourceId("id/csZbarScannerView"));
scannerView.addView(scannerSurface);
findViewById(getResourceId("id/csZbarScannerTitle")).bringToFront();
findViewById(getResourceId("id/csZbarScannerInstructions")).bringToFront();
findViewById(getResourceId("id/csZbarScannerSightContainer")).bringToFront();
@ -170,6 +185,10 @@ implements SurfaceHolder.Callback {
} else {
camParams.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO);
}
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);
@ -347,6 +366,14 @@ implements SurfaceHolder.Callback {
}
}
public Collection<ZBarcodeFormat> getFormats() {
if(mFormats == null) {
return ZBarcodeFormat.ALL_FORMATS;
}
return mFormats;
}
// Start the camera preview if possible.
// If start is attempted but fails, exit with error message.
private void tryStartPreview () {
@ -358,7 +385,7 @@ implements SurfaceHolder.Callback {
camera.setPreviewDisplay(holder);
camera.setPreviewCallback(previewCb);
camera.startPreview();
camera.autoFocus(autoFocusCb); // We are not using any of the
//camera.autoFocus(autoFocusCb); // We are not using any of the
// continuous autofocus modes as that does not seem to work
// well with flash setting of "on"... At least with this
// simple and stupid focus method, we get to turn the flash

View File

@ -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<ZBarcodeFormat> ALL_FORMATS = new ArrayList<ZBarcodeFormat>();
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;
}
}

View File

@ -44,6 +44,7 @@
<color name="csZbarScannerBackground">#000000</color>
</config-file>
<resource-file src="android/res/layout/cszbarscanner.xml" target="res/layout/cszbarscanner.xml" />
<source-file src="android/ZBarcodeFormat.java" target-dir="src/org/cloudsky/cordovaPlugins" />
<source-file src="android/ZBar.java" target-dir="src/org/cloudsky/cordovaPlugins" />
<source-file src="android/ZBarScannerActivity.java" target-dir="src/org/cloudsky/cordovaPlugins" />
<source-file src="android/libs/zbar.jar" target-dir="libs" />