diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitband5/AmazfitBand5Coordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitband5/AmazfitBand5Coordinator.java index 44b0e7dc4..efd0f5a82 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitband5/AmazfitBand5Coordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/amazfitband5/AmazfitBand5Coordinator.java @@ -87,7 +87,7 @@ public class AmazfitBand5Coordinator extends HuamiCoordinator { @Override public int[] getSupportedDeviceSpecificSettings(GBDevice device) { return new int[]{ - R.xml.devicesettings_miband5, + R.xml.devicesettings_amazfitband5, R.xml.devicesettings_wearlocation, R.xml.devicesettings_custom_emoji_font, R.xml.devicesettings_timeformat, diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java index 91f29b57c..f888974b8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/HuamiSupport.java @@ -48,8 +48,10 @@ import java.util.GregorianCalendar; import java.util.HashSet; import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.Set; import java.util.SimpleTimeZone; +import java.util.SortedMap; import java.util.Timer; import java.util.TimerTask; import java.util.UUID; @@ -2312,6 +2314,51 @@ public class HuamiSupport extends AbstractBTLEDeviceSupport { return this; } + protected HuamiSupport setDisplayItemsNew(TransactionBuilder builder, int defaultSettings, Map keyIdMap) { + if (gbDevice.getFirmwareVersion() == null) { + LOG.warn("Device not initialized yet, won't set menu items"); + return this; + } + + SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()); + Set pages = prefs.getStringSet(HuamiConst.PREF_DISPLAY_ITEMS, new HashSet<>(Arrays.asList(getContext().getResources().getStringArray(defaultSettings)))); + LOG.info("Setting display items to " + (pages == null ? "none" : pages)); + + if (pages != null) { + byte[] command = new byte[keyIdMap.size() * 4 + 1]; + command[0] = 0x1e; + // it seem that we first have to put all ENABLED items into the array + int pos = 1; + int index = 0; + for (Map.Entry entry : keyIdMap.entrySet()) { + String key = entry.getKey(); + int id = entry.getValue(); + + if (pages.contains(key)) { + command[pos++] = (byte) index++; + command[pos++] = 0x00; + command[pos++] = (byte) 0xff; + command[pos++] = (byte) id; + } + } + // And then all DISABLED ones + for (Map.Entry entry : keyIdMap.entrySet()) { + String key = entry.getKey(); + int id = entry.getValue(); + + if (!pages.contains(key)) { + command[pos++] = (byte) index++; + command[pos++] = 0x01; + command[pos++] = (byte) 0xff; + command[pos++] = (byte) id; + } + } + writeToChunked(builder, 2, command); + } + + return this; + } + protected HuamiSupport setShortcuts(TransactionBuilder builder) { return this; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitband5/AmazfitBand5Support.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitband5/AmazfitBand5Support.java index 8342db1ea..9f350c107 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitband5/AmazfitBand5Support.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitband5/AmazfitBand5Support.java @@ -19,13 +19,41 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitband5; import android.content.Context; import android.net.Uri; -import java.io.IOException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.io.IOException; +import java.util.LinkedHashMap; +import java.util.Map; + +import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitband5.AmazfitBand5FWHelper; +import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband5.MiBand5Support; public class AmazfitBand5Support extends MiBand5Support { + private static final Logger LOG = LoggerFactory.getLogger(AmazfitBand5Support.class); + + @Override + protected AmazfitBand5Support setDisplayItems(TransactionBuilder builder) { + Map keyIdMap = new LinkedHashMap<>(); + keyIdMap.put("status", 0x01); + keyIdMap.put("pai", 0x19); + keyIdMap.put("hr", 0x02); + keyIdMap.put("spo2", 0x24); + keyIdMap.put("notifications", 0x06); + keyIdMap.put("breathing", 0x33); + keyIdMap.put("eventreminder", 0x15); + keyIdMap.put("weather", 0x04); + keyIdMap.put("workout", 0x03); + keyIdMap.put("more", 0x07); + keyIdMap.put("stress", 0x1c); + keyIdMap.put("cycles", 0x1d); + + setDisplayItemsNew(builder, R.array.pref_amazfitband5_display_items_default, keyIdMap); + return this; + } @Override public HuamiFWHelper createFWHelper(Uri uri, Context context) throws IOException { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbips/AmazfitBipSSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbips/AmazfitBipSSupport.java index 159f9f883..686a9291f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbips/AmazfitBipSSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitbips/AmazfitBipSSupport.java @@ -28,6 +28,8 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.Arrays; import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.Map; import java.util.Set; import nodomain.freeyourgadget.gadgetbridge.GBApplication; @@ -115,59 +117,22 @@ public class AmazfitBipSSupport extends AmazfitBipSupport { @Override protected AmazfitBipSSupport setDisplayItems(TransactionBuilder builder) { - if (gbDevice.getFirmwareVersion() == null) { - LOG.warn("Device not initialized yet, won't set menu items"); - return this; - } - - SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()); - Set pages = prefs.getStringSet(HuamiConst.PREF_DISPLAY_ITEMS, new HashSet<>(Arrays.asList(getContext().getResources().getStringArray(R.array.pref_bips_display_items_default)))); - LOG.info("Setting display items to " + (pages == null ? "none" : pages)); - byte[] command = new byte[]{ - 0x1E, - 0x00, 0x00, (byte) 0xFF, 0x01, // Status - 0x01, 0x00, (byte) 0xFF, 0x02, // HR - 0x02, 0x00, (byte) 0xFF, 0x19, // PAI - 0x03, 0x00, (byte) 0xFF, 0x03, // Workout - 0x04, 0x00, (byte) 0xFF, 0x11, // Alipay - 0x05, 0x00, (byte) 0xFF, 0x10, // NFC - 0x06, 0x00, (byte) 0xFF, 0x04, // Weather - 0x07, 0x00, (byte) 0xFF, 0x09, // Alarm - 0x08, 0x00, (byte) 0xFF, 0x1B, // Timer - 0x09, 0x00, (byte) 0xFF, 0x16, // Compass - 0x0A, 0x00, (byte) 0xFF, 0x1A, // World clock - 0x0B, 0x00, (byte) 0xFF, 0x0B, // Music - 0x0C, 0x00, (byte) 0xFF, 0x13 // Settings - }; - - String[] keys = {"status", "hr", "pai", "workout", "alipay", "nfc", "weather", "alarm", "timer", "compass", "worldclock", "music", "settings"}; - byte[] ids = {1, 2, 25, 3, 17, 16, 4, 9, 27, 22, 26, 11, 19}; - - if (pages != null) { - // it seem that we first have to put all ENABLED items into the array - int pos = 1; - for (int i = 0; i < keys.length; i++) { - String key = keys[i]; - byte id = ids[i]; - if (pages.contains(key)) { - command[pos + 1] = 0x00; - command[pos + 3] = id; - pos += 4; - } - } - // And then all DISABLED ones - for (int i = 0; i < keys.length; i++) { - String key = keys[i]; - byte id = ids[i]; - if (!pages.contains(key)) { - command[pos + 1] = 0x01; - command[pos + 3] = id; - pos += 4; - } - } - writeToChunked(builder, 2, command); - } + Map keyIdMap = new LinkedHashMap<>(); + keyIdMap.put("status", 0x01); + keyIdMap.put("hr", 0x02); + keyIdMap.put("pai", 0x19); + keyIdMap.put("workout", 0x03); + keyIdMap.put("alipay", 0x11); + keyIdMap.put("nfc", 0x10); + keyIdMap.put("weather", 0x04); + keyIdMap.put("alarm", 0x09); + keyIdMap.put("timer", 0x1b); + keyIdMap.put("compass", 0x16); + keyIdMap.put("worldclock", 0x1a); + keyIdMap.put("music", 0x0b); + keyIdMap.put("settings", 0x13); + setDisplayItemsNew(builder, R.array.pref_bips_display_items_default, keyIdMap); return this; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts/AmazfitGTSSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts/AmazfitGTSSupport.java index b9f09bb3e..1a7ab2a9b 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts/AmazfitGTSSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/amazfitgts/AmazfitGTSSupport.java @@ -17,20 +17,16 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.amazfitgts; import android.content.Context; -import android.content.SharedPreferences; import android.net.Uri; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; +import java.util.LinkedHashMap; +import java.util.Map; -import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; -import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.huami.amazfitgts.AmazfitGTSFWHelper; import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; @@ -70,59 +66,21 @@ public class AmazfitGTSSupport extends AmazfitBipSupport { @Override protected AmazfitGTSSupport setDisplayItems(TransactionBuilder builder) { - if (gbDevice.getFirmwareVersion() == null) { - LOG.warn("Device not initialized yet, won't set menu items"); - return this; - } - - SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()); - Set pages = prefs.getStringSet(HuamiConst.PREF_DISPLAY_ITEMS, new HashSet<>(Arrays.asList(getContext().getResources().getStringArray(R.array.pref_gts_display_items_default)))); - LOG.info("Setting display items to " + (pages == null ? "none" : pages)); - byte[] command = new byte[]{ - 0x1E, - 0x00, 0x00, (byte) 0xFF, 0x01, // Status - 0x01, 0x00, (byte) 0xFF, 0x19, // PAI - 0x02, 0x00, (byte) 0xFF, 0x02, // HR - 0x03, 0x00, (byte) 0xFF, 0x03, // Workout - 0x04, 0x00, (byte) 0xFF, 0x14, // Activities - 0x05, 0x00, (byte) 0xFF, 0x04, // Weather - 0x06, 0x00, (byte) 0xFF, 0x0B, // Music - 0x07, 0x00, (byte) 0xFF, 0x06, // Notifications - 0x08, 0x00, (byte) 0xFF, 0x09, // Alarm - 0x09, 0x00, (byte) 0xFF, 0x15, // Event reminder - 0x0A, 0x00, (byte) 0xFF, 0x07, // More - 0x0B, 0x00, (byte) 0xFF, 0x13 // Settings - }; - - String[] keys = {"status", "pai", "hr", "workout", "activity", "weather", "music", "notifications", "alarm", "eventreminder", "more", "settings"}; - byte[] ids = {1, 25, 2, 3, 20, 4, 11, 6, 9, 21, 7, 19}; - - if (pages != null) { - pages.add("settings"); - // it seem that we first have to put all ENABLED items into the array - int pos = 1; - for (int i = 0; i < keys.length; i++) { - String key = keys[i]; - byte id = ids[i]; - if (pages.contains(key)) { - command[pos + 1] = 0x00; - command[pos + 3] = id; - pos += 4; - } - } - // And then all DISABLED ones - for (int i = 0; i < keys.length; i++) { - String key = keys[i]; - byte id = ids[i]; - if (!pages.contains(key)) { - command[pos + 1] = 0x01; - command[pos + 3] = id; - pos += 4; - } - } - writeToChunked(builder, 2, command); - } + Map keyIdMap = new LinkedHashMap<>(); + keyIdMap.put("status", 0x01); + keyIdMap.put("pai", 0x19); + keyIdMap.put("hr", 0x02); + keyIdMap.put("workout", 0x03); + keyIdMap.put("activity", 0x14); + keyIdMap.put("weather", 0x04); + keyIdMap.put("music", 0x0b); + keyIdMap.put("notifications", 0x06); + keyIdMap.put("alarm", 0x09); + keyIdMap.put("eventreminder", 0x15); + keyIdMap.put("more", 0x07); + keyIdMap.put("settings", 0x13); + setDisplayItemsNew(builder, R.array.pref_gts_display_items_default, keyIdMap); return this; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/miband5/MiBand5Support.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/miband5/MiBand5Support.java index de9bf8ef1..8eb2ee7c8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/miband5/MiBand5Support.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huami/miband5/MiBand5Support.java @@ -17,20 +17,16 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.huami.miband5; import android.content.Context; -import android.content.SharedPreferences; import android.net.Uri; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; +import java.util.LinkedHashMap; +import java.util.Map; -import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; -import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiFWHelper; import nodomain.freeyourgadget.gadgetbridge.devices.huami.miband5.MiBand5FWHelper; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; @@ -41,59 +37,20 @@ public class MiBand5Support extends MiBand4Support { @Override protected MiBand5Support setDisplayItems(TransactionBuilder builder) { - if (gbDevice.getFirmwareVersion() == null) { - LOG.warn("Device not initialized yet, won't set menu items"); - return this; - } - - SharedPreferences prefs = GBApplication.getDeviceSpecificSharedPrefs(gbDevice.getAddress()); - Set pages = prefs.getStringSet(HuamiConst.PREF_DISPLAY_ITEMS, new HashSet<>(Arrays.asList(getContext().getResources().getStringArray(R.array.pref_miband5_display_items_default)))); - LOG.info("Setting display items to " + (pages == null ? "none" : pages)); - byte[] command = new byte[]{ - 0x1E, - 0x00, 0x00, (byte) 0xFF, 0x12, // Display clock? - 0x01, 0x00, (byte) 0xFF, 0x01, // Status - 0x02, 0x00, (byte) 0xFF, 0x19, // PAI - 0x03, 0x00, (byte) 0xFF, 0x02, // HR - 0x04, 0x00, (byte) 0xFF, 0x06, // Notifications - 0x05, 0x00, (byte) 0xFF, 0x33, // Breathing - 0x06, 0x00, (byte) 0xFF, 0x15, // Events - 0x07, 0x00, (byte) 0xFF, 0x04, // Weather - 0x08, 0x00, (byte) 0xFF, 0x03, // Workout - 0x09, 0x00, (byte) 0xFF, 0x07, // More - 0x0A, 0x00, (byte) 0xFF, 0x1c, // Stress - 0x0B, 0x00, (byte) 0xFF, 0x1d // Cycles - }; - - String[] keys = {"displayclock", "status", "pai", "hr", "notifications", "breathing", "eventreminder", "weather", "workout", "more", "stress", "cycles"}; - byte[] ids = {0x12, 0x01, 0x19, 0x02, 0x06, 0x33, 0x15, 0x04, 0x03, 0x07, 0x1c, 0x1d}; - - if (pages != null) { - pages.add("displayclock"); - // it seem that we first have to put all ENABLED items into the array - int pos = 1; - for (int i = 0; i < keys.length; i++) { - String key = keys[i]; - byte id = ids[i]; - if (pages.contains(key)) { - command[pos + 1] = 0x00; - command[pos + 3] = id; - pos += 4; - } - } - // And then all DISABLED ones - for (int i = 0; i < keys.length; i++) { - String key = keys[i]; - byte id = ids[i]; - if (!pages.contains(key)) { - command[pos + 1] = 0x01; - command[pos + 3] = id; - pos += 4; - } - } - writeToChunked(builder, 2, command); - } + Map keyIdMap = new LinkedHashMap<>(); + keyIdMap.put("status", 0x01); + keyIdMap.put("pai", 0x19); + keyIdMap.put("hr", 0x02); + keyIdMap.put("notifications", 0x06); + keyIdMap.put("breathing", 0x33); + keyIdMap.put("eventreminder", 0x15); + keyIdMap.put("weather", 0x04); + keyIdMap.put("workout", 0x03); + keyIdMap.put("more", 0x07); + keyIdMap.put("stress", 0x1c); + keyIdMap.put("cycles", 0x1d); + setDisplayItemsNew(builder, R.array.pref_miband5_display_items_default, keyIdMap); return this; } diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 1619bac8f..c6a426053 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -355,6 +355,51 @@ @string/p_menuitem_cycles + + @string/menuitem_status + @string/menuitem_pai + @string/menuitem_hr + @string/menuitem_spo2 + @string/menuitem_notifications + @string/menuitem_breathing + @string/menuitem_eventreminder + @string/menuitem_weather + @string/menuitem_workout + @string/menuitem_more + @string/menuitem_stress + @string/menuitem_cycles + + + + @string/p_menuitem_status + @string/p_menuitem_pai + @string/p_menuitem_hr + @string/p_menuitem_spo2 + @string/p_menuitem_notifications + @string/p_menuitem_breathing + @string/p_menuitem_eventreminder + @string/p_menuitem_weather + @string/p_menuitem_workout + @string/p_menuitem_more + @string/p_menuitem_stress + @string/p_menuitem_cycles + + + + @string/p_menuitem_status + @string/p_menuitem_pai + @string/p_menuitem_hr + @string/p_menuitem_spo2 + @string/p_menuitem_notifications + @string/p_menuitem_breathing + @string/p_menuitem_eventreminder + @string/p_menuitem_weather + @string/p_menuitem_workout + @string/p_menuitem_more + @string/p_menuitem_stress + @string/p_menuitem_cycles + + @string/menuitem_shortcut_alipay @string/menuitem_shortcut_weather diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8971a2380..7cde1ece4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -828,6 +828,7 @@ Stress PAI Heart Rate + SpO2 Event Reminder Workout Unknown diff --git a/app/src/main/res/values/values.xml b/app/src/main/res/values/values.xml index 4b228a9d0..3709203ff 100644 --- a/app/src/main/res/values/values.xml +++ b/app/src/main/res/values/values.xml @@ -35,6 +35,7 @@ more nfc hr + spo2 pai stress cycles diff --git a/app/src/main/res/xml/devicesettings_amazfitband5.xml b/app/src/main/res/xml/devicesettings_amazfitband5.xml new file mode 100644 index 000000000..25efda5ad --- /dev/null +++ b/app/src/main/res/xml/devicesettings_amazfitband5.xml @@ -0,0 +1,20 @@ + + + + +