Commit b9bb89a9 by PKnittel

Implemented new fireEvent-method on android.

parent ed78cdfb
...@@ -40,6 +40,7 @@ import android.content.Context; ...@@ -40,6 +40,7 @@ import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.Editor;
import android.os.Build; import android.os.Build;
import android.util.Log;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import de.appplant.cordova.plugin.notification.*; import de.appplant.cordova.plugin.notification.*;
...@@ -240,8 +241,8 @@ public class LocalNotification extends CordovaPlugin { ...@@ -240,8 +241,8 @@ public class LocalNotification extends CordovaPlugin {
Options options = new Options(context).parse(arguments); Options options = new Options(context).parse(arguments);
options.setInitDate(); options.setInitDate();
nWrapper.schedule(options); nWrapper.schedule(options);
JSONArray data = new JSONArray().put(options.getJSONObject()); JSONArray fireData= new JSONArray().put(options.getJSONObject());
fireEvent("add", options.getId(), options.getJSON(), data); fireEvent("add", options.getId(),options.getJSON(), fireData);
} }
} }
...@@ -270,7 +271,7 @@ public class LocalNotification extends CordovaPlugin { ...@@ -270,7 +271,7 @@ public class LocalNotification extends CordovaPlugin {
id = args.optString(i); id = args.optString(i);
nWrapper.cancel(id); nWrapper.cancel(id);
JSONArray managerId = new JSONArray().put(id); JSONArray managerId = new JSONArray().put(id);
JSONArray data = new JSONArray().put(manager.getAll(managerId)); JSONArray data = manager.getAll(managerId);
fireEvent("cancel", id, "",data); fireEvent("cancel", id, "",data);
} }
} }
...@@ -303,7 +304,7 @@ public class LocalNotification extends CordovaPlugin { ...@@ -303,7 +304,7 @@ public class LocalNotification extends CordovaPlugin {
id = args.optString(i); id = args.optString(i);
nWrapper.clear(id); nWrapper.clear(id);
JSONArray managerId = new JSONArray().put(id); JSONArray managerId = new JSONArray().put(id);
JSONArray data = new JSONArray().put(manager.getAll(managerId)); JSONArray data = manager.getAll(managerId);
fireEvent("clear", id, "",data); fireEvent("clear", id, "",data);
} }
} }
...@@ -401,21 +402,44 @@ public class LocalNotification extends CordovaPlugin { ...@@ -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} event The Name of the event
* @param {String} id The ID of the notification * @param {String} id The ID of the notification
* @param {String} json A custom (JSON) string * @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) { public static void fireEvent (String event, String id, String json, JSONArray data) {
String state = getApplicationState(); String state = getApplicationState();
//TODO dataArray handling String params = "\"" + id + "\",\"" + state + "\"," + JSONObject.quote(json)+","+ data;
String params = "\"" + id + "\",\"" + state + "\",\\'" + JSONObject.quote(json) + "\\'.replace(/(^\"|\"$)/g, \\'\\')";
// params = params + "," + dataArray;
String js = "setTimeout('plugin.notification.local.on" + event + "(" + params + ")',0)"; String js = "setTimeout('plugin.notification.local.on" + event + "(" + params + ")',0)";
// webview may available, but callbacks needs to be executed // webview may available, but callbacks needs to be executed
// after deviceready // after deviceready
Log.e("FireEvent","JS-String: "+ js);
if (deviceready == false) { if (deviceready == false) {
eventQueue.add(js); eventQueue.add(js);
} else { } else {
...@@ -423,6 +447,8 @@ public class LocalNotification extends CordovaPlugin { ...@@ -423,6 +447,8 @@ public class LocalNotification extends CordovaPlugin {
} }
} }
/** /**
* Retrieves the application state * 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