Commit e2e97195 by Oscar Fuentes

Change plugin initialize

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