Commit 3b624527 by Sebastián Katzer

Add method implementation for `deviceready` for Android

parent 7e47b387
...@@ -54,9 +54,10 @@ public class LocalNotification extends CordovaPlugin { ...@@ -54,9 +54,10 @@ public class LocalNotification extends CordovaPlugin {
protected final static String PLUGIN_NAME = "LocalNotification"; protected final static String PLUGIN_NAME = "LocalNotification";
private static CordovaWebView webView = null; private static CordovaWebView webView = null;
private static Boolean deviceready = false;
protected static Context context = null; protected static Context context = null;
private static ArrayList<String> callbackQueue = new ArrayList<String>(); private static ArrayList<String> eventQueue = new ArrayList<String>();
@Override @Override
public void initialize (CordovaInterface cordova, CordovaWebView webView) { public void initialize (CordovaInterface cordova, CordovaWebView webView) {
...@@ -64,8 +65,6 @@ public class LocalNotification extends CordovaPlugin { ...@@ -64,8 +65,6 @@ public class LocalNotification extends CordovaPlugin {
LocalNotification.webView = super.webView; LocalNotification.webView = super.webView;
LocalNotification.context = super.cordova.getActivity().getApplicationContext(); LocalNotification.context = super.cordova.getActivity().getApplicationContext();
execPendingCallbacks();
} }
@Override @Override
...@@ -122,11 +121,34 @@ public class LocalNotification extends CordovaPlugin { ...@@ -122,11 +121,34 @@ public class LocalNotification extends CordovaPlugin {
return true; return true;
} }
if (action.equalsIgnoreCase("deviceready")) {
cordova.getThreadPool().execute( new Runnable() {
public void run() {
deviceready();
}
});
return true;
}
// Returning false results in a "MethodNotFound" error. // Returning false results in a "MethodNotFound" error.
return false; return false;
} }
/** /**
* Calls all pending callbacks after the deviceready event has been fired.
*/
private static void deviceready () {
deviceready = true;
for (String js : eventQueue) {
webView.sendJavascript(js);
}
eventQueue.clear();
}
/**
* Set an alarm. * Set an alarm.
* *
* @param options * @param options
...@@ -288,10 +310,8 @@ public class LocalNotification extends CordovaPlugin { ...@@ -288,10 +310,8 @@ public class LocalNotification extends CordovaPlugin {
String params = "\"" + id + "\",\"" + state + "\",\\'" + JSONObject.quote(json) + "\\'.replace(/(^\"|\"$)/g, \\'\\')"; String params = "\"" + id + "\",\"" + state + "\",\\'" + JSONObject.quote(json) + "\\'.replace(/(^\"|\"$)/g, \\'\\')";
String js = "setTimeout('plugin.notification.local.on" + event + "(" + params + ")',0)"; String js = "setTimeout('plugin.notification.local.on" + event + "(" + params + ")',0)";
// after reboot, LocalNotification.webView is always be null if (deviceready == false) {
// call background callback later eventQueue.add(js);
if (webView == null) {
callbackQueue.add(js);
} else { } else {
webView.sendJavascript(js); webView.sendJavascript(js);
} }
...@@ -337,15 +357,4 @@ public class LocalNotification extends CordovaPlugin { ...@@ -337,15 +357,4 @@ public class LocalNotification extends CordovaPlugin {
return true; return true;
} }
} }
/**
* Calls all pending callbacks after the webview was created.
*/
private void execPendingCallbacks () {
for (String js : callbackQueue) {
webView.sendJavascript(js);
}
callbackQueue.clear();
}
} }
\ No newline at end of file
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