Commit b9bb89a9 authored by PKnittel's avatar PKnittel
Browse files

Implemented new fireEvent-method on android.

parent ed78cdfb
Loading
Loading
Loading
Loading
+34 −8
Changes for src/android/LocalNotification.java: 34 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Build;
import android.util.Log;
import android.annotation.TargetApi;

import de.appplant.cordova.plugin.notification.*;
@@ -240,8 +241,8 @@ public class LocalNotification extends CordovaPlugin {
    		Options options      = new Options(context).parse(arguments);
    		options.setInitDate();
        	nWrapper.schedule(options);
        	JSONArray data = new JSONArray().put(options.getJSONObject());
       		fireEvent("add", options.getId(), options.getJSON(), data);
        	JSONArray fireData= new JSONArray().put(options.getJSONObject());
        	fireEvent("add", options.getId(),options.getJSON(), fireData);
    	}     	
    }
    
@@ -270,7 +271,7 @@ public class LocalNotification extends CordovaPlugin {
    		id = args.optString(i);
    		nWrapper.cancel(id);
        	JSONArray managerId = new JSONArray().put(id);
        	JSONArray data = new JSONArray().put(manager.getAll(managerId));
        	JSONArray data = manager.getAll(managerId);
            fireEvent("cancel", id, "",data);
    	}
    }
@@ -303,7 +304,7 @@ public class LocalNotification extends CordovaPlugin {
    		id = args.optString(i);
    		nWrapper.clear(id);
        	JSONArray managerId = new JSONArray().put(id);
        	JSONArray data = new JSONArray().put(manager.getAll(managerId));
        	JSONArray data = manager.getAll(managerId);
            fireEvent("clear", id, "",data);
    	}
    }
@@ -401,21 +402,44 @@ public class LocalNotification extends CordovaPlugin {

    // 
    /**
     * Fires the given event.
     * Fires the given event (Only one Callback also for multiple notifications in one action).
     *
     * @param {String} event The Name of the event
     * @param ids    The IDs of the notifications as JSONArray
     * @param json  The notifications JSONObjects in a JSONArray
     */
    public static void fireEvent (String event, JSONArray ids, JSONArray json) {
        String state  = getApplicationState();
        String params = ids + ",\"" + state + "\"," + json;
        String js     = "setTimeout('plugin.notification.local.on" + event + "(" + params + ")',0)";

        // webview may available, but callbacks needs to be executed
        // after deviceready
        Log.e("FireEvent","JS-String: "+ js);
        if (deviceready == false) {
            eventQueue.add(js);
        } else {
            sendJavascript(js);
        }
    }

    //
    /**
     * Fires the given event. (Standard-method)
     *
     * @param {String} event The Name of the event
     * @param {String} id The ID of the notification
     * @param {String} json A custom (JSON) string
     * @param data	The notifications as JSONObject
     */
    public static void fireEvent (String event, String id, String json, JSONArray data) {
    	String state = getApplicationState();
        //TODO dataArray handling
        String params = "\"" + id + "\",\"" + state + "\",\\'" + JSONObject.quote(json) + "\\'.replace(/(^\"|\"$)/g, \\'\\')";
     //   params = params + "," + dataArray;
    	String params = "\"" + id + "\",\"" + state + "\"," + JSONObject.quote(json)+","+ data;
    	String js = "setTimeout('plugin.notification.local.on" + event + "(" + params + ")',0)";
    
    	// webview may available, but callbacks needs to be executed
    	// after deviceready
    	Log.e("FireEvent","JS-String: "+ js);
    	if (deviceready == false) {
    		eventQueue.add(js);
    	} else {
@@ -423,6 +447,8 @@ public class LocalNotification extends CordovaPlugin {
    	}
    }
    
    
    
    /**
     * Retrieves the application state
     *