From 09b0a8b161418d915eb85f04e1be2462a891271f Mon Sep 17 00:00:00 2001 From: Torsten Grote <t@grobox.de> Date: Tue, 13 Dec 2016 15:07:43 -0200 Subject: [PATCH] Use different notification icons for different features and use the primary color for the notification. --- .../android/AndroidNotificationManagerImpl.java | 16 +++++++++++----- .../briarproject/briar/android/BriarService.java | 4 +++- .../res/drawable/introduction_notification.xml | 9 --------- .../res/drawable/message_notification_icon.xml | 9 --------- .../src/main/res/drawable/notification_blog.xml | 10 ++++++++++ .../src/main/res/drawable/notification_forum.xml | 10 ++++++++++ .../res/drawable/notification_introduction.xml | 10 ++++++++++ ...ication_icon.xml => notification_ongoing.xml} | 0 .../res/drawable/notification_private_group.xml | 10 ++++++++++ .../drawable/notification_private_message.xml | 10 ++++++++++ 10 files changed, 64 insertions(+), 24 deletions(-) delete mode 100644 briar-android/src/main/res/drawable/introduction_notification.xml delete mode 100644 briar-android/src/main/res/drawable/message_notification_icon.xml create mode 100644 briar-android/src/main/res/drawable/notification_blog.xml create mode 100644 briar-android/src/main/res/drawable/notification_forum.xml create mode 100644 briar-android/src/main/res/drawable/notification_introduction.xml rename briar-android/src/main/res/drawable/{ongoing_notification_icon.xml => notification_ongoing.xml} (100%) create mode 100644 briar-android/src/main/res/drawable/notification_private_group.xml create mode 100644 briar-android/src/main/res/drawable/notification_private_message.xml diff --git a/briar-android/src/main/java/org/briarproject/briar/android/AndroidNotificationManagerImpl.java b/briar-android/src/main/java/org/briarproject/briar/android/AndroidNotificationManagerImpl.java index 3f1dc6d096..d41835c809 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/AndroidNotificationManagerImpl.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/AndroidNotificationManagerImpl.java @@ -12,6 +12,7 @@ import android.os.Build; import android.support.annotation.UiThread; import android.support.v4.app.NotificationCompat; import android.support.v4.app.TaskStackBuilder; +import android.support.v4.content.ContextCompat; import org.briarproject.bramble.api.contact.ContactId; import org.briarproject.bramble.api.db.DatabaseExecutor; @@ -327,7 +328,8 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager, } else if (settings.getBoolean("notifyPrivateMessages", true)) { NotificationCompat.Builder b = new NotificationCompat.Builder(appContext); - b.setSmallIcon(R.drawable.message_notification_icon); + b.setSmallIcon(R.drawable.notification_private_message); + b.setColor(ContextCompat.getColor(appContext, R.color.briar_primary)); b.setContentTitle(appContext.getText(R.string.app_name)); b.setContentText(appContext.getResources().getQuantityString( R.plurals.private_message_notification_text, contactTotal, @@ -435,7 +437,8 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager, } else if (settings.getBoolean(PREF_NOTIFY_GROUP, true)) { NotificationCompat.Builder b = new NotificationCompat.Builder(appContext); - b.setSmallIcon(R.drawable.message_notification_icon); + b.setSmallIcon(R.drawable.notification_private_group); + b.setColor(ContextCompat.getColor(appContext, R.color.briar_primary)); b.setContentTitle(appContext.getText(R.string.app_name)); b.setContentText(appContext.getResources().getQuantityString( R.plurals.group_message_notification_text, groupTotal, @@ -530,7 +533,8 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager, } else if (settings.getBoolean("notifyForumPosts", true)) { NotificationCompat.Builder b = new NotificationCompat.Builder(appContext); - b.setSmallIcon(R.drawable.message_notification_icon); + b.setSmallIcon(R.drawable.notification_forum); + b.setColor(ContextCompat.getColor(appContext, R.color.briar_primary)); b.setContentTitle(appContext.getText(R.string.app_name)); b.setContentText(appContext.getResources().getQuantityString( R.plurals.forum_post_notification_text, forumTotal, @@ -625,7 +629,8 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager, } else if (settings.getBoolean(PREF_NOTIFY_BLOG, true)) { NotificationCompat.Builder b = new NotificationCompat.Builder(appContext); - b.setSmallIcon(R.drawable.message_notification_icon); + b.setSmallIcon(R.drawable.notification_blog); + b.setColor(ContextCompat.getColor(appContext, R.color.briar_primary)); b.setContentTitle(appContext.getText(R.string.app_name)); b.setContentText(appContext.getResources().getQuantityString( R.plurals.blog_post_notification_text, blogTotal, @@ -685,7 +690,8 @@ class AndroidNotificationManagerImpl implements AndroidNotificationManager, private void updateIntroductionNotification() { NotificationCompat.Builder b = new NotificationCompat.Builder(appContext); - b.setSmallIcon(R.drawable.introduction_notification); + b.setSmallIcon(R.drawable.notification_introduction); + b.setColor(ContextCompat.getColor(appContext, R.color.briar_primary)); b.setContentTitle(appContext.getText(R.string.app_name)); b.setContentText(appContext.getResources().getQuantityString( R.plurals.introduction_notification_text, introductionTotal, diff --git a/briar-android/src/main/java/org/briarproject/briar/android/BriarService.java b/briar-android/src/main/java/org/briarproject/briar/android/BriarService.java index f7eabd5086..e273d393d6 100644 --- a/briar-android/src/main/java/org/briarproject/briar/android/BriarService.java +++ b/briar-android/src/main/java/org/briarproject/briar/android/BriarService.java @@ -10,6 +10,7 @@ import android.os.Binder; import android.os.Build; import android.os.IBinder; import android.support.v4.app.NotificationCompat; +import android.support.v4.content.ContextCompat; import org.briarproject.bramble.api.db.DatabaseConfig; import org.briarproject.bramble.api.lifecycle.LifecycleManager; @@ -75,7 +76,8 @@ public class BriarService extends Service { } // Show an ongoing notification that the service is running NotificationCompat.Builder b = new NotificationCompat.Builder(this); - b.setSmallIcon(R.drawable.ongoing_notification_icon); + b.setSmallIcon(R.drawable.notification_ongoing); + b.setColor(ContextCompat.getColor(this, R.color.briar_primary)); b.setContentTitle(getText(R.string.ongoing_notification_title)); b.setContentText(getText(R.string.ongoing_notification_text)); b.setWhen(0); // Don't show the time diff --git a/briar-android/src/main/res/drawable/introduction_notification.xml b/briar-android/src/main/res/drawable/introduction_notification.xml deleted file mode 100644 index ac4328d121..0000000000 --- a/briar-android/src/main/res/drawable/introduction_notification.xml +++ /dev/null @@ -1,9 +0,0 @@ -<vector xmlns:android="http://schemas.android.com/apk/res/android" - android:width="24dp" - android:height="24dp" - android:viewportWidth="24.0" - android:viewportHeight="24.0"> - <path - android:fillColor="#FFFFFFFF" - android:pathData="M21,8V7l-3,2 -3,-2v1l3,2 3,-2zm1,-5H2C0.9,3 0,3.9 0,5v14c0,1.1 0.9,2 2,2h20c1.1,0 1.99,-0.9 1.99,-2L24,5c0,-1.1 -0.9,-2 -2,-2zM8,6c1.66,0 3,1.34 3,3s-1.34,3 -3,3 -3,-1.34 -3,-3 1.34,-3 3,-3zm6,12H2v-1c0,-2 4,-3.1 6,-3.1s6,1.1 6,3.1v1zm8,-6h-8V6h8v6z"/> -</vector> diff --git a/briar-android/src/main/res/drawable/message_notification_icon.xml b/briar-android/src/main/res/drawable/message_notification_icon.xml deleted file mode 100644 index c300537f64..0000000000 --- a/briar-android/src/main/res/drawable/message_notification_icon.xml +++ /dev/null @@ -1,9 +0,0 @@ -<vector xmlns:android="http://schemas.android.com/apk/res/android" - android:width="24dp" - android:height="24dp" - android:viewportWidth="24.0" - android:viewportHeight="24.0"> - <path - android:fillColor="#FFFFFFFF" - android:pathData="M20,4L4,4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2zM20,8l-8,5 -8,-5L4,6l8,5 8,-5v2z"/> -</vector> diff --git a/briar-android/src/main/res/drawable/notification_blog.xml b/briar-android/src/main/res/drawable/notification_blog.xml new file mode 100644 index 0000000000..d5218f6329 --- /dev/null +++ b/briar-android/src/main/res/drawable/notification_blog.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="utf-8"?> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportHeight="24.0" + android:viewportWidth="24.0"> + <path + android:fillColor="#FFFFFFFF" + android:pathData="M13,12h7v1.5h-7zM13,9.5h7L20,11h-7zM13,14.5h7L20,16h-7zM21,4L3,4c-1.1,0 -2,0.9 -2,2v13c0,1.1 0.9,2 2,2h18c1.1,0 2,-0.9 2,-2L23,6c0,-1.1 -0.9,-2 -2,-2zM21,19h-9L12,6h9v13z"/> +</vector> diff --git a/briar-android/src/main/res/drawable/notification_forum.xml b/briar-android/src/main/res/drawable/notification_forum.xml new file mode 100644 index 0000000000..5bd071e1d6 --- /dev/null +++ b/briar-android/src/main/res/drawable/notification_forum.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="utf-8"?> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportHeight="24.0" + android:viewportWidth="24.0"> + <path + android:fillColor="#FFFFFFFF" + android:pathData="M21,6h-2v9L6,15v2c0,0.55 0.45,1 1,1h11l4,4L22,7c0,-0.55 -0.45,-1 -1,-1zM17,12L17,3c0,-0.55 -0.45,-1 -1,-1L3,2c-0.55,0 -1,0.45 -1,1v14l4,-4h10c0.55,0 1,-0.45 1,-1z"/> +</vector> diff --git a/briar-android/src/main/res/drawable/notification_introduction.xml b/briar-android/src/main/res/drawable/notification_introduction.xml new file mode 100644 index 0000000000..48c8339f02 --- /dev/null +++ b/briar-android/src/main/res/drawable/notification_introduction.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="utf-8"?> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportHeight="24.0" + android:viewportWidth="24.0"> + <path + android:fillColor="#FFFFFFFF" + android:pathData="M20,0L4,0v2h16L20,0zM4,24h16v-2L4,22v2zM20,4L4,4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2zM12,6.75c1.24,0 2.25,1.01 2.25,2.25s-1.01,2.25 -2.25,2.25S9.75,10.24 9.75,9 10.76,6.75 12,6.75zM17,17L7,17v-1.5c0,-1.67 3.33,-2.5 5,-2.5s5,0.83 5,2.5L17,17z"/> +</vector> diff --git a/briar-android/src/main/res/drawable/ongoing_notification_icon.xml b/briar-android/src/main/res/drawable/notification_ongoing.xml similarity index 100% rename from briar-android/src/main/res/drawable/ongoing_notification_icon.xml rename to briar-android/src/main/res/drawable/notification_ongoing.xml diff --git a/briar-android/src/main/res/drawable/notification_private_group.xml b/briar-android/src/main/res/drawable/notification_private_group.xml new file mode 100644 index 0000000000..55cbde9eee --- /dev/null +++ b/briar-android/src/main/res/drawable/notification_private_group.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="utf-8"?> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportHeight="24.0" + android:viewportWidth="24.0"> + <path + android:fillColor="#FFFFFFFF" + android:pathData="M16,11c1.66,0 2.99,-1.34 2.99,-3S17.66,5 16,5c-1.66,0 -3,1.34 -3,3s1.34,3 3,3zM8,11c1.66,0 2.99,-1.34 2.99,-3S9.66,5 8,5C6.34,5 5,6.34 5,8s1.34,3 3,3zM8,13c-2.33,0 -7,1.17 -7,3.5L1,19h14v-2.5c0,-2.33 -4.67,-3.5 -7,-3.5zM16,13c-0.29,0 -0.62,0.02 -0.97,0.05 1.16,0.84 1.97,1.97 1.97,3.45L17,19h6v-2.5c0,-2.33 -4.67,-3.5 -7,-3.5z"/> +</vector> diff --git a/briar-android/src/main/res/drawable/notification_private_message.xml b/briar-android/src/main/res/drawable/notification_private_message.xml new file mode 100644 index 0000000000..49cb74cf2b --- /dev/null +++ b/briar-android/src/main/res/drawable/notification_private_message.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="utf-8"?> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportHeight="24.0" + android:viewportWidth="24.0"> + <path + android:fillColor="#FFFFFFFF" + android:pathData="M20,4L4,4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2zM20,8l-8,5 -8,-5L4,6l8,5 8,-5v2z"/> +</vector> -- GitLab