From 6f162c593b7536c6113a9d5a34092b7e5075e004 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Fri, 8 May 2015 12:50:42 +0200 Subject: [PATCH] Pebble message intent notifications default to "never" now If these get turned on, Conversations notifications will be handled through Pebble message intents and get filtered out from generic notifcation handling. --- .../externalevents/NotificationListener.java | 25 +++++++++++++------ .../externalevents/PebbleReceiver.java | 4 +-- app/src/main/res/xml/preferences.xml | 2 +- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java index 18662c400..feb4dd9b2 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java @@ -48,8 +48,6 @@ public class NotificationListener extends NotificationListenerService { return; } - String source = sbn.getPackageName(); - Log.i(TAG, source); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); if (!sharedPrefs.getBoolean("notifications_generic_whenscreenon", false)) { @@ -59,8 +57,13 @@ public class NotificationListener extends NotificationListenerService { } } + String source = sbn.getPackageName(); Notification notification = sbn.getNotification(); + if ((notification.flags & Notification.FLAG_ONGOING_EVENT) == Notification.FLAG_ONGOING_EVENT) { + return; + } + /* do not display messages from "android" * This includes keyboard selection message, usb connection messages, etc * Hope it does not filter out too much, we will see... @@ -70,13 +73,14 @@ public class NotificationListener extends NotificationListenerService { source.equals("com.android.systemui") || source.equals("com.android.dialer") || source.equals("com.android.mms") || - source.equals("com.fsck.k9") || - source.equals("eu.siacs.conversations")) { + source.equals("com.fsck.k9")) { return; } - if ((notification.flags & Notification.FLAG_ONGOING_EVENT) == Notification.FLAG_ONGOING_EVENT) { - return; + if (source.equals("eu.siacs.conversations")) { + if (!"never".equals(sharedPrefs.getString("notification_mode_pebblemsg", "never"))) { + return; + } } Log.i(TAG, "Processing notification from source " + source); @@ -84,20 +88,25 @@ public class NotificationListener extends NotificationListenerService { Bundle extras = notification.extras; String title = extras.getCharSequence(Notification.EXTRA_TITLE).toString(); String content = null; - if (extras.containsKey(Notification.EXTRA_TEXT)) { + if (extras.containsKey(Notification.EXTRA_TEXT)) + + { CharSequence contentCS = extras.getCharSequence(Notification.EXTRA_TEXT); if (contentCS != null) { content = contentCS.toString(); } } - if (content != null) { + if (content != null) + + { Intent startIntent = new Intent(NotificationListener.this, BluetoothCommunicationService.class); startIntent.setAction(BluetoothCommunicationService.ACTION_NOTIFICATION_GENERIC); startIntent.putExtra("notification_title", title); startIntent.putExtra("notification_body", content); startService(startIntent); } + } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/PebbleReceiver.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/PebbleReceiver.java index fe45002bf..bedef8f6a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/PebbleReceiver.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/PebbleReceiver.java @@ -21,10 +21,10 @@ public class PebbleReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); - if ("never".equals(sharedPrefs.getString("notification_mode_pebblemsg", "when_screen_off"))) { + if ("never".equals(sharedPrefs.getString("notification_mode_pebblemsg", "never"))) { return; } - if ("when_screen_off".equals(sharedPrefs.getString("notification_mode_pebblemsg", "when_screen_off"))) { + if ("when_screen_off".equals(sharedPrefs.getString("notification_mode_pebblemsg", "never"))) { PowerManager powermanager = (PowerManager) context.getSystemService(Context.POWER_SERVICE); if (powermanager.isScreenOn()) { return; diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 7ab3c00aa..1646bdbd9 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -35,7 +35,7 @@ android:title="@string/pref_title_notifications_k9mail" />