From a784f30db9806ff17d586c8bdea54d26da65f12d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Rebelo?= Date: Thu, 21 Sep 2017 19:28:05 +0100 Subject: [PATCH] Mi Band 2: Vibrate-only notifications, find lost device while in DND --- .../profiles/alertnotification/AlertCategory.java | 1 + .../devices/miband2/Mi2NotificationStrategy.java | 12 ++++++++++++ .../devices/miband2/Mi2TextNotificationStrategy.java | 6 +++++- .../service/devices/miband2/MiBand2Support.java | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/profiles/alertnotification/AlertCategory.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/profiles/alertnotification/AlertCategory.java index 4a896f4118..9df1ade572 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/profiles/alertnotification/AlertCategory.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/btle/profiles/alertnotification/AlertCategory.java @@ -38,6 +38,7 @@ public enum AlertCategory { // 251-255 defined by service specification Any(255), Custom(-1), + CustomVibrateOnly(-2), CustomMiBand2(-6); private final int id; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/Mi2NotificationStrategy.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/Mi2NotificationStrategy.java index 4ec7471f18..e7786531d3 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/Mi2NotificationStrategy.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/Mi2NotificationStrategy.java @@ -19,10 +19,12 @@ import android.bluetooth.BluetoothGattCharacteristic; import android.support.annotation.Nullable; +import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBand2Service; import nodomain.freeyourgadget.gadgetbridge.devices.miband.VibrationProfile; import nodomain.freeyourgadget.gadgetbridge.service.btle.BtLEAction; import nodomain.freeyourgadget.gadgetbridge.service.btle.GattCharacteristic; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; +import nodomain.freeyourgadget.gadgetbridge.service.btle.profiles.alertnotification.AlertCategory; import nodomain.freeyourgadget.gadgetbridge.service.devices.common.SimpleNotification; import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.V2NotificationStrategy; @@ -35,6 +37,16 @@ public Mi2NotificationStrategy(MiBand2Support support) { alertLevelCharacteristic = support.getCharacteristic(GattCharacteristic.UUID_CHARACTERISTIC_ALERT_LEVEL); } + @Override + public void sendDefaultNotification(TransactionBuilder builder, SimpleNotification simpleNotification, BtLEAction extraAction) { + VibrationProfile profile = VibrationProfile.getProfile(VibrationProfile.ID_MEDIUM, (short) 3); + if (simpleNotification.getAlertCategory() == AlertCategory.CustomVibrateOnly) { + profile.setAlertLevel(MiBand2Service.ALERT_LEVEL_VIBRATE_ONLY); + } + sendCustomNotification(profile, simpleNotification, extraAction, builder); + } + + @Override protected void sendCustomNotification(VibrationProfile vibrationProfile, SimpleNotification simpleNotification, BtLEAction extraAction, TransactionBuilder builder) { for (short i = 0; i < vibrationProfile.getRepeat(); i++) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/Mi2TextNotificationStrategy.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/Mi2TextNotificationStrategy.java index 3affdd36dd..a12f65c4b5 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/Mi2TextNotificationStrategy.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/Mi2TextNotificationStrategy.java @@ -59,7 +59,11 @@ protected void sendCustomNotification(VibrationProfile vibrationProfile, SimpleN @Override protected void startNotify(TransactionBuilder builder, int alertLevel, SimpleNotification simpleNotification) { - builder.write(newAlertCharacteristic, getNotifyMessage(simpleNotification)); + if (alertLevel == MiBand2Service.ALERT_LEVEL_VIBRATE_ONLY) { + super.startNotify(builder, alertLevel, simpleNotification); + } else { + builder.write(newAlertCharacteristic, getNotifyMessage(simpleNotification)); + } } protected byte[] getNotifyMessage(SimpleNotification simpleNotification) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/MiBand2Support.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/MiBand2Support.java index 570137782e..ccb2e73437 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/MiBand2Support.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/miband2/MiBand2Support.java @@ -729,7 +729,7 @@ protected boolean shouldAbort() { return !isLocatingDevice; } }; - SimpleNotification simpleNotification = new SimpleNotification(getContext().getString(R.string.find_device_you_found_it), AlertCategory.HighPriorityAlert); + SimpleNotification simpleNotification = new SimpleNotification(getContext().getString(R.string.find_device_you_found_it), AlertCategory.CustomVibrateOnly); performDefaultNotification("locating device", simpleNotification, (short) 255, abortAction); } }