From cd195a59698acfbee3b97db433215a566a71b4b5 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Tue, 11 Oct 2016 11:54:52 +0200 Subject: [PATCH] map more apps to notification types (icons and colors on the pebble) --- .../devices/pebble/PebbleIconID.java | 28 ++++++++++++++----- .../externalevents/K9Receiver.java | 2 +- .../externalevents/NotificationListener.java | 12 +++++--- .../externalevents/PebbleReceiver.java | 5 +++- .../externalevents/SMSReceiver.java | 2 +- .../gadgetbridge/model/NotificationType.java | 9 ++++-- .../service/DeviceCommunicationService.java | 4 +-- .../devices/miband/MiBand2Support.java | 20 +++++++++---- .../service/devices/miband/MiBandSupport.java | 18 +++++------- .../devices/pebble/PebbleProtocol.java | 26 ++++++++++++----- 10 files changed, 83 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleIconID.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleIconID.java index 18b409ae..89069a8c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleIconID.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/pebble/PebbleIconID.java @@ -85,11 +85,25 @@ public final class PebbleIconID { public static final int SETTINGS = 83; public static final int SUNRISE = 84; public static final int SUNSET = 85; - public static final int FACETIME_DISMISSED = 86; - public static final int FACETIME_INCOMING = 87; - public static final int FACETIME_OUTGOING = 88; - public static final int FACETIME_MISSED = 89; - public static final int FACETIME_DURING = 90; - public static final int BLUESCREEN_OF_DEATH = 91; - public static final int START_MUSIC_PHONE = 92; + public static final int RESULT_UNMUTE = 86; + public static final int RESULT_UNMUTE_ALT = 94; + public static final int DURING_PHONE_CALL_CENTERED = 95; + public static final int TIMELINE_EMPTY_CALENDAR = 96; + public static final int THUMBS_UP = 97; + public static final int ARROW_UP = 98; + public static final int ARROW_DOWN = 99; + public static final int ACTIVITY = 100; + public static final int SLEEP = 101; + public static final int REWARD_BAD = 102; + public static final int REWARD_GOOD = 103; + public static final int REWARD_AVERAGE = 104; + public static final int NOTIFICATION_FACETIME = 110; + + // 4.x only from here + public static final int NOTIFICATION_AMAZON = 111; + public static final int NOTIFICATION_GOOGLE_MAPS = 112; + public static final int NOTIFICATION_GOOGLE_PHOTOS = 113; + public static final int NOTIFICATION_IOS_PHOTOS = 114; + public static final int NOTIFICATION_LINKEDIN = 115; + public static final int NOTIFICATION_SLACK = 116; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/K9Receiver.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/K9Receiver.java index 439c34b0..17eb67e9 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/K9Receiver.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/K9Receiver.java @@ -54,7 +54,7 @@ public class K9Receiver extends BroadcastReceiver { NotificationSpec notificationSpec = new NotificationSpec(); notificationSpec.id = -1; - notificationSpec.type = NotificationType.EMAIL; + notificationSpec.type = NotificationType.GENERIC_EMAIL; /* * there seems to be no way to specify the the uri in the where clause. 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 2cefeff1..4c986758 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/NotificationListener.java @@ -257,27 +257,31 @@ public class NotificationListener extends NotificationListenerService { break; case "com.fsck.k9": case "com.android.email": - notificationSpec.type = NotificationType.EMAIL; + notificationSpec.type = NotificationType.GENERIC_EMAIL; break; case "com.moez.QKSMS": case "com.android.mms": case "com.android.messaging": case "com.sonyericsson.conversations": case "org.smssecure.smssecure": - notificationSpec.type = NotificationType.SMS; + notificationSpec.type = NotificationType.GENERIC_SMS; break; case "eu.siacs.conversations": + notificationSpec.type = NotificationType.CONVERSATIONS; + break; case "org.thoughtcrime.securesms": - notificationSpec.type = NotificationType.CHAT; + notificationSpec.type = NotificationType.SIGNAL; break; case "org.telegram.messenger": notificationSpec.type = NotificationType.TELEGRAM; break; - case "com.facebook.orca": case "com.facebook.katana": case "org.indywidualni.fblite": notificationSpec.type = NotificationType.FACEBOOK; break; + case "com.facebook.orca": + notificationSpec.type = NotificationType.FACEBOOK_MESSENGER; + break; default: notificationSpec.type = NotificationType.UNKNOWN; break; 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 06790cfd..723f5c4a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/PebbleReceiver.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/PebbleReceiver.java @@ -61,7 +61,10 @@ public class PebbleReceiver extends BroadcastReceiver { notificationSpec.type = NotificationType.UNKNOWN; String sender = intent.getStringExtra("sender"); if ("Conversations".equals(sender)) { - notificationSpec.type = NotificationType.CHAT; + notificationSpec.type = NotificationType.CONVERSATIONS; + } + else if ("OsmAnd".equals(sender)) { + notificationSpec.type = NotificationType.GENERIC_NAVIGATION; } GBApplication.deviceService().onNotification(notificationSpec); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/SMSReceiver.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/SMSReceiver.java index 5df07c8d..62e66a26 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/SMSReceiver.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/SMSReceiver.java @@ -31,7 +31,7 @@ public class SMSReceiver extends BroadcastReceiver { NotificationSpec notificationSpec = new NotificationSpec(); notificationSpec.id = -1; - notificationSpec.type = NotificationType.SMS; + notificationSpec.type = NotificationType.GENERIC_SMS; Bundle bundle = intent.getExtras(); if (bundle != null) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/NotificationType.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/NotificationType.java index b17f0dc0..5f7577a1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/NotificationType.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/NotificationType.java @@ -4,10 +4,13 @@ public enum NotificationType { UNKNOWN, - CHAT, - EMAIL, + CONVERSATIONS, + GENERIC_EMAIL, + GENERIC_NAVIGATION, + GENERIC_SMS, FACEBOOK, - SMS, + FACEBOOK_MESSENGER, + SIGNAL, TWITTER, TELEGRAM; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java index aa2c7c47..333c7f6a 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationService.java @@ -310,14 +310,14 @@ public class DeviceCommunicationService extends Service implements SharedPrefere notificationSpec.id = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1); notificationSpec.flags = intent.getIntExtra(EXTRA_NOTIFICATION_FLAGS, 0); notificationSpec.sourceName = intent.getStringExtra(EXTRA_NOTIFICATION_SOURCENAME); - if (notificationSpec.type == NotificationType.SMS && notificationSpec.phoneNumber != null) { + if (notificationSpec.type == NotificationType.GENERIC_SMS && notificationSpec.phoneNumber != null) { notificationSpec.sender = getContactDisplayNameByNumber(notificationSpec.phoneNumber); notificationSpec.id = mRandom.nextInt(); // FIXME: add this in external SMS Receiver? GBApplication.getIDSenderLookup().add(notificationSpec.id, notificationSpec.phoneNumber); } if (((notificationSpec.flags & NotificationSpec.FLAG_WEARABLE_REPLY) > 0) - || (notificationSpec.type == NotificationType.SMS && notificationSpec.phoneNumber != null)) { + || (notificationSpec.type == NotificationType.GENERIC_SMS && notificationSpec.phoneNumber != null)) { // NOTE: maybe not where it belongs if (prefs.getBoolean("pebble_force_untested", false)) { // I would rather like to save that as an array in ShadredPreferences diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBand2Support.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBand2Support.java index 5e81c090..5f240ef1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBand2Support.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBand2Support.java @@ -554,11 +554,15 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport { String task; int alertLevel; switch (notificationSpec.type) { - case SMS: + case CONVERSATIONS: + task = "conversations message received"; + alertLevel = MiBand2Service.ALERT_LEVEL_MESSAGE; + break; + case GENERIC_SMS: task = "sms received"; alertLevel = MiBand2Service.ALERT_LEVEL_MESSAGE; break; - case EMAIL: + case GENERIC_EMAIL: task = "email received"; alertLevel = MiBand2Service.ALERT_LEVEL_MESSAGE; break; @@ -566,6 +570,14 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport { task = "facebook message received"; alertLevel = MiBand2Service.ALERT_LEVEL_MESSAGE; break; + case FACEBOOK_MESSENGER: + task = "facebook messenger message received"; + alertLevel = MiBand2Service.ALERT_LEVEL_MESSAGE; + break; + case SIGNAL: + task = "signal message received"; + alertLevel = MiBand2Service.ALERT_LEVEL_MESSAGE; + break; case TWITTER: task = "twitter message received"; alertLevel = MiBand2Service.ALERT_LEVEL_MESSAGE; @@ -574,10 +586,6 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport { task = "telegram message received"; alertLevel = MiBand2Service.ALERT_LEVEL_MESSAGE; break; - case CHAT: - task = "chat message received"; - alertLevel = MiBand2Service.ALERT_LEVEL_MESSAGE; - break; case UNKNOWN: default: task = "generic notification received"; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java index 5e2bdc62..ce11b0f4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband/MiBandSupport.java @@ -536,22 +536,18 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport { public void onNotification(NotificationSpec notificationSpec) { String origin = notificationSpec.type.getFixedValue(); switch (notificationSpec.type) { - case SMS: + case GENERIC_SMS: performPreferredNotification("sms received", origin, null); break; - case EMAIL: + case GENERIC_EMAIL: performPreferredNotification("email received", origin, null); break; - case CHAT: - performPreferredNotification("chat message received", origin, null); - break; - case TELEGRAM: - performPreferredNotification("chat message received", origin, null); - break; - case TWITTER: - performPreferredNotification("chat message received", origin, null); - break; + case CONVERSATIONS: case FACEBOOK: + case FACEBOOK_MESSENGER: + case SIGNAL: + case TELEGRAM: + case TWITTER: performPreferredNotification("chat message received", origin, null); break; case UNKNOWN: diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java index a4ab599d..a2a7e73f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/pebble/PebbleProtocol.java @@ -464,7 +464,7 @@ public class PebbleProtocol extends GBDeviceProtocol { if (mFwMajor >= 3) { // 3.x notification return encodeBlobdbNotification(id, (int) (ts & 0xffffffffL), title, subtitle, notificationSpec.body, notificationSpec.sourceName, hasHandle, notificationSpec.type, notificationSpec.cannedReplies); - } else if (mForceProtocol || notificationSpec.type != NotificationType.EMAIL) { + } else if (mForceProtocol || notificationSpec.type != NotificationType.GENERIC_EMAIL) { // 2.x notification return encodeExtensibleNotification(id, (int) (ts & 0xffffffffL), title, subtitle, notificationSpec.body, notificationSpec.sourceName, hasHandle, notificationSpec.cannedReplies); } else { @@ -834,11 +834,19 @@ public class PebbleProtocol extends GBDeviceProtocol { int icon_id; byte color_id; switch (notificationType) { - case EMAIL: + case CONVERSATIONS: + icon_id = PebbleIconID.NOTIFICATION_HIPCHAT; + color_id = PebbleColor.Inchworm; + break; + case GENERIC_EMAIL: icon_id = PebbleIconID.GENERIC_EMAIL; color_id = PebbleColor.JaegerGreen; break; - case SMS: + case GENERIC_NAVIGATION: + icon_id = mFwMajor >= 4 ? PebbleIconID.NOTIFICATION_GOOGLE_MAPS : PebbleIconID.LOCATION; + color_id = PebbleColor.Orange; + break; + case GENERIC_SMS: icon_id = PebbleIconID.GENERIC_SMS; color_id = PebbleColor.VividViolet; break; @@ -848,16 +856,20 @@ public class PebbleProtocol extends GBDeviceProtocol { break; case FACEBOOK: icon_id = PebbleIconID.NOTIFICATION_FACEBOOK; - color_id = PebbleColor.VeryLightBlue; + color_id = PebbleColor.Liberty; break; - case CHAT: - icon_id = PebbleIconID.NOTIFICATION_HIPCHAT; - color_id = PebbleColor.Inchworm; + case FACEBOOK_MESSENGER: + icon_id = PebbleIconID.NOTIFICATION_FACEBOOK_MESSENGER; + color_id = PebbleColor.VeryLightBlue; break; case TELEGRAM: icon_id = PebbleIconID.NOTIFICATION_TELEGRAM; color_id = PebbleColor.PictonBlue; break; + case SIGNAL: + icon_id = PebbleIconID.NOTIFICATION_HIPCHAT; + color_id = PebbleColor.BlueMoon; + break; default: icon_id = PebbleIconID.NOTIFICATION_GENERIC; color_id = PebbleColor.Red;