|
|
@@ -141,52 +141,34 @@ public class LocalNotification extends CordovaPlugin {
|
|
|
actions(args, command);
|
|
|
} else
|
|
|
if (action.equals("schedule")) {
|
|
|
- schedule(args);
|
|
|
- check(command);
|
|
|
+ schedule(args, command);
|
|
|
} else
|
|
|
if (action.equals("update")) {
|
|
|
- update(args);
|
|
|
- check(command);
|
|
|
+ update(args, command);
|
|
|
} else
|
|
|
if (action.equals("cancel")) {
|
|
|
- cancel(args);
|
|
|
- command.success();
|
|
|
+ cancel(args, command);
|
|
|
} else
|
|
|
if (action.equals("cancelAll")) {
|
|
|
- cancelAll();
|
|
|
- command.success();
|
|
|
+ cancelAll(command);
|
|
|
} else
|
|
|
if (action.equals("clear")) {
|
|
|
- clear(args);
|
|
|
- command.success();
|
|
|
+ clear(args, command);
|
|
|
} else
|
|
|
if (action.equals("clearAll")) {
|
|
|
- clearAll();
|
|
|
- command.success();
|
|
|
+ clearAll(command);
|
|
|
} else
|
|
|
if (action.equals("type")) {
|
|
|
- type(args.optInt(0), command);
|
|
|
+ type(args, command);
|
|
|
} else
|
|
|
if (action.equals("ids")) {
|
|
|
- ids(command);
|
|
|
- } else
|
|
|
- if (action.equals("scheduledIds")) {
|
|
|
- scheduledIds(command);
|
|
|
- } else
|
|
|
- if (action.equals("triggeredIds")) {
|
|
|
- triggeredIds(command);
|
|
|
+ ids(args, command);
|
|
|
} else
|
|
|
if (action.equals("notification")) {
|
|
|
- notification(args.optInt(0), command);
|
|
|
+ notification(args, command);
|
|
|
} else
|
|
|
if (action.equals("notifications")) {
|
|
|
notifications(args, command);
|
|
|
- } else
|
|
|
- if (action.equals("scheduledNotifications")) {
|
|
|
- scheduledNotifications(command);
|
|
|
- } else
|
|
|
- if (action.equals("triggeredNotifications")) {
|
|
|
- triggeredNotifications(command);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
@@ -248,35 +230,23 @@ public class LocalNotification extends CordovaPlugin {
|
|
|
* JavaScript.
|
|
|
*/
|
|
|
private void actions (JSONArray args, CallbackContext command) {
|
|
|
- int task = args.optInt(0);
|
|
|
-
|
|
|
- ActionGroup group;
|
|
|
- JSONObject spec;
|
|
|
- boolean found;
|
|
|
- String id;
|
|
|
+ int task = args.optInt(0);
|
|
|
+ String id = args.optString(1);
|
|
|
+ JSONObject spec = args.optJSONObject(2);
|
|
|
|
|
|
switch (task) {
|
|
|
- case 1:
|
|
|
- spec = args.optJSONObject(1);
|
|
|
- group = ActionGroup.parse(cordova.getActivity(), spec);
|
|
|
-
|
|
|
+ case 0:
|
|
|
+ ActionGroup group = ActionGroup.parse(cordova.getActivity(), spec);
|
|
|
if (group != null) ActionGroup.register(group);
|
|
|
command.success();
|
|
|
-
|
|
|
break;
|
|
|
- case -1:
|
|
|
- id = args.optString(1);
|
|
|
-
|
|
|
+ case 1:
|
|
|
ActionGroup.unregister(id);
|
|
|
command.success();
|
|
|
-
|
|
|
break;
|
|
|
- case 0:
|
|
|
- id = args.optString(1);
|
|
|
-
|
|
|
- found = ActionGroup.isRegistered(id);
|
|
|
+ case 2:
|
|
|
+ boolean found = ActionGroup.isRegistered(id);
|
|
|
success(command, found);
|
|
|
-
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
@@ -284,107 +254,130 @@ public class LocalNotification extends CordovaPlugin {
|
|
|
/**
|
|
|
* Schedule multiple local notifications.
|
|
|
*
|
|
|
- * @param notifications The notifications to schedule.
|
|
|
+ * @param toasts The notifications to schedule.
|
|
|
+ * @param command The callback context used when calling back into
|
|
|
+ * JavaScript.
|
|
|
*/
|
|
|
- private void schedule (JSONArray notifications) {
|
|
|
+ private void schedule (JSONArray toasts, CallbackContext command) {
|
|
|
Manager mgr = getNotMgr();
|
|
|
|
|
|
- for (int i = 0; i < notifications.length(); i++) {
|
|
|
- JSONObject dict = notifications.optJSONObject(i);
|
|
|
- Options options = new Options(dict);
|
|
|
- Request request = new Request(options);
|
|
|
-
|
|
|
- Notification notification =
|
|
|
- mgr.schedule(request, TriggerReceiver.class);
|
|
|
+ for (int i = 0; i < toasts.length(); i++) {
|
|
|
+ JSONObject dict = toasts.optJSONObject(i);
|
|
|
+ Options options = new Options(dict);
|
|
|
+ Request request = new Request(options);
|
|
|
+ Notification toast = mgr.schedule(request, TriggerReceiver.class);
|
|
|
|
|
|
- if (notification != null) {
|
|
|
- fireEvent("add", notification);
|
|
|
+ if (toast != null) {
|
|
|
+ fireEvent("add", toast);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ check(command);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Update multiple local notifications.
|
|
|
*
|
|
|
- * @param updates Notification properties including their IDs
|
|
|
+ * @param updates Notification properties including their IDs.
|
|
|
+ * @param command The callback context used when calling back into
|
|
|
+ * JavaScript.
|
|
|
*/
|
|
|
- private void update (JSONArray updates) {
|
|
|
- for (int i = 0; i < updates.length(); i++) {
|
|
|
- JSONObject update = updates.optJSONObject(i);
|
|
|
- int id = update.optInt("id", 0);
|
|
|
+ private void update (JSONArray updates, CallbackContext command) {
|
|
|
+ Manager mgr = getNotMgr();
|
|
|
|
|
|
- Notification notification =
|
|
|
- getNotMgr().update(id, update, TriggerReceiver.class);
|
|
|
+ for (int i = 0; i < updates.length(); i++) {
|
|
|
+ JSONObject update = updates.optJSONObject(i);
|
|
|
+ int id = update.optInt("id", 0);
|
|
|
+ Notification toast = mgr.update(id, update, TriggerReceiver.class);
|
|
|
|
|
|
- if (notification == null)
|
|
|
+ if (toast == null)
|
|
|
continue;
|
|
|
|
|
|
- fireEvent("update", notification);
|
|
|
+ fireEvent("update", toast);
|
|
|
}
|
|
|
+
|
|
|
+ check(command);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Cancel multiple local notifications.
|
|
|
*
|
|
|
- * @param ids Set of local notification IDs
|
|
|
+ * @param ids Set of local notification IDs.
|
|
|
+ * @param command The callback context used when calling back into
|
|
|
+ * JavaScript.
|
|
|
*/
|
|
|
- private void cancel (JSONArray ids) {
|
|
|
- for (int i = 0; i < ids.length(); i++) {
|
|
|
- int id = ids.optInt(i, 0);
|
|
|
+ private void cancel (JSONArray ids, CallbackContext command) {
|
|
|
+ Manager mgr = getNotMgr();
|
|
|
|
|
|
- Notification notification =
|
|
|
- getNotMgr().cancel(id);
|
|
|
+ for (int i = 0; i < ids.length(); i++) {
|
|
|
+ int id = ids.optInt(i, 0);
|
|
|
+ Notification toast = mgr.cancel(id);
|
|
|
|
|
|
- if (notification == null)
|
|
|
+ if (toast == null)
|
|
|
continue;
|
|
|
|
|
|
- fireEvent("cancel", notification);
|
|
|
+ fireEvent("cancel", toast);
|
|
|
}
|
|
|
+
|
|
|
+ command.success();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Cancel all scheduled notifications.
|
|
|
+ *
|
|
|
+ * @param command The callback context used when calling back into
|
|
|
+ * JavaScript.
|
|
|
*/
|
|
|
- private void cancelAll() {
|
|
|
+ private void cancelAll(CallbackContext command) {
|
|
|
getNotMgr().cancelAll();
|
|
|
fireEvent("cancelall");
|
|
|
+ command.success();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Clear multiple local notifications without canceling them.
|
|
|
*
|
|
|
- * @param ids Set of local notification IDs
|
|
|
+ * @param ids Set of local notification IDs.
|
|
|
+ * @param command The callback context used when calling back into
|
|
|
+ * JavaScript.
|
|
|
*/
|
|
|
- private void clear(JSONArray ids){
|
|
|
- for (int i = 0; i < ids.length(); i++) {
|
|
|
- int id = ids.optInt(i, 0);
|
|
|
+ private void clear(JSONArray ids, CallbackContext command) {
|
|
|
+ Manager mgr = getNotMgr();
|
|
|
|
|
|
- Notification notification =
|
|
|
- getNotMgr().clear(id);
|
|
|
+ for (int i = 0; i < ids.length(); i++) {
|
|
|
+ int id = ids.optInt(i, 0);
|
|
|
+ Notification toast = mgr.clear(id);
|
|
|
|
|
|
- if (notification == null)
|
|
|
+ if (toast == null)
|
|
|
continue;
|
|
|
|
|
|
- fireEvent("clear", notification);
|
|
|
+ fireEvent("clear", toast);
|
|
|
}
|
|
|
+
|
|
|
+ command.success();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Clear all triggered notifications without canceling them.
|
|
|
+ *
|
|
|
+ * @param command The callback context used when calling back into
|
|
|
+ * JavaScript.
|
|
|
*/
|
|
|
- private void clearAll() {
|
|
|
+ private void clearAll(CallbackContext command) {
|
|
|
getNotMgr().clearAll();
|
|
|
fireEvent("clearall");
|
|
|
+ command.success();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Get the type of the notification (unknown, scheduled, triggered).
|
|
|
*
|
|
|
- * @param id The ID of the notification to check.
|
|
|
+ * @param args The exec() arguments in JSON form.
|
|
|
* @param command The callback context used when calling back into
|
|
|
* JavaScript.
|
|
|
*/
|
|
|
- private void type (int id, CallbackContext command) {
|
|
|
+ private void type (JSONArray args, CallbackContext command) {
|
|
|
+ int id = args.optInt(0);
|
|
|
Notification toast = getNotMgr().get(id);
|
|
|
|
|
|
if (toast == null) {
|
|
|
@@ -408,48 +401,46 @@ public class LocalNotification extends CordovaPlugin {
|
|
|
/**
|
|
|
* Set of IDs from all existent notifications.
|
|
|
*
|
|
|
+ * @param args The exec() arguments in JSON form.
|
|
|
* @param command The callback context used when calling back into
|
|
|
* JavaScript.
|
|
|
*/
|
|
|
- private void ids (CallbackContext command) {
|
|
|
- List<Integer> ids = getNotMgr().getIds();
|
|
|
- command.success(new JSONArray(ids));
|
|
|
- }
|
|
|
+ private void ids (JSONArray args, CallbackContext command) {
|
|
|
+ int type = args.optInt(0);
|
|
|
+ Manager mgr = getNotMgr();
|
|
|
+ List<Integer> ids;
|
|
|
|
|
|
- /**
|
|
|
- * Set of IDs from all scheduled notifications.
|
|
|
- *
|
|
|
- * @param command The callback context used when calling back into
|
|
|
- * JavaScript.
|
|
|
- */
|
|
|
- private void scheduledIds (CallbackContext command) {
|
|
|
- List<Integer> ids = getNotMgr().getIdsByType(SCHEDULED);
|
|
|
- command.success(new JSONArray(ids));
|
|
|
- }
|
|
|
+ switch (type) {
|
|
|
+ case 0:
|
|
|
+ ids = mgr.getIds();
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ ids = mgr.getIdsByType(SCHEDULED);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ ids = mgr.getIdsByType(TRIGGERED);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ ids = new ArrayList<Integer>(0);
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * Set of IDs from all triggered notifications.
|
|
|
- *
|
|
|
- * @param command The callback context used when calling back into
|
|
|
- * JavaScript.
|
|
|
- */
|
|
|
- private void triggeredIds (CallbackContext command) {
|
|
|
- List<Integer> ids = getNotMgr().getIdsByType(TRIGGERED);
|
|
|
command.success(new JSONArray(ids));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Options from local notification.
|
|
|
*
|
|
|
- * @param id The ID of the notification.
|
|
|
+ * @param args The exec() arguments in JSON form.
|
|
|
* @param command The callback context used when calling back into
|
|
|
* JavaScript.
|
|
|
*/
|
|
|
- private void notification (int id, CallbackContext command) {
|
|
|
- Options options = getNotMgr().getOptions(id);
|
|
|
+ private void notification (JSONArray args, CallbackContext command) {
|
|
|
+ int id = args.optInt(0);
|
|
|
+ Options opts = getNotMgr().getOptions(id);
|
|
|
|
|
|
- if (options != null) {
|
|
|
- command.success(options.getDict());
|
|
|
+ if (opts != null) {
|
|
|
+ command.success(opts.getDict());
|
|
|
} else {
|
|
|
command.success();
|
|
|
}
|
|
|
@@ -458,48 +449,41 @@ public class LocalNotification extends CordovaPlugin {
|
|
|
/**
|
|
|
* Set of options from local notification.
|
|
|
*
|
|
|
- * @param ids Set of local notification IDs.
|
|
|
+ * @param args The exec() arguments in JSON form.
|
|
|
* @param command The callback context used when calling back into
|
|
|
* JavaScript.
|
|
|
*/
|
|
|
- private void notifications (JSONArray ids, CallbackContext command) {
|
|
|
+ private void notifications (JSONArray args, CallbackContext command) {
|
|
|
+ int type = args.optInt(0);
|
|
|
+ JSONArray ids = args.optJSONArray(1);
|
|
|
+ Manager mgr = getNotMgr();
|
|
|
List<JSONObject> options;
|
|
|
|
|
|
- if (ids.length() == 0) {
|
|
|
- options = getNotMgr().getOptions();
|
|
|
- } else {
|
|
|
- options = getNotMgr().getOptionsById(toList(ids));
|
|
|
+ switch (type) {
|
|
|
+ case 0:
|
|
|
+ options = mgr.getOptions();
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ options = mgr.getOptionsByType(SCHEDULED);
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ options = mgr.getOptionsByType(TRIGGERED);
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ options = mgr.getOptionsById(toList(ids));
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ options = new ArrayList<JSONObject>(0);
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
command.success(new JSONArray(options));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Set of options from scheduled notifications.
|
|
|
- *
|
|
|
- * @param command The callback context used when calling back into
|
|
|
- * JavaScript.
|
|
|
- */
|
|
|
- private void scheduledNotifications (CallbackContext command) {
|
|
|
- List<JSONObject> options = getNotMgr().getOptionsByType(SCHEDULED);
|
|
|
- command.success(new JSONArray(options));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Set of options from triggered notifications.
|
|
|
- *
|
|
|
- * @param command The callback context used when calling back into
|
|
|
- * JavaScript.
|
|
|
- */
|
|
|
- private void triggeredNotifications (CallbackContext command) {
|
|
|
- List<JSONObject> options = getNotMgr().getOptionsByType(TRIGGERED);
|
|
|
- command.success(new JSONArray(options));
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Call all pending callbacks after the deviceready event has been fired.
|
|
|
*/
|
|
|
- private static synchronized void deviceready () {
|
|
|
+ private static synchronized void deviceready() {
|
|
|
deviceready = true;
|
|
|
|
|
|
for (String js : eventQueue) {
|