From d52aec691518ad568fe41e3dd07135bfd639630c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=BDivorad=20Mileki=C4=87?= Date: Sat, 24 Feb 2018 14:19:43 +0100 Subject: [PATCH 1/3] Don't display default icon in notification --- src/android/Notification.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/android/Notification.java b/src/android/Notification.java index 131df6fa..79508b4a 100644 --- a/src/android/Notification.java +++ b/src/android/Notification.java @@ -49,7 +49,7 @@ public Bitmap getLargeIcon() { Uri uri = assets.parse(this.icon); bmp = assets.getIconFromUri(uri); } catch (Exception e){ - bmp = assets.getIconFromDrawable(this.icon); + bmp = null; } return bmp; From 6d245da51fce9522ef353dff9c610489bed9095d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=BDivorad=20Mileki=C4=87?= Date: Sat, 24 Feb 2018 14:38:12 +0100 Subject: [PATCH 2/3] Added support for notification color --- src/android/GeoNotificationNotifier.java | 1 + src/android/Notification.java | 35 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/android/GeoNotificationNotifier.java b/src/android/GeoNotificationNotifier.java index 5afbf97c..899dd852 100644 --- a/src/android/GeoNotificationNotifier.java +++ b/src/android/GeoNotificationNotifier.java @@ -28,6 +28,7 @@ public void notify(Notification notification) { notification.setContext(context); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setVibrate(notification.getVibrate()) + .setColor(notification.getColor()) .setSmallIcon(notification.getSmallIcon()) .setLargeIcon(notification.getLargeIcon()) .setAutoCancel(true) diff --git a/src/android/Notification.java b/src/android/Notification.java index 79508b4a..5378face 100644 --- a/src/android/Notification.java +++ b/src/android/Notification.java @@ -2,7 +2,9 @@ import android.content.Context; import android.graphics.Bitmap; +import android.graphics.Color; import android.net.Uri; +import android.support.v4.app.NotificationCompat; import com.google.gson.annotations.Expose; @@ -16,6 +18,7 @@ public class Notification { @Expose public long[] vibrate = new long[] { 1000 }; @Expose public String icon = ""; @Expose public String smallIcon = ""; + @Expose public String color; @Expose public Object data; @Expose public boolean openAppOnClick; @@ -55,6 +58,34 @@ public Bitmap getLargeIcon() { return bmp; } + public int getColor() { + String hex = this.color; + + if (hex == null) + return NotificationCompat.COLOR_DEFAULT; + + try { + hex = stripHex(hex); + + if (hex.matches("[^0-9]*")) { + return Color.class + .getDeclaredField(hex.toUpperCase()) + .getInt(null); + } + + int aRGB = Integer.parseInt(hex, 16); + return aRGB + 0xFF000000; + } catch (NumberFormatException e) { + e.printStackTrace(); + } catch (NoSuchFieldException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + + return NotificationCompat.COLOR_DEFAULT; + } + public String getDataJson() { if (this.data == null) { return ""; @@ -77,4 +108,8 @@ private long[] concat(long[] a, long[] b) { System.arraycopy(b, 0, c, a.length, b.length); return c; } + + private String stripHex(String hex) { + return (hex.charAt(0) == '#') ? hex.substring(1) : hex; + } } From f58d5398db4aa2ff9894abd210033d723299ab80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=BDivorad=20Mileki=C4=87?= Date: Sat, 24 Feb 2018 14:52:33 +0100 Subject: [PATCH 3/3] Added color property in README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 54d99e88..82fce403 100644 --- a/README.md +++ b/README.md @@ -186,6 +186,7 @@ window.geofence.addOrUpdate({ text: String, //Text of notification smallIcon: String, //Small icon showed in notification area, only res URI icon: String, //icon showed in notification drawer + color: String, //Notification color, only hex openAppOnClick: Boolean,//is main app activity should be opened after clicking on notification vibration: [Integer], //Optional vibration pattern - see description data: Object //Custom object associated with notification