Loading plugin.xml +6 −1 Changes for plugin.xml: 6 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -100,10 +100,15 @@ <source-file src="src/android/LocalNotification.java" target-dir="src/de/appplant/cordova/plugin/localnotification" /> <source-file src="src/android/Receiver.java" target-dir="src/de/appplant/cordova/plugin/localnotification" /> <source-file src="src/android/Options.java" target-dir="src/de/appplant/cordova/plugin/localnotification" /> <source-file src="src/android/Restore.java" target-dir="src/de/appplant/cordova/plugin/localnotification" /> <source-file src="src/android/ReceiverActivity.java" target-dir="src/de/appplant/cordova/plugin/localnotification" /> <source-file src="src/android/DeleteIntentReceiver.java" target-dir="src/de/appplant/cordova/plugin/localnotification" /> <source-file src="src/android/notification/Options.java" target-dir="src/de/appplant/cordova/plugin/notification" /> <source-file src="src/android/notification/Asset.java" target-dir="src/de/appplant/cordova/plugin/notification" /> <source-file src="src/android/notification/Manager.java" target-dir="src/de/appplant/cordova/plugin/notification" /> <source-file src="src/android/notification/NotificationBuilder.java" target-dir="src/de/appplant/cordova/plugin/notification" /> <source-file src="src/android/notification/NotificationWrapper.java" target-dir="src/de/appplant/cordova/plugin/notification" /> </platform> <!-- wp8 --> Loading src/android/DeleteIntentReceiver.java +10 −12 Changes for src/android/DeleteIntentReceiver.java: 10 added lines, 12 removed lines. Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ package de.appplant.cordova.plugin.localnotification; import java.util.Date; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; Loading @@ -31,10 +32,15 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; import de.appplant.cordova.plugin.notification.Options; public class DeleteIntentReceiver extends BroadcastReceiver { public static final String OPTIONS = "LOCAL_NOTIFICATION_OPTIONS"; /** * Is called when a Notification is cleared manualy by the User */ @Override public void onReceive(Context context, Intent intent) { Options options = null; Loading @@ -53,7 +59,8 @@ public class DeleteIntentReceiver extends BroadcastReceiver { Date now = new Date(); if ((options.getInterval()!=0)){ LocalNotification.persist(options.getId(), setInitDate(args)); options.setInitDate(); LocalNotification.persist(options.getId(), options.getJSONObject()); } else if((new Date(options.getDate()).before(now))){ LocalNotification.unpersist(options.getId()); Loading @@ -62,21 +69,12 @@ public class DeleteIntentReceiver extends BroadcastReceiver { fireClearEvent(options); } private JSONObject setInitDate(JSONObject arguments){ long initialDate = arguments.optLong("date", 0) * 1000; try { arguments.put("initialDate", initialDate); } catch (JSONException e) { e.printStackTrace(); } return arguments; } /** * Fires onclear event. */ private void fireClearEvent (Options options) { LocalNotification.fireEvent("clear", options.getId(), options.getJSON()); JSONArray data = new JSONArray().put(options.getJSONObject()); LocalNotification.fireEvent("clear", options.getId(), options.getJSON(),data); } } src/android/LocalNotification.java +137 −405 File changed.Preview size limit exceeded, changes collapsed. Show changes src/android/Receiver.java +14 −92 Changes for src/android/Receiver.java: 14 added lines, 92 removed lines. Original line number Diff line number Diff line Loading @@ -22,23 +22,18 @@ package de.appplant.cordova.plugin.localnotification; import java.util.Calendar; import java.util.Random; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.annotation.SuppressLint; import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat.*; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Build; import android.os.Bundle; import de.appplant.cordova.plugin.notification.*; /** * The alarm receiver is triggered when a scheduled alarm is fired. This class * reads the information in the intent and displays this information in the Loading @@ -49,11 +44,12 @@ public class Receiver extends BroadcastReceiver { public static final String OPTIONS = "LOCAL_NOTIFICATION_OPTIONS"; private Context context; private Options options; @Override public void onReceive (Context context, Intent intent) { NotificationWrapper nWrapper = new NotificationWrapper(context, Receiver.class,LocalNotification.PLUGIN_NAME,OPTIONS); Options options = null; Bundle bundle = intent.getExtras(); JSONObject args; Loading @@ -64,10 +60,11 @@ public class Receiver extends BroadcastReceiver { } catch (JSONException e) { return; } this.context = context; this.options = options; NotificationBuilder builder = new NotificationBuilder(options,context,OPTIONS, DeleteIntentReceiver.class,ReceiverActivity.class); // The context may got lost if the app was not running before LocalNotification.setContext(context); Loading @@ -77,18 +74,18 @@ public class Receiver extends BroadcastReceiver { } else if (isFirstAlarmInFuture()) { return; } else { LocalNotification.add(options.moveDate(), false); nWrapper.schedule(options.moveDate()); } if (!LocalNotification.isInBackground && options.getForegroundMode()){ if (options.getInterval() == 0) { LocalNotification.unpersist(options.getId()); } LocalNotification.showNotification(options.getTitle(), options.getMessage()); builder.showNotificationToast(); fireTriggerEvent(); } else { Builder notification = buildNotification(); builder.buildNotification(); showNotification(notification); builder.showNotification(); } } Loading Loading @@ -117,86 +114,11 @@ public class Receiver extends BroadcastReceiver { return false; } /** * Creates the notification. */ @SuppressLint("NewApi") private Builder buildNotification () { Uri sound = options.getSound(); //DeleteIntent is called when the user clears a notification manually Intent deleteIntent = new Intent(context, DeleteIntentReceiver.class) .setAction("" + options.getId()) .putExtra(Receiver.OPTIONS, options.getJSONObject().toString()); PendingIntent dpi = PendingIntent.getBroadcast(context, 0, deleteIntent, PendingIntent.FLAG_CANCEL_CURRENT); Builder notification = new NotificationCompat.Builder(context) .setDefaults(0) // Do not inherit any defaults .setContentTitle(options.getTitle()) .setContentText(options.getMessage()) .setNumber(options.getBadge()) .setTicker(options.getMessage()) .setSmallIcon(options.getSmallIcon()) .setLargeIcon(options.getIcon()) .setAutoCancel(options.getAutoCancel()) .setOngoing(options.getOngoing()) .setLights(options.getColor(), 500, 500) .setDeleteIntent(dpi); if (sound != null) { notification.setSound(sound); } if (Build.VERSION.SDK_INT > 16) { notification.setStyle(new NotificationCompat.BigTextStyle() .bigText(options.getMessage())); } setClickEvent(notification); return notification; } /** * Adds an onclick handler to the notification */ private Builder setClickEvent (Builder notification) { Intent intent = new Intent(context, ReceiverActivity.class) .putExtra(OPTIONS, options.getJSONObject().toString()) .setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); int requestCode = new Random().nextInt(); PendingIntent contentIntent = PendingIntent.getActivity(context, requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT); return notification.setContentIntent(contentIntent); } /** * Shows the notification */ @SuppressWarnings("deprecation") private void showNotification (Builder notification) { NotificationManager mgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); int id = 0; try { id = Integer.parseInt(options.getId()); } catch (Exception e) {} if (Build.VERSION.SDK_INT<16) { // build notification for HoneyComb to ICS mgr.notify(id, notification.getNotification()); } else if (Build.VERSION.SDK_INT>15) { // Notification for Jellybean and above mgr.notify(id, notification.build()); } } /** * Fires ontrigger event. */ private void fireTriggerEvent () { LocalNotification.fireEvent("trigger", options.getId(), options.getJSON()); JSONArray data = new JSONArray().put(options.getJSONObject()); LocalNotification.fireEvent("trigger", options.getId(), options.getJSON(),data); } } src/android/ReceiverActivity.java +6 −2 Changes for src/android/ReceiverActivity.java: 6 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -23,12 +23,15 @@ package de.appplant.cordova.plugin.localnotification; import org.json.JSONException; import org.json.JSONObject; import org.json.JSONArray; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import de.appplant.cordova.plugin.notification.*; public class ReceiverActivity extends Activity { /** Called when the activity is first created. */ Loading Loading @@ -65,10 +68,11 @@ public class ReceiverActivity extends Activity { * Fires the onclick event. */ private void fireClickEvent (Options options) { LocalNotification.fireEvent("click", options.getId(), options.getJSON()); JSONArray data = new JSONArray().put(options.getJSONObject()); LocalNotification.fireEvent("click", options.getId(), options.getJSON(),data); if (options.getAutoCancel()) { LocalNotification.fireEvent("cancel", options.getId(), options.getJSON()); LocalNotification.fireEvent("cancel", options.getId(), options.getJSON(),data); } } } Loading
plugin.xml +6 −1 Changes for plugin.xml: 6 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -100,10 +100,15 @@ <source-file src="src/android/LocalNotification.java" target-dir="src/de/appplant/cordova/plugin/localnotification" /> <source-file src="src/android/Receiver.java" target-dir="src/de/appplant/cordova/plugin/localnotification" /> <source-file src="src/android/Options.java" target-dir="src/de/appplant/cordova/plugin/localnotification" /> <source-file src="src/android/Restore.java" target-dir="src/de/appplant/cordova/plugin/localnotification" /> <source-file src="src/android/ReceiverActivity.java" target-dir="src/de/appplant/cordova/plugin/localnotification" /> <source-file src="src/android/DeleteIntentReceiver.java" target-dir="src/de/appplant/cordova/plugin/localnotification" /> <source-file src="src/android/notification/Options.java" target-dir="src/de/appplant/cordova/plugin/notification" /> <source-file src="src/android/notification/Asset.java" target-dir="src/de/appplant/cordova/plugin/notification" /> <source-file src="src/android/notification/Manager.java" target-dir="src/de/appplant/cordova/plugin/notification" /> <source-file src="src/android/notification/NotificationBuilder.java" target-dir="src/de/appplant/cordova/plugin/notification" /> <source-file src="src/android/notification/NotificationWrapper.java" target-dir="src/de/appplant/cordova/plugin/notification" /> </platform> <!-- wp8 --> Loading
src/android/DeleteIntentReceiver.java +10 −12 Changes for src/android/DeleteIntentReceiver.java: 10 added lines, 12 removed lines. Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ package de.appplant.cordova.plugin.localnotification; import java.util.Date; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; Loading @@ -31,10 +32,15 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; import de.appplant.cordova.plugin.notification.Options; public class DeleteIntentReceiver extends BroadcastReceiver { public static final String OPTIONS = "LOCAL_NOTIFICATION_OPTIONS"; /** * Is called when a Notification is cleared manualy by the User */ @Override public void onReceive(Context context, Intent intent) { Options options = null; Loading @@ -53,7 +59,8 @@ public class DeleteIntentReceiver extends BroadcastReceiver { Date now = new Date(); if ((options.getInterval()!=0)){ LocalNotification.persist(options.getId(), setInitDate(args)); options.setInitDate(); LocalNotification.persist(options.getId(), options.getJSONObject()); } else if((new Date(options.getDate()).before(now))){ LocalNotification.unpersist(options.getId()); Loading @@ -62,21 +69,12 @@ public class DeleteIntentReceiver extends BroadcastReceiver { fireClearEvent(options); } private JSONObject setInitDate(JSONObject arguments){ long initialDate = arguments.optLong("date", 0) * 1000; try { arguments.put("initialDate", initialDate); } catch (JSONException e) { e.printStackTrace(); } return arguments; } /** * Fires onclear event. */ private void fireClearEvent (Options options) { LocalNotification.fireEvent("clear", options.getId(), options.getJSON()); JSONArray data = new JSONArray().put(options.getJSONObject()); LocalNotification.fireEvent("clear", options.getId(), options.getJSON(),data); } }
src/android/LocalNotification.java +137 −405 File changed.Preview size limit exceeded, changes collapsed. Show changes
src/android/Receiver.java +14 −92 Changes for src/android/Receiver.java: 14 added lines, 92 removed lines. Original line number Diff line number Diff line Loading @@ -22,23 +22,18 @@ package de.appplant.cordova.plugin.localnotification; import java.util.Calendar; import java.util.Random; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import android.annotation.SuppressLint; import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat.*; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Build; import android.os.Bundle; import de.appplant.cordova.plugin.notification.*; /** * The alarm receiver is triggered when a scheduled alarm is fired. This class * reads the information in the intent and displays this information in the Loading @@ -49,11 +44,12 @@ public class Receiver extends BroadcastReceiver { public static final String OPTIONS = "LOCAL_NOTIFICATION_OPTIONS"; private Context context; private Options options; @Override public void onReceive (Context context, Intent intent) { NotificationWrapper nWrapper = new NotificationWrapper(context, Receiver.class,LocalNotification.PLUGIN_NAME,OPTIONS); Options options = null; Bundle bundle = intent.getExtras(); JSONObject args; Loading @@ -64,10 +60,11 @@ public class Receiver extends BroadcastReceiver { } catch (JSONException e) { return; } this.context = context; this.options = options; NotificationBuilder builder = new NotificationBuilder(options,context,OPTIONS, DeleteIntentReceiver.class,ReceiverActivity.class); // The context may got lost if the app was not running before LocalNotification.setContext(context); Loading @@ -77,18 +74,18 @@ public class Receiver extends BroadcastReceiver { } else if (isFirstAlarmInFuture()) { return; } else { LocalNotification.add(options.moveDate(), false); nWrapper.schedule(options.moveDate()); } if (!LocalNotification.isInBackground && options.getForegroundMode()){ if (options.getInterval() == 0) { LocalNotification.unpersist(options.getId()); } LocalNotification.showNotification(options.getTitle(), options.getMessage()); builder.showNotificationToast(); fireTriggerEvent(); } else { Builder notification = buildNotification(); builder.buildNotification(); showNotification(notification); builder.showNotification(); } } Loading Loading @@ -117,86 +114,11 @@ public class Receiver extends BroadcastReceiver { return false; } /** * Creates the notification. */ @SuppressLint("NewApi") private Builder buildNotification () { Uri sound = options.getSound(); //DeleteIntent is called when the user clears a notification manually Intent deleteIntent = new Intent(context, DeleteIntentReceiver.class) .setAction("" + options.getId()) .putExtra(Receiver.OPTIONS, options.getJSONObject().toString()); PendingIntent dpi = PendingIntent.getBroadcast(context, 0, deleteIntent, PendingIntent.FLAG_CANCEL_CURRENT); Builder notification = new NotificationCompat.Builder(context) .setDefaults(0) // Do not inherit any defaults .setContentTitle(options.getTitle()) .setContentText(options.getMessage()) .setNumber(options.getBadge()) .setTicker(options.getMessage()) .setSmallIcon(options.getSmallIcon()) .setLargeIcon(options.getIcon()) .setAutoCancel(options.getAutoCancel()) .setOngoing(options.getOngoing()) .setLights(options.getColor(), 500, 500) .setDeleteIntent(dpi); if (sound != null) { notification.setSound(sound); } if (Build.VERSION.SDK_INT > 16) { notification.setStyle(new NotificationCompat.BigTextStyle() .bigText(options.getMessage())); } setClickEvent(notification); return notification; } /** * Adds an onclick handler to the notification */ private Builder setClickEvent (Builder notification) { Intent intent = new Intent(context, ReceiverActivity.class) .putExtra(OPTIONS, options.getJSONObject().toString()) .setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); int requestCode = new Random().nextInt(); PendingIntent contentIntent = PendingIntent.getActivity(context, requestCode, intent, PendingIntent.FLAG_CANCEL_CURRENT); return notification.setContentIntent(contentIntent); } /** * Shows the notification */ @SuppressWarnings("deprecation") private void showNotification (Builder notification) { NotificationManager mgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); int id = 0; try { id = Integer.parseInt(options.getId()); } catch (Exception e) {} if (Build.VERSION.SDK_INT<16) { // build notification for HoneyComb to ICS mgr.notify(id, notification.getNotification()); } else if (Build.VERSION.SDK_INT>15) { // Notification for Jellybean and above mgr.notify(id, notification.build()); } } /** * Fires ontrigger event. */ private void fireTriggerEvent () { LocalNotification.fireEvent("trigger", options.getId(), options.getJSON()); JSONArray data = new JSONArray().put(options.getJSONObject()); LocalNotification.fireEvent("trigger", options.getId(), options.getJSON(),data); } }
src/android/ReceiverActivity.java +6 −2 Changes for src/android/ReceiverActivity.java: 6 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -23,12 +23,15 @@ package de.appplant.cordova.plugin.localnotification; import org.json.JSONException; import org.json.JSONObject; import org.json.JSONArray; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import de.appplant.cordova.plugin.notification.*; public class ReceiverActivity extends Activity { /** Called when the activity is first created. */ Loading Loading @@ -65,10 +68,11 @@ public class ReceiverActivity extends Activity { * Fires the onclick event. */ private void fireClickEvent (Options options) { LocalNotification.fireEvent("click", options.getId(), options.getJSON()); JSONArray data = new JSONArray().put(options.getJSONObject()); LocalNotification.fireEvent("click", options.getId(), options.getJSON(),data); if (options.getAutoCancel()) { LocalNotification.fireEvent("cancel", options.getId(), options.getJSON()); LocalNotification.fireEvent("cancel", options.getId(), options.getJSON(),data); } } }