From 3b25181a32a1cf21cefa00414bf79fa6695b8347 Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Tue, 15 May 2018 23:12:18 +0200 Subject: [PATCH] Amazfit Bip: allow enabling shortcuts (weather, Alipay) --- .../activities/SettingsActivity.java | 19 +++++++++------ .../devices/amazfitbip/AmazfitBipSupport.java | 24 +++++++++++++++++++ app/src/main/res/values/arrays.xml | 4 ++++ app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/values/values.xml | 2 ++ 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java index fb243cac4..f76f4731f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/SettingsActivity.java @@ -398,13 +398,18 @@ public class SettingsActivity extends AbstractSettingsActivity { try { return AndroidUtils.getFilePath(getApplicationContext(), uri); } catch (IllegalArgumentException e) { - Cursor cursor = getContentResolver().query( - uri, - new String[] { DocumentsContract.Document.COLUMN_DISPLAY_NAME }, - null, null, null, null - ); - if (cursor != null && cursor.moveToFirst()) { - return cursor.getString(cursor.getColumnIndex(DocumentsContract.Document.COLUMN_DISPLAY_NAME)); + try { + Cursor cursor = getContentResolver().query( + uri, + new String[]{DocumentsContract.Document.COLUMN_DISPLAY_NAME}, + null, null, null, null + ); + if (cursor != null && cursor.moveToFirst()) { + return cursor.getString(cursor.getColumnIndex(DocumentsContract.Document.COLUMN_DISPLAY_NAME)); + } + } + catch (Exception fdfsdfds) { + LOG.warn("fuck"); } } return ""; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/amazfitbip/AmazfitBipSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/amazfitbip/AmazfitBipSupport.java index 18174a993..64e08d920 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/amazfitbip/AmazfitBipSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/amazfitbip/AmazfitBipSupport.java @@ -150,6 +150,9 @@ public class AmazfitBipSupport extends MiBand2Support { LOG.info("Setting display items to " + (pages == null ? "none" : pages)); byte[] command = AmazfitBipService.COMMAND_CHANGE_SCREENS.clone(); + boolean shortcut_weather = false; + boolean shortcut_alipay = false; + if (pages != null) { if (pages.contains("status")) { command[1] |= 0x02; @@ -175,11 +178,32 @@ public class AmazfitBipSupport extends MiBand2Support { if (pages.contains("alipay")) { command[2] |= 0x01; } + if (pages.contains("shortcut_weather")) { + shortcut_weather = true; + } + if (pages.contains("shortcut_alipay")) { + shortcut_alipay = true; + } } builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), command); + setShortcuts(builder, shortcut_weather, shortcut_alipay); + return this; } + private void setShortcuts(TransactionBuilder builder, boolean weather, boolean alipay) { + LOG.info("Setting shortcuts: weather=" + weather + " alipay=" + alipay); + + // Basically a hack to put weather first always, if alipay is the only enabled one + // there are actually two alipays set but the second one disabled.... :P + byte[] command = new byte[]{0x10, + (byte) ((alipay || weather) ? 0x80 : 0x00), (byte) (weather ? 0x02 : 0x01), + (byte) ((alipay && weather) ? 0x81 : 0x01), 0x01, + }; + + builder.write(getCharacteristic(MiBand2Service.UUID_CHARACTERISTIC_3_CONFIGURATION), command); + } + @Override public void onSendWeather(WeatherSpec weatherSpec) { if (gbDevice.getFirmwareVersion() == null) { diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index fa9cde984..b1e70e8d7 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -184,6 +184,8 @@ + @string/menuitem_shortcut_alipay + @string/menuitem_shortcut_weather @string/menuitem_status @string/menuitem_activity @string/menuitem_weather @@ -195,6 +197,8 @@ + @string/p_menuitem_shortcut_alipay + @string/p_menuitem_shortcut_weather @string/p_menuitem_status @string/p_menuitem_activity @string/p_menuitem_weather diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c33ddfbad..b90c1ad68 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -558,6 +558,8 @@ Gadgetbridge notifications + Alipay (Shortcut) + Weather (Shortcut) Status Activity Weather diff --git a/app/src/main/res/values/values.xml b/app/src/main/res/values/values.xml index 42a7f2b8f..5e90e5b5f 100644 --- a/app/src/main/res/values/values.xml +++ b/app/src/main/res/values/values.xml @@ -19,6 +19,8 @@ heart_rate battery + shortcut_alipay + shortcut_weather status activity weather