From d8145a52f90ea31c8996617fd88a270a31d6dbd9 Mon Sep 17 00:00:00 2001 From: cpfeiffer Date: Sun, 13 Nov 2016 21:33:43 +0100 Subject: [PATCH] Activate the display when lifting the wrist #323 Configurable, defaults to true --- .../devices/miband/MiBand2Coordinator.java | 5 ++++ .../devices/miband/MiBand2Service.java | 3 +++ .../devices/miband/MiBandConst.java | 3 +-- .../miband/MiBandPreferencesActivity.java | 25 ++++++++++++++++++- .../devices/miband/MiBand2Support.java | 15 +++++++++++ app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/miband_preferences.xml | 5 ++++ 7 files changed, 54 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBand2Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBand2Coordinator.java index 94070a19..6cf308f8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBand2Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBand2Coordinator.java @@ -67,4 +67,9 @@ public class MiBand2Coordinator extends MiBandCoordinator { } return DateTimeDisplay.DATE_TIME; } + + public static boolean getActivateDisplayOnLiftWrist() { + Prefs prefs = GBApplication.getPrefs(); + return prefs.getBoolean(MiBandConst.PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT, true); + } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBand2Service.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBand2Service.java index 6f397364..c29451e9 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBand2Service.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBand2Service.java @@ -297,6 +297,9 @@ public class MiBand2Service { public static final byte[] COMMAND_ENABLE_HR_SLEEP_MEASUREMENT = new byte[]{0x15, 0x00, 0x01}; public static final byte[] COMMAND_DISABLE_HR_SLEEP_MEASUREMENT = new byte[]{0x15, 0x00, 0x00}; + public static final byte[] COMMAND_ENABLE_DISPLAY_ON_LIFT_WRIST = new byte[]{0x06, 0x05, 0x00, 0x01}; + public static final byte[] COMMAND_DISABLE_DISPLAY_ON_LIFT_WRIST = new byte[]{0x06, 0x05, 0x00, 0x00}; + static { MIBAND_DEBUG = new HashMap<>(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandConst.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandConst.java index 145f8179..f4d5ec9f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandConst.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandConst.java @@ -18,8 +18,7 @@ public final class MiBandConst { public static final String PREF_MIBAND_USE_HR_FOR_SLEEP_DETECTION = "mi_hr_sleep_detection"; public static final String PREF_MIBAND_DEVICE_TIME_OFFSET_HOURS = "mi_device_time_offset_hours"; public static final String PREF_MI2_DATEFORMAT = "mi2_dateformat"; - - public static final String PREF_TRY_SMS = "mi_try_sms"; + public static final String PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT = "mi2_activate_display_on_lift_wrist"; public static final String ORIGIN_INCOMING_CALL = "incoming_call"; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandPreferencesActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandPreferencesActivity.java index cb289b1c..af1d07a8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandPreferencesActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandPreferencesActivity.java @@ -18,6 +18,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.NotificationType; import nodomain.freeyourgadget.gadgetbridge.util.GB; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.ORIGIN_INCOMING_CALL; +import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MI2_DATEFORMAT; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_ADDRESS; import static nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst.PREF_MIBAND_DEVICE_TIME_OFFSET_HOURS; @@ -45,11 +46,12 @@ public class MiBandPreferencesActivity extends AbstractSettingsActivity { return true; } }); + final Preference setDateFormat = findPreference(PREF_MI2_DATEFORMAT); setDateFormat.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newVal) { - getListView().post(new Runnable() { // delayed execution so that the preferences are applied first + invokeLater(new Runnable() { @Override public void run() { GBApplication.deviceService().onSendConfiguration(PREF_MI2_DATEFORMAT); @@ -58,6 +60,27 @@ public class MiBandPreferencesActivity extends AbstractSettingsActivity { return true; } }); + + final Preference activateDisplayOnLift = findPreference(PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT); + activateDisplayOnLift.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newVal) { + invokeLater(new Runnable() { + @Override + public void run() { + GBApplication.deviceService().onSendConfiguration(PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT); + } + }); + return true; + } + }); + } + + /** + * delayed execution so that the preferences are applied first + */ + private void invokeLater(Runnable runnable) { + getListView().post(runnable); } @Override 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 e8602b76..10e6de68 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 @@ -1168,6 +1168,9 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport { case MiBandConst.PREF_MI2_DATEFORMAT: setDateDisplay(builder); break; + case MiBandConst.PREF_MI2_ACTIVATE_DISPLAY_ON_LIFT: + setActivateDisplayOnLiftWrist(builder); + break; } builder.queue(getQueue()); } catch (IOException e) { @@ -1193,11 +1196,23 @@ public class MiBand2Support extends AbstractBTLEDeviceSupport { return this; } + private MiBand2Support setActivateDisplayOnLiftWrist(TransactionBuilder builder) { + boolean enable = MiBand2Coordinator.getActivateDisplayOnLiftWrist(); + LOG.info("Setting activate display on lift wrist to " + enable); + if (enable) { + builder.write(getCharacteristic(MiBand2Service.UUID_UNKNOWN_CHARACTERISTIC3), MiBand2Service.COMMAND_ENABLE_DISPLAY_ON_LIFT_WRIST); + } else { + builder.write(getCharacteristic(MiBand2Service.UUID_UNKNOWN_CHARACTERISTIC3), MiBand2Service.COMMAND_DISABLE_DISPLAY_ON_LIFT_WRIST); + } + return this; + } + public void phase2Initialize(TransactionBuilder builder) { LOG.info("phase2Initialize..."); enableFurtherNotifications(builder, true); setDateDisplay(builder); setWearLocation(builder); + setActivateDisplayOnLiftWrist(builder); setHeartrateSleepSupport(builder); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7e9e7dd2..7981aa24 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -348,4 +348,5 @@ Mi2: Date Format Time + Activate display upon lift diff --git a/app/src/main/res/xml/miband_preferences.xml b/app/src/main/res/xml/miband_preferences.xml index b2a5c363..6b0e1032 100644 --- a/app/src/main/res/xml/miband_preferences.xml +++ b/app/src/main/res/xml/miband_preferences.xml @@ -43,6 +43,11 @@ android:maxLength="2" android:title="@string/miband_prefs_device_time_offset_hours" /> + +