@Override public void onReceive(Context context, Intent intent) { Options options = null; Bundle bundle = intent.getExtras(); JSONObject args; try { args = new JSONObject(bundle.getString(OPTIONS)); options = new Options(context).parse(args); } catch (JSONException e) { return; } this.context = context; this.options = options; // The context may got lost if the app was not running before LocalNotification.setContext(context); fireTriggerEvent(); if (options.getInterval() == 0) { LocalNotification.unpersist(options.getId()); } else if (isFirstAlarmInFuture()) { return; } else { LocalNotification.add(options.moveDate(), false); } Builder notification = buildNotification(); showNotification(notification); }
/** * Called when local notification was clicked by the user. * * @param notification Wrapper around the local notification */ @Override public void onClick(NotificationClass notification) { LocalNotification.fireEvent("click", notification); super.onClick(notification); if (notification.getOptions().isOngoing()) return; String event = notification.isRepeating() ? "clear" : "cancel"; LocalNotification.fireEvent(event, notification); }
/** Clear all alarms from the Android shared Preferences. */ public static void unpersistAll() { Editor editor = LocalNotification.getSharedPreferences().edit(); editor.clear(); editor.commit(); }
/** Fires ontrigger event. */ private void fireTriggerEvent() { LocalNotification.fireEvent("trigger", options.getId(), options.getJSON()); }