Commit e2e97195 by Oscar Fuentes

Change plugin initialize

parent 8ca4fb80
......@@ -20,11 +20,10 @@ public class BarcodeScanChainway extends CordovaPlugin {
}
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) {
PluginHelper.init(cordova);
Log.d(TAG, "execute: " + action);
if (action.equalsIgnoreCase("scan")) {
PluginHelper.scan(cordova, webView, args, callbackContext);
}else if(action.equalsIgnoreCase("getDevices")){
} else if (action.equalsIgnoreCase("getDevices")) {
PluginHelper.getDevices(cordova, webView, args, callbackContext);
}
return true;
......
......@@ -27,24 +27,22 @@ public class PluginHelper {
private static Barcode2DWithSoft mInstance;
private static JSONArray Devices = new JSONArray().put("camera").put("c4050");
public static void init(CordovaInterface cordova) {
Context context = cordova.getActivity();
try {
mInstance = Barcode2DWithSoft.getInstance();
if (mInstance != null) {
mInstance.open(context);
}
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
}
public static void scan(CordovaInterface cordova, CordovaWebView webView, JSONArray args,
final CallbackContext callbackContext) {
String device = "";
try {
device = args.get(0).toString();
if (device.equalsIgnoreCase(Devices.getString(1))) {
Context context = cordova.getActivity();
try {
mInstance = Barcode2DWithSoft.getInstance();
if (mInstance != null) {
mInstance.open(context);
}
} catch (Exception e) {
Log.e(TAG, e.getMessage());
callbackContext.sendPluginResult(new PluginResult(Status.ERROR, e.getMessage()));
}
mInstance.setScanCallback(new Barcode2DWithSoft.ScanCallback() {
@Override
public void onScanComplete(int i, int length, byte[] data) {
......@@ -62,8 +60,7 @@ public class PluginHelper {
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, ""));
callbackContext.sendPluginResult(new PluginResult(Status.ERROR, e.getMessage()));
}
}
});
......@@ -81,7 +78,8 @@ public class PluginHelper {
}
}
public static void getDevices(CordovaInterface cordova, CordovaWebView webView, JSONArray args, final CallbackContext callbackContext){
public static void getDevices(CordovaInterface cordova, CordovaWebView webView, JSONArray args,
final CallbackContext callbackContext) {
callbackContext.sendPluginResult(new PluginResult(Status.OK, Devices));
}
}
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