Commit 9849a1c2 by Oscar Fuentes

Test camera scan

parent a278f8bf
......@@ -9,8 +9,6 @@ import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import org.json.JSONArray;
import org.json.JSONException;
import com.phonegap.plugins.barcodescanner.BarcodeScanner;
public class BarcodeScanChainway extends CordovaPlugin {
......@@ -24,16 +22,8 @@ public class BarcodeScanChainway extends CordovaPlugin {
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) {
PluginHelper.init(cordova);
Log.d(TAG, "execute: " + action);
try {
String device = args.get(0).toString();
if (action.equalsIgnoreCase("scan") && device.equalsIgnoreCase("scanner")) {
PluginHelper.scan(cordova, webView, args, callbackContext);
} else if (action.equalsIgnoreCase("scan") && device.equalsIgnoreCase("mobile")) {
BarcodeScanner barcodeScanner = new BarcodeScanner();
barcodeScanner.scan(args);
}
} catch (JSONException e) {
e.printStackTrace();
if (action.equalsIgnoreCase("scan")) {
PluginHelper.scan(cordova, webView, args, callbackContext);
}
return true;
}
......
......@@ -12,6 +12,8 @@ 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 com.phonegap.plugins.barcodescanner.BarcodeScanner;
import android.content.Context;
import android.os.Message;
......@@ -38,43 +40,38 @@ public class PluginHelper {
public static void scan(CordovaInterface cordova, CordovaWebView webView, JSONArray args,
final CallbackContext callbackContext) {
String device = "";
try {
device = args.get(0).toString();
} catch (JSONException e) {
e.printStackTrace();
callbackContext.sendPluginResult(new PluginResult(Status.ERROR, ""));
}
if (device == "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;
}
mInstance.setScanCallback(new Barcode2DWithSoft.ScanCallback() {
@Override
public void onScanComplete(int i, int length, byte[] data) {
Log.i(TAG, "onScanComplete() i=" + i);
String barCode = new String(data);
barCode = barCode.replaceAll("\u0000", "");
Log.i(TAG, barCode);
if (length < 1) {
return;
callbackContext.sendPluginResult(new PluginResult(Status.OK, barCode));
}
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;
// }
});
mInstance.scan();
} else if (device == "camera") {
BarcodeScanner barcodeScanner = new BarcodeScanner();
barcodeScanner.cordova = cordova;
barcodeScanner.webView = webView;
barcodeScanner.execute("scan", new JSONArray(), callbackContext);
}
}
private static class GetBarcode implements Runnable {
......
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