Commit b5c02b12 by Oscar Fuentes

Merge branch 'development'

parents 60e57475 26ef8e36
......@@ -12,6 +12,10 @@ import org.apache.cordova.CallbackContext;
import org.apache.cordova.PluginResult;
import org.apache.cordova.PluginResult.Status;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.phonegap.plugins.barcodescanner.BarcodeScanner;
import android.content.Context;
import android.os.Message;
......@@ -38,93 +42,43 @@ public class PluginHelper {
public static void scan(CordovaInterface cordova, CordovaWebView webView, JSONArray args,
final CallbackContext callbackContext) {
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;
}
String barCode = new String(data);
barCode = barCode.replaceAll("\u0000", "");
Log.i(TAG, barCode);
callbackContext.sendPluginResult(new PluginResult(Status.OK, barCode));
}
});
mInstance.scan();
//
// boolean bContinuous = false;
// Log.i("ErDActivity", "scan() ");
//
// executor = cordova.getThreadPool();
//
// if (threadStop) {
//
// int iBetween = 0;
//
// // thread = new Thread(new GetBarcode(bContinuous, iBetween));
// // thread.start();
//
// executor.execute(new GetBarcode(bContinuous, iBetween));
//
// } else {
// threadStop = true;
// }
}
private static class GetBarcode implements Runnable {
private boolean isContinuous = false;
String barCode = "";
private long sleepTime = 1000;
Message msg = null;
public GetBarcode(boolean isContinuous) {
this.isContinuous = isContinuous;
}
public GetBarcode(boolean isContinuous, int sleep) {
this.isContinuous = isContinuous;
this.sleepTime = sleep;
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 (length < 1) {
return;
}
@Override
public void run() {
do {
mInstance.scan();
Log.i("MY", "barCode " + barCode.trim());
msg = new Message();
if (StringUtility.isEmpty(barCode)) {
msg.arg1 = 0;
msg.obj = "";
} else {
msg.arg1 = 1;
msg.obj = barCode;
}
String barCode = new String(data);
barCode = barCode.replaceAll("\u0000", "");
Log.i(TAG, barCode);
if (isContinuous) {
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
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, ""));
}
}
} while (isContinuous && !threadStop);
});
mInstance.scan();
} else if (device.equalsIgnoreCase("camera")) {
BarcodeScanner barcodeScanner = new BarcodeScanner();
barcodeScanner.cordova = cordova;
barcodeScanner.webView = webView;
barcodeScanner.execute("scan", new JSONArray(), callbackContext);
}
}
}
......@@ -3,8 +3,8 @@ var exec = require('cordova/exec');
var PLUGIN_NAME = 'BarcodeScanChainway';
var BarcodeScanChainway = {
scan: function (cb, error) {
exec(cb, error, PLUGIN_NAME, 'scan', []);
scan: function (device, cb, error) {
exec(cb, error, PLUGIN_NAME, 'scan', [device]);
}
};
module.exports = BarcodeScanChainway;
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