Commit b9bb89a9 by PKnittel

Implemented new fireEvent-method on android.

parent ed78cdfb
......@@ -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,9 +241,9 @@ 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,20 @@ 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 {String} id The ID of the notification
* @param {String} json A custom (JSON) string
* @param ids The IDs of the notifications as JSONArray
* @param json The notifications JSONObjects in a JSONArray
*/
public static void fireEvent (String event, String id, String json, JSONArray data) {
public static void fireEvent (String event, JSONArray ids, JSONArray json) {
String state = getApplicationState();
//TODO dataArray handling
String params = "\"" + id + "\",\"" + state + "\",\\'" + JSONObject.quote(json) + "\\'.replace(/(^\"|\"$)/g, \\'\\')";
// params = params + "," + dataArray;
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 {
......@@ -423,6 +423,32 @@ public class LocalNotification extends CordovaPlugin {
}
}
//
/**
* 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();
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 {
sendJavascript(js);
}
}
/**
* Retrieves the application state
*
......
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