Ver Fonte

Set icon property to be null by default

Sebastián Katzer há 8 anos atrás
pai
commit
46b8f4f635

+ 1 - 2
src/android/LocalNotification.java

@@ -293,8 +293,7 @@ public class LocalNotification extends CordovaPlugin {
     /**
      * Update multiple local notifications.
      *
-     * @param updates
-     *      Notification properties including their IDs
+     * @param updates Notification properties including their IDs
      */
     private void update (JSONArray updates) {
         for (int i = 0; i < updates.length(); i++) {

+ 3 - 4
src/android/notification/Builder.java

@@ -116,7 +116,6 @@ public final class Builder {
             return new Notification(context, options);
         }
 
-        int smallIcon = options.getSmallIcon();
         Uri sound     = options.getSound();
         Bundle extras = new Bundle();
 
@@ -151,11 +150,11 @@ public final class Builder {
                     options.isIndeterminateProgress());
         }
 
-        if (smallIcon != 0) {
-            builder.setSmallIcon(smallIcon);
+        if (options.hasLargeIcon()) {
+            builder.setSmallIcon(options.getSmallIcon());
             builder.setLargeIcon(options.getLargeIcon());
         } else {
-            builder.setSmallIcon(options.getIcon());
+            builder.setSmallIcon(options.getSmallIcon());
         }
 
         applyStyle(builder);

+ 13 - 32
src/android/notification/Options.java

@@ -332,27 +332,21 @@ public final class Options {
         return assets.parse(options.optString("sound", null));
     }
 
-    public long[] getVibrate() {
-        JSONArray array = options.optJSONArray("vibrate");
-
-        if (array == null)
-            return null;
-
-        long[] rv = new long[array.length()];
-
-        for (int i = 0; i < array.length(); i++) {
-            rv[i] = array.optInt(i);
-        }
-
-        return rv;
+    /**
+     * Icon resource ID for the local notification.
+     */
+    public boolean hasLargeIcon () {
+        String icon = options.optString("icon", null);
+        return icon != null;
     }
 
     /**
      * Icon bitmap for the local notification.
      */
     Bitmap getLargeIcon() {
-        Uri uri    = assets.parse(options.optString("icon", DEFAULT_ICON));
-        Bitmap bmp = null;
+        String icon = options.optString("icon", null);
+        Uri uri     = assets.parse(icon);
+        Bitmap bmp  = null;
 
         try {
             bmp = assets.getIconFromUri(uri);
@@ -364,16 +358,11 @@ public final class Options {
     }
 
     /**
-     * Icon resource ID for the local notification.
+     * Small icon resource ID for the local notification.
      */
-    public int getIcon () {
-        String icon = options.optString("icon", DEFAULT_ICON);
-
-        int resId = assets.getResId(icon);
-
-        if (resId == 0) {
-            resId = getSmallIcon();
-        }
+    int getSmallIcon() {
+        String icon = options.optString("smallIcon", DEFAULT_ICON);
+        int resId   = assets.getResId(icon);
 
         if (resId == 0) {
             resId = assets.getResId(DEFAULT_ICON);
@@ -390,14 +379,6 @@ public final class Options {
         return resId;
     }
 
-    /**
-     * Small icon resource ID for the local notification.
-     */
-    int getSmallIcon() {
-        String icon = options.optString("smallIcon", "");
-        return assets.getResId(icon);
-    }
-
     /**
      * If the phone should vibrate.
      */

+ 6 - 2
www/local-notification-util.js

@@ -55,8 +55,8 @@ exports.applyPlatformSpecificOptions = function () {
         defaults.group        = null;
         defaults.groupSummary = false;
         defaults.summary      = null;
-        defaults.icon         = 'res://icon';
-        defaults.smallIcon    = null;
+        defaults.icon         = null;
+        defaults.smallIcon    = 'res://icon';
         defaults.sticky       = false;
         defaults.autoClear    = true;
         defaults.led          = true;
@@ -146,6 +146,10 @@ exports.convertProperties = function (options) {
         options.defaults = parseToInt('defaults', options);
     }
 
+    if (options.smallIcon && !options.smallIcon.match(/^res:/)) {
+        console.warn('Property "smallIcon" must be of kind res://...');
+    }
+
     options.data = JSON.stringify(options.data);
 
     this.convertTrigger(options);