Commit 792469d2 by Oscar Fuentes

Merge branch 'development'

parents b5c02b12 63e806e9
......@@ -24,6 +24,8 @@ public class BarcodeScanChainway extends CordovaPlugin {
Log.d(TAG, "execute: " + action);
if (action.equalsIgnoreCase("scan")) {
PluginHelper.scan(cordova, webView, args, callbackContext);
}else if(action.equalsIgnoreCase("getDevices")){
PluginHelper.getDevices(cordova, webView, args, callbackContext);
}
return true;
}
......
package com.cocodin.barcodescan.plugin;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.rscja.utility.StringUtility;
import com.zebra.adc.decoder.Barcode2DWithSoft;
import org.apache.cordova.CordovaInterface;
......@@ -18,7 +17,6 @@ import org.json.JSONObject;
import com.phonegap.plugins.barcodescanner.BarcodeScanner;
import android.content.Context;
import android.os.Message;
import android.util.Log;
public class PluginHelper {
......@@ -27,9 +25,12 @@ public class PluginHelper {
private static boolean threadStop = true;
private static ExecutorService executor;
private static Barcode2DWithSoft mInstance;
private static JSONArray Devices = new JSONArray();
public static void init(CordovaInterface cordova) {
Context context = cordova.getActivity();
Devices.put("camera");
Devices.put("c4050");
try {
mInstance = Barcode2DWithSoft.getInstance();
if (mInstance != null) {
......@@ -45,40 +46,44 @@ public class PluginHelper {
String device = "";
try {
device = args.get(0).toString();
} catch (JSONException e) {
e.printStackTrace();
callbackContext.sendPluginResult(new PluginResult(Status.ERROR, ""));
}
if (device.equalsIgnoreCase("scanner")) {
mInstance.setScanCallback(new Barcode2DWithSoft.ScanCallback() {
@Override
public void onScanComplete(int i, int length, byte[] data) {
Log.i(TAG, "onScanComplete() i=" + i);
if (device.equalsIgnoreCase(Devices.getString(1))) {
mInstance.setScanCallback(new Barcode2DWithSoft.ScanCallback() {
@Override
public void onScanComplete(int i, int length, byte[] data) {
Log.i(TAG, "onScanComplete() i=" + i);
if (length < 1) {
return;
}
if (length < 1) {
return;
}
String barCode = new String(data);
barCode = barCode.replaceAll("\u0000", "");
Log.i(TAG, barCode);
String barCode = new String(data);
barCode = barCode.replaceAll("\u0000", "");
Log.i(TAG, barCode);
try {
JSONObject result = new JSONObject().put("text", barCode);
callbackContext.sendPluginResult(new PluginResult(Status.OK, result));
} catch (JSONException e) {
e.printStackTrace();
callbackContext.sendPluginResult(new PluginResult(Status.ERROR, ""));
try {
JSONObject result = new JSONObject().put("text", barCode);
callbackContext.sendPluginResult(new PluginResult(Status.OK, result));
} catch (JSONException e) {
e.printStackTrace();
callbackContext.sendPluginResult(new PluginResult(Status.ERROR, ""));
}
}
}
});
});
mInstance.scan();
} else if (device.equalsIgnoreCase("camera")) {
BarcodeScanner barcodeScanner = new BarcodeScanner();
barcodeScanner.cordova = cordova;
barcodeScanner.webView = webView;
barcodeScanner.execute("scan", new JSONArray(), callbackContext);
mInstance.scan();
} else if (device.equalsIgnoreCase(Devices.getString(0))) {
BarcodeScanner barcodeScanner = new BarcodeScanner();
barcodeScanner.cordova = cordova;
barcodeScanner.webView = webView;
barcodeScanner.execute("scan", new JSONArray(), callbackContext);
}
} catch (JSONException e) {
e.printStackTrace();
callbackContext.sendPluginResult(new PluginResult(Status.ERROR, ""));
}
}
public static void getDevices(CordovaInterface cordova, CordovaWebView webView, JSONArray args, final CallbackContext callbackContext){
callbackContext.sendPluginResult(new PluginResult(Status.OK, Devices));
}
}
var exec = require('cordova/exec');
var exec = require('cordova/exec');
var PLUGIN_NAME = 'BarcodeScanChainway';
var PLUGIN_NAME = 'BarcodeScanChainway';
var BarcodeScanChainway = {
scan: function (device, cb, error) {
exec(cb, error, PLUGIN_NAME, 'scan', [device]);
}
};
module.exports = BarcodeScanChainway;
var BarcodeScanChainway = {
scan: function (device, cb, error) {
exec(cb, error, PLUGIN_NAME, 'scan', [device]);
},
getDevices: function (cb, error) {
exec(cb, error, PLUGIN_NAME, 'getDevices', []);
}
};
module.exports = BarcodeScanChainway;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment