Commit 3b624527 authored by Sebastián Katzer's avatar Sebastián Katzer
Browse files

Add method implementation for `deviceready` for Android

parent 7e47b387
Loading
Loading
Loading
Loading
+27 −18
Changes for src/android/LocalNotification.java: 27 added lines, 18 removed lines.
Original line number Diff line number Diff line
@@ -54,9 +54,10 @@ public class LocalNotification extends CordovaPlugin {
    protected final static String PLUGIN_NAME = "LocalNotification";

    private   static CordovaWebView webView = null;
    private   static Boolean deviceready = false;
    protected static Context context = null;

    private   static ArrayList<String> callbackQueue = new ArrayList<String>();
    private   static ArrayList<String> eventQueue = new ArrayList<String>();

    @Override
    public void initialize (CordovaInterface cordova, CordovaWebView webView) {
@@ -64,8 +65,6 @@ public class LocalNotification extends CordovaPlugin {

        LocalNotification.webView = super.webView;
        LocalNotification.context = super.cordova.getActivity().getApplicationContext();

        execPendingCallbacks();
    }

    @Override
@@ -122,10 +121,33 @@ public class LocalNotification extends CordovaPlugin {
            return true;
        }

        if (action.equalsIgnoreCase("deviceready")) {
            cordova.getThreadPool().execute( new Runnable() {
                public void run() {
                    deviceready();
                }
            });

            return true;
        }

        // Returning false results in a "MethodNotFound" error.
        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.
     *
@@ -288,10 +310,8 @@ public class LocalNotification extends CordovaPlugin {
        String params = "\"" + id + "\",\"" + state + "\",\\'" + JSONObject.quote(json) + "\\'.replace(/(^\"|\"$)/g, \\'\\')";
        String js     = "setTimeout('plugin.notification.local.on" + event + "(" + params + ")',0)";

        // after reboot, LocalNotification.webView is always be null
        // call background callback later
        if (webView == null) {
            callbackQueue.add(js);
        if (deviceready == false) {
            eventQueue.add(js);
        } else {
            webView.sendJavascript(js);
        }
@@ -337,15 +357,4 @@ public class LocalNotification extends CordovaPlugin {
            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