1515public class EnterpriseBarcode extends CordovaPlugin {
1616 public static final String LOG_TAG = "EnterpriseBarcode" ;
1717 private ZebraAndroidExtensions zebraExtensions = null ;
18- private int userEnabledScanner = 0 ;
18+ private JSONObject argumentsToEnable = null ;
1919
2020 public static void FailureCallback (CallbackContext callbackContext , String message )
2121 {
22- JSONObject failureMessage = new JSONObject ();
23- try {
24- failureMessage .put ("message" , message );
25- } catch (JSONException e ) {
26- Log .d (LOG_TAG , "JSON Error" );
22+ if (callbackContext != null ) {
23+ JSONObject failureMessage = new JSONObject ();
24+ try {
25+ failureMessage .put ("message" , message );
26+ } catch (JSONException e ) {
27+ Log .e (LOG_TAG , "JSON Error" );
28+ }
29+ callbackContext .error (failureMessage );
30+ }
31+ }
32+
33+ public static void SuccessCallback (CallbackContext callbackContext , String message )
34+ {
35+ if (callbackContext != null ) {
36+ JSONObject successMessage = new JSONObject ();
37+ try {
38+ successMessage .put ("message" , message );
39+ } catch (JSONException e ) {
40+ Log .e (LOG_TAG , "JSON Error" );
41+ }
42+ callbackContext .success (successMessage );
2743 }
28- callbackContext .error (failureMessage );
2944 }
3045
3146 /**
@@ -49,26 +64,24 @@ public void initialize(CordovaInterface cordova, CordovaWebView webView) {
4964 public void onResume (boolean multitasking )
5065 {
5166 Log .d (LOG_TAG , "On Resume" );
52- // todo - start EMDK
53- // todo - need static log string
54- InitializeZebraExtensions (null , userEnabledScanner );
55- zebraExtensions .onResume ();
67+ // EMDK seems reliable without having to re-enable it on resume
68+ // InitializeZebraExtensions(null);
5669 }
5770
5871 public void onPause (boolean multitasking )
5972 {
6073 Log .d (LOG_TAG , "On Pause" );
61- // todo - stop EMDK
62- zebraExtensions .destroy ();
74+ // EMDK Seems reliable without having to disable it on pause
75+ // zebraExtensions.destroy();
6376 }
6477
65- public void InitializeZebraExtensions (CallbackContext callbackContext , int userEnabledScanner )
78+ public void InitializeZebraExtensions (CallbackContext callbackContext )
6679 {
6780 Context c = this .cordova .getActivity ().getApplicationContext ();
6881 if (ZebraAndroidExtensions .isEMDKAvailable (c ))
6982 {
7083 // Create the EMDK object
71- zebraExtensions = new ZebraAndroidExtensions (c , callbackContext , userEnabledScanner );
84+ zebraExtensions = new ZebraAndroidExtensions (c , callbackContext );
7285 }
7386 else
7487 {
@@ -88,11 +101,8 @@ public boolean execute(String action, JSONArray args, final CallbackContext call
88101 Log .d (LOG_TAG , "Args: " + args .length ());
89102 if (action .equals ("initializeBarcode" )) {
90103 JSONObject r = new JSONObject ();
91- // todo - Initialise EMDK
92104 // todo - get EMDK 3.0 jar
93- // todo - don't delete or overwrite my android platform code
94- InitializeZebraExtensions (callbackContext , userEnabledScanner );
95- //callbackContext.success(r);
105+ InitializeZebraExtensions (callbackContext );
96106 }
97107 else if (action .equals ("enable" ))
98108 {
@@ -102,6 +112,7 @@ else if (action.equals("enable"))
102112 try {
103113 JSONObject arguments = args .getJSONObject (0 );
104114 arguments = arguments .getJSONObject ("options" );
115+ argumentsToEnable = arguments ;
105116 Log .d (LOG_TAG , String .valueOf (arguments ));
106117 }
107118 catch (JSONException je )
@@ -110,16 +121,14 @@ else if (action.equals("enable"))
110121 }
111122 }
112123 Log .d (LOG_TAG , "Enable Scanner" );
113- userEnabledScanner = 1 ;
114124 cordova .getThreadPool ().execute (new Runnable () {
115125 public void run () {
116- ScannerEnable (callbackContext );
126+ ScannerEnable (callbackContext , argumentsToEnable );
117127 }
118128 });
119129 }
120130 else if (action .equalsIgnoreCase ("disable" )) {
121131 Log .d (LOG_TAG , "Disable Scanner" );
122- userEnabledScanner = 0 ;
123132 cordova .getThreadPool ().execute (new Runnable () {
124133 public void run () {
125134 ScannerDisable (callbackContext );
@@ -147,11 +156,13 @@ else if (action.equals("enumerate"))
147156 return true ;
148157 }
149158
159+
160+
150161 //--------------------------------------------------------------------------
151162 // LOCAL METHODS
152163 //--------------------------------------------------------------------------
153164
154- public JSONObject ScannerEnable (CallbackContext callbackContext )
165+ public JSONObject ScannerEnable (CallbackContext callbackContext , JSONObject userSpecifiedArgumentsToEnable )
155166 {
156167 if (zebraExtensions == null )
157168 {
@@ -166,7 +177,7 @@ else if (!zebraExtensions.isReady())
166177 else
167178 {
168179 // EMDK is ready, let's go
169- return zebraExtensions .enableScanner (callbackContext );
180+ return zebraExtensions .enableScanner (callbackContext , userSpecifiedArgumentsToEnable );
170181 }
171182 }
172183
0 commit comments