Browse Source

Added color option for Android

Sebastián Katzer 10 năm trước cách đây
mục cha
commit
5cb48c4151

+ 2 - 1
CHANGELOG.md

@@ -4,7 +4,8 @@ ChangeLog
 Please also read the [Upgrade Guide](https://github.com/katzer/cordova-plugin-local-notifications/wiki/Upgrade-Guide) for more information.
 
 #### Version 0.8.3 (not yet released)
-- New "quarter" intervall for iOS & Android
+- New `color` attribute for Android (Thanks to @Eusebius1920)
+- New `quarter` intervall for iOS & Android
 - Made small icon optional (Android)
 - Fixed #588 crash when basename & extension can't be extracted (Android)
 - Fixed #732 loop between update and trigger (Android)

+ 5 - 0
src/android/notification/Builder.java

@@ -127,12 +127,17 @@ public class Builder {
                 .setTicker(options.getText())
                 .setAutoCancel(options.isAutoClear())
                 .setOngoing(options.isOngoing())
+                .setColor(options.getColor())
                 .setLights(options.getLedColor(), 500, 500);
 
         if (sound != null) {
             builder.setSound(sound);
         }
 
+        if (sound != null) {
+            builder.setSound(sound);
+        }
+
         if (smallIcon == 0) {
             builder.setSmallIcon(options.getIcon());
         } else {

+ 18 - 0
src/android/notification/Options.java

@@ -27,6 +27,7 @@ import android.app.AlarmManager;
 import android.content.Context;
 import android.graphics.Bitmap;
 import android.net.Uri;
+import android.support.v4.app.NotificationCompat;
 
 import org.json.JSONException;
 import org.json.JSONObject;
@@ -249,6 +250,23 @@ public class Options {
         return aRGB;
     }
 
+    /**
+     * @return
+     *      The notification background color for the small icon
+     *      Returns null, if no color is given.
+     */
+    public Integer getColor() {
+        String hex = options.optString("color", null);
+
+        if (hex == null) {
+            return NotificationCompat.COLOR_DEFAULT;
+        }
+
+        int aRGB = Integer.parseInt(hex, 16);
+
+        return aRGB + 0xFF000000;
+    }
+
     /**
      * Sound file path for the local notification.
      */

+ 1 - 0
www/local-notification-util.js

@@ -65,6 +65,7 @@ exports.applyPlatformSpecificOptions = function () {
         defaults.ongoing   = false;
         defaults.autoClear = true;
         defaults.led       = 'FFFFFF';
+        defaults.color     = undefined;
         break;
     }