Commit adf62bf2 by Sebastián Katzer

Add `autoCancel` flag to indicate that the notification shall be automatically…

Add `autoCancel` flag to indicate that the notification shall be automatically canceled when the user clicks it
parent b129a48e
...@@ -50,6 +50,7 @@ More informations can be found [here](https://build.phonegap.com/plugins/331). ...@@ -50,6 +50,7 @@ More informations can be found [here](https://build.phonegap.com/plugins/331).
- [bugfix:] App throws an error on iOS if `message` is null. - [bugfix:] App throws an error on iOS if `message` is null.
- [bugfix:] Removed extra line break on iOS if `title` is null or empty. - [bugfix:] Removed extra line break on iOS if `title` is null or empty.
- [bugfix:] Notification on iOS will be canceled if a new one with the same ID was added. - [bugfix:] Notification on iOS will be canceled if a new one with the same ID was added.
- [enhancement:] Added `autoCancel` flag.
#### Version 0.6.3 (12.12.2013) #### Version 0.6.3 (12.12.2013)
- [bugfix:] Black screen on Android. - [bugfix:] Black screen on Android.
...@@ -99,15 +100,16 @@ All properties are optional. If no date object is given, the notification will p ...@@ -99,15 +100,16 @@ All properties are optional. If no date object is given, the notification will p
```javascript ```javascript
window.plugin.notification.local.add({ window.plugin.notification.local.add({
id: String, // a unique id of the notifiction id: String, // A unique id of the notifiction
date: Date, // this expects a date object date: Date, // This expects a date object
message: String, // the message that is displayed message: String, // The message that is displayed
title: String, // the title of the message title: String, // The title of the message
repeat: String, // has the options of daily', 'weekly',''monthly','yearly') repeat: String, // Has the options of daily', 'weekly',''monthly','yearly')
badge: Number, // displays number badge to notification badge: Number, // Displays number badge to notification
sound: String, // a sound to be played (iOS & Android) sound: String, // A sound to be played (iOS & Android)
foreground: String, // a javascript function to be called if the app is running autoCancel: Boolean, // Setting this flag and the notification is automatically canceled when the user clicks it
background: String, // a javascript function to be called if the app is in the background foreground: String, // A javascript function to be called if the app is running
background: String, // A javascript function to be called if the app is in the background
}); });
``` ```
**Note:** On Android the notification id needs to be a string which can be converted to a number. If the ID has an invalid format, it will be ignored, but canceling the notification will fail. **Note:** On Android the notification id needs to be a string which can be converted to a number. If the ID has an invalid format, it will be ignored, but canceling the notification will fail.
......
...@@ -38,10 +38,8 @@ import android.net.Uri; ...@@ -38,10 +38,8 @@ import android.net.Uri;
public class Options { public class Options {
private JSONObject options = new JSONObject(); private JSONObject options = new JSONObject();
private String id = null;
private String packageName = null; private String packageName = null;
private long interval = 0; private long interval = 0;
private long date = 0;
Options (Activity activity) { Options (Activity activity) {
packageName = activity.getPackageName(); packageName = activity.getPackageName();
...@@ -58,8 +56,6 @@ public class Options { ...@@ -58,8 +56,6 @@ public class Options {
String repeat = options.optString("repeat"); String repeat = options.optString("repeat");
this.options = options; this.options = options;
date = options.optLong("date") * 1000;
id = options.optString("id");
if (repeat.equalsIgnoreCase("daily")) { if (repeat.equalsIgnoreCase("daily")) {
interval = AlarmManager.INTERVAL_DAY; interval = AlarmManager.INTERVAL_DAY;
...@@ -85,7 +81,7 @@ public class Options { ...@@ -85,7 +81,7 @@ public class Options {
* Gibt die Zeit in Sekunden an, wann die Notification aufpoppen soll. * Gibt die Zeit in Sekunden an, wann die Notification aufpoppen soll.
*/ */
public long getDate() { public long getDate() {
return date; return options.optLong("date", 0) * 1000;
} }
/** /**
...@@ -103,14 +99,14 @@ public class Options { ...@@ -103,14 +99,14 @@ public class Options {
* Gibt die Nachricht der Notification an. * Gibt die Nachricht der Notification an.
*/ */
public String getMessage () { public String getMessage () {
return options.optString("message"); return options.optString("message", "");
} }
/** /**
* Gibt den Titel der Notification an. * Gibt den Titel der Notification an.
*/ */
public String getTitle () { public String getTitle () {
return options.optString("title"); return options.optString("title", "");
} }
/** /**
...@@ -184,7 +180,14 @@ public class Options { ...@@ -184,7 +180,14 @@ public class Options {
* Gibt die Callback-ID des PluginResults an. * Gibt die Callback-ID des PluginResults an.
*/ */
public String getId () { public String getId () {
return id; return options.optString("id", "0");
}
/**
* Gibt an, ob die Notification automatisch geschlossen werden soll, wenn der Benutzer darauf klickt.
*/
public Boolean getAutoCancel () {
return options.optBoolean("autoCancel", false);
} }
/** /**
......
...@@ -121,7 +121,8 @@ public class Receiver extends BroadcastReceiver { ...@@ -121,7 +121,8 @@ public class Receiver extends BroadcastReceiver {
.setNumber(options.getBadge()) .setNumber(options.getBadge())
.setTicker(options.getTitle()) .setTicker(options.getTitle())
.setSmallIcon(options.getIcon()) .setSmallIcon(options.getIcon())
.setSound(options.getSound()); .setSound(options.getSound())
.setAutoCancel(options.getAutoCancel());
setClickEvent(notification); setClickEvent(notification);
......
...@@ -23,8 +23,6 @@ ...@@ -23,8 +23,6 @@
@interface APPLocalNotification (Private) @interface APPLocalNotification (Private)
// Entfernt die zur ID passende Meldung
- (void) cancelNotificationWithId:(NSString*)notificationId;
- (NSMutableDictionary*) repeatDict; - (NSMutableDictionary*) repeatDict;
// Alle zusätzlichen Metadaten der Notification als Hash // Alle zusätzlichen Metadaten der Notification als Hash
- (NSDictionary*) userDict:(NSMutableDictionary*)options; - (NSDictionary*) userDict:(NSMutableDictionary*)options;
...@@ -58,7 +56,9 @@ ...@@ -58,7 +56,9 @@
} }
/** /**
* Entfernt die zur ID passende Meldung. * Entfernt den anhand der ID angegebenen Eintrag.
*
* @param {NSString} id Die ID der Notification
*/ */
- (void) cancel:(CDVInvokedUrlCommand*)command - (void) cancel:(CDVInvokedUrlCommand*)command
{ {
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
} }
/** /**
* Entfernt die zur ID passende Meldung. * Entfernt den anhand der ID angegebenen Eintrag.
* *
* @param {NSString} id Die ID der Notification * @param {NSString} id Die ID der Notification
*/ */
...@@ -127,8 +127,9 @@ ...@@ -127,8 +127,9 @@
NSString* id = [options objectForKey:@"id"]; NSString* id = [options objectForKey:@"id"];
NSString* bg = [options objectForKey:@"background"]; NSString* bg = [options objectForKey:@"background"];
NSString* fg = [options objectForKey:@"foreground"]; NSString* fg = [options objectForKey:@"foreground"];
NSString* ac = [options objectForKey:@"autoCancel"];
return [NSDictionary dictionaryWithObjectsAndKeys:id, @"id", bg, @"background", fg, @"foreground", nil]; return [NSDictionary dictionaryWithObjectsAndKeys:id, @"id", bg, @"background", fg, @"foreground", ac, @"autoCancel", nil];
} }
/** /**
...@@ -191,6 +192,12 @@ ...@@ -191,6 +192,12 @@
NSString* id = [notification.userInfo objectForKey:@"id"]; NSString* id = [notification.userInfo objectForKey:@"id"];
NSString* callbackType = isActive ? @"foreground" : @"background"; NSString* callbackType = isActive ? @"foreground" : @"background";
NSString* callbackFn = [notification.userInfo objectForKey:callbackType]; NSString* callbackFn = [notification.userInfo objectForKey:callbackType];
BOOL autoCancel = [[notification.userInfo objectForKey:@"autoCancel"] boolValue];
if (autoCancel && !isActive)
{
[[UIApplication sharedApplication] cancelLocalNotification:notification];
}
if (callbackFn && callbackFn.length > 0) if (callbackFn && callbackFn.length > 0)
{ {
......
...@@ -93,6 +93,12 @@ namespace De.APPPlant.Cordova.Plugin.LocalNotification ...@@ -93,6 +93,12 @@ namespace De.APPPlant.Cordova.Plugin.LocalNotification
public string Foreground { get; set; } public string Foreground { get; set; }
/// <summary> /// <summary>
/// Setting this flag will make it so the notification is automatically canceled when the user clicks it
/// </summary>
[DataMember(IsRequired = false, Name = "autoCancel")]
public bool AutoCancel { get; set; }
/// <summary>
/// The notification small background image to be displayed /// The notification small background image to be displayed
/// </summary> /// </summary>
[DataMember(IsRequired = false, Name = "smallImage")] [DataMember(IsRequired = false, Name = "smallImage")]
......
/** /*
* locale-notification.js Copyright 2013 appPlant UG
* Cordova LocalNotification Plugin
* Licensed to the Apache Software Foundation (ASF) under one
* Created by Sebastian Katzer (github.com/katzer) on 10/08/2013. or more contributor license agreements. See the NOTICE file
* Copyright 2013 Sebastian Katzer. All rights reserved. distributed with this work for additional information
* GPL v2 licensed regarding copyright ownership. The ASF licenses this file
*/ to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
var LocalNotification = function () { var LocalNotification = function () {
...@@ -23,11 +35,12 @@ LocalNotification.prototype = { ...@@ -23,11 +35,12 @@ LocalNotification.prototype = {
date: new Date(), date: new Date(),
message: '', message: '',
title: '', title: '',
autoCancel: false,
badge: 0, badge: 0,
id: 0, id: 0,
repeat: '', repeat: '',
background: undefined, background: '',
foreground: undefined foreground: ''
}; };
switch (device.platform) { switch (device.platform) {
......
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