From 1a5ebe2ee711fc2661bbd12c7f090bb7245bbc26 Mon Sep 17 00:00:00 2001 From: Arjan Schrijver Date: Fri, 12 Nov 2021 15:34:57 +0100 Subject: [PATCH] Support multiple 2nd-TZ and Custom widgets --- .../{widgetCustom0.bin => widgetCustom.bin} | Bin .../main/assets/fossil_hr/widgetCustom1.bin | Bin 508 -> 0 bytes .../main/assets/fossil_hr/widgetCustom2.bin | Bin 508 -> 0 bytes .../main/assets/fossil_hr/widgetCustom3.bin | Bin 508 -> 0 bytes .../HybridHRWatchfaceDesignerActivity.java | 6 +- .../qhybrid/HybridHRWatchfaceFactory.java | 89 ++++++++++-------- .../qhybrid/HybridHRWatchfaceWidget.java | 5 +- .../fossil_hr/FossilHRWatchAdapter.java | 7 -- app/src/main/res/values/strings.xml | 5 +- external/build_fossil_hr_watchface.sh | 5 +- 10 files changed, 58 insertions(+), 59 deletions(-) rename app/src/main/assets/fossil_hr/{widgetCustom0.bin => widgetCustom.bin} (100%) delete mode 100644 app/src/main/assets/fossil_hr/widgetCustom1.bin delete mode 100644 app/src/main/assets/fossil_hr/widgetCustom2.bin delete mode 100644 app/src/main/assets/fossil_hr/widgetCustom3.bin diff --git a/app/src/main/assets/fossil_hr/widgetCustom0.bin b/app/src/main/assets/fossil_hr/widgetCustom.bin similarity index 100% rename from app/src/main/assets/fossil_hr/widgetCustom0.bin rename to app/src/main/assets/fossil_hr/widgetCustom.bin diff --git a/app/src/main/assets/fossil_hr/widgetCustom1.bin b/app/src/main/assets/fossil_hr/widgetCustom1.bin deleted file mode 100644 index 12acd2a53124600473cb2bf576df2b796db0e3c6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 508 zcmYjOJ#WG=5Pc3N&KIhn3|SbMphHK<(zR{Wk*S>`D={HeNFp$z{G$Ghc7uP?ztM9O ziAH|*yYt<>7x`tidJEBha|Y0YiG5;ISj4sX9DFDq z`g8VWxIG<3V&Oz?I&q13k)L+APvpAQVT^g6@n-(v)1#R_X$DsvF=%z}z{Zy)SY#RJ zk-ZRMpLRENE;J2rQPr7BD!Ek@*+}bZUF04PO`~>+Rv((-o>a^F*u^&}d+Cp0V0$Dm^!vFvP diff --git a/app/src/main/assets/fossil_hr/widgetCustom2.bin b/app/src/main/assets/fossil_hr/widgetCustom2.bin deleted file mode 100644 index 12acd2a53124600473cb2bf576df2b796db0e3c6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 508 zcmYjOJ#WG=5Pc3N&KIhn3|SbMphHK<(zR{Wk*S>`D={HeNFp$z{G$Ghc7uP?ztM9O ziAH|*yYt<>7x`tidJEBha|Y0YiG5;ISj4sX9DFDq z`g8VWxIG<3V&Oz?I&q13k)L+APvpAQVT^g6@n-(v)1#R_X$DsvF=%z}z{Zy)SY#RJ zk-ZRMpLRENE;J2rQPr7BD!Ek@*+}bZUF04PO`~>+Rv((-o>a^F*u^&}d+Cp0V0$Dm^!vFvP diff --git a/app/src/main/assets/fossil_hr/widgetCustom3.bin b/app/src/main/assets/fossil_hr/widgetCustom3.bin deleted file mode 100644 index 12acd2a53124600473cb2bf576df2b796db0e3c6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 508 zcmYjOJ#WG=5Pc3N&KIhn3|SbMphHK<(zR{Wk*S>`D={HeNFp$z{G$Ghc7uP?ztM9O ziAH|*yYt<>7x`tidJEBha|Y0YiG5;ISj4sX9DFDq z`g8VWxIG<3V&Oz?I&q13k)L+APvpAQVT^g6@n-(v)1#R_X$DsvF=%z}z{Zy)SY#RJ zk-ZRMpLRENE;J2rQPr7BD!Ek@*+}bZUF04PO`~>+Rv((-o>a^F*u^&}d+Cp0V0$Dm^!vFvP diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceDesignerActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceDesignerActivity.java index 244841a12..d57a8d657 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceDesignerActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceDesignerActivity.java @@ -376,14 +376,18 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem widgetName = "widget2ndTZ"; break; } - if (widgetName.equals("widget2ndTZ")) { + if (widgetName.startsWith("widget2ndTZ")) { try { + widgetName = "widget2ndTZ"; JSONObject widgetData = layoutItem.getJSONObject("data"); widgetTimezone = widgetData.getString("tzName"); } catch (JSONException e) { LOG.error("Couldn't determine tzName!", e); } } + if (widgetName.startsWith("widgetCustom")) { + widgetName = "widgetCustom"; + } int widgetColor = layoutItem.getString("color").equals("white") ? HybridHRWatchfaceWidget.COLOR_WHITE : HybridHRWatchfaceWidget.COLOR_BLACK; widgets.add(new HybridHRWatchfaceWidget(widgetName, layoutItem.getJSONObject("pos").getInt("x"), diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceFactory.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceFactory.java index e4b87efc2..c21f2106e 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceFactory.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceFactory.java @@ -71,10 +71,7 @@ public class HybridHRWatchfaceFactory { case "widgetCalories": case "widgetActiveMins": case "widgetChanceOfRain": - case "widgetCustom0": - case "widgetCustom1": - case "widgetCustom2": - case "widgetCustom3": + case "widgetCustom": widget.put("type", "comp"); widget.put("name", widgetDesc.getWidgetType()); widget.put("goal_ring", false); @@ -120,16 +117,17 @@ public class HybridHRWatchfaceFactory { } } - private boolean includeWidget(String name) { + private int includeWidget(String name) { + int count = 0; for (JSONObject widget : this.widgets) { try { if (widget.get("name").equals(name)) { - return true; + count++; } } catch (JSONException e) { } } - return false; + return count; } public byte[] getWapp(Context context) throws IOException { @@ -138,19 +136,20 @@ public class HybridHRWatchfaceFactory { LinkedHashMap code = new LinkedHashMap<>(); try { code.put(watchfaceName, context.getAssets().open("fossil_hr/openSourceWatchface.bin")); - if (includeWidget("widgetDate")) code.put("widgetDate", context.getAssets().open("fossil_hr/widgetDate.bin")); - if (includeWidget("widgetWeather")) code.put("widgetWeather", context.getAssets().open("fossil_hr/widgetWeather.bin")); - if (includeWidget("widgetSteps")) code.put("widgetSteps", context.getAssets().open("fossil_hr/widgetSteps.bin")); - if (includeWidget("widgetHR")) code.put("widgetHR", context.getAssets().open("fossil_hr/widgetHR.bin")); - if (includeWidget("widgetBattery")) code.put("widgetBattery", context.getAssets().open("fossil_hr/widgetBattery.bin")); - if (includeWidget("widgetCalories")) code.put("widgetCalories", context.getAssets().open("fossil_hr/widgetCalories.bin")); - if (includeWidget("widgetActiveMins")) code.put("widgetActiveMins", context.getAssets().open("fossil_hr/widgetActiveMins.bin")); - if (includeWidget("widgetChanceOfRain")) code.put("widgetChanceOfRain", context.getAssets().open("fossil_hr/widgetChanceOfRain.bin")); - if (includeWidget("widget2ndTZ")) code.put("widget2ndTZ", context.getAssets().open("fossil_hr/widget2ndTZ.bin")); - if (includeWidget("widgetCustom0")) code.put("widgetCustom0", context.getAssets().open("fossil_hr/widgetCustom0.bin")); - if (includeWidget("widgetCustom1")) code.put("widgetCustom1", context.getAssets().open("fossil_hr/widgetCustom1.bin")); - if (includeWidget("widgetCustom2")) code.put("widgetCustom2", context.getAssets().open("fossil_hr/widgetCustom2.bin")); - if (includeWidget("widgetCustom3")) code.put("widgetCustom3", context.getAssets().open("fossil_hr/widgetCustom3.bin")); + if (includeWidget("widgetDate") > 0) code.put("widgetDate", context.getAssets().open("fossil_hr/widgetDate.bin")); + if (includeWidget("widgetWeather") > 0) code.put("widgetWeather", context.getAssets().open("fossil_hr/widgetWeather.bin")); + if (includeWidget("widgetSteps") > 0) code.put("widgetSteps", context.getAssets().open("fossil_hr/widgetSteps.bin")); + if (includeWidget("widgetHR") > 0) code.put("widgetHR", context.getAssets().open("fossil_hr/widgetHR.bin")); + if (includeWidget("widgetBattery") > 0) code.put("widgetBattery", context.getAssets().open("fossil_hr/widgetBattery.bin")); + if (includeWidget("widgetCalories") > 0) code.put("widgetCalories", context.getAssets().open("fossil_hr/widgetCalories.bin")); + if (includeWidget("widgetActiveMins") > 0) code.put("widgetActiveMins", context.getAssets().open("fossil_hr/widgetActiveMins.bin")); + if (includeWidget("widgetChanceOfRain") > 0) code.put("widgetChanceOfRain", context.getAssets().open("fossil_hr/widgetChanceOfRain.bin")); + for (int i=0; i 0) icons.put("icWthClearDay", context.getAssets().open("fossil_hr/icWthClearDay.rle")); + if (includeWidget("widgetWeather") > 0) icons.put("icWthClearNite", context.getAssets().open("fossil_hr/icWthClearNite.rle")); + if (includeWidget("widgetWeather") > 0) icons.put("icWthCloudy", context.getAssets().open("fossil_hr/icWthCloudy.rle")); + if (includeWidget("widgetWeather") > 0) icons.put("icWthPartCloudyDay", context.getAssets().open("fossil_hr/icWthPartCloudyDay.rle")); + if (includeWidget("widgetWeather") > 0) icons.put("icWthPartCloudyNite", context.getAssets().open("fossil_hr/icWthPartCloudyNite.rle")); + if (includeWidget("widgetWeather") > 0) icons.put("icWthRainy", context.getAssets().open("fossil_hr/icWthRainy.rle")); + if (includeWidget("widgetWeather") > 0) icons.put("icWthSnowy", context.getAssets().open("fossil_hr/icWthSnowy.rle")); + if (includeWidget("widgetWeather") > 0) icons.put("icWthStormy", context.getAssets().open("fossil_hr/icWthStormy.rle")); + if (includeWidget("widgetWeather") > 0) icons.put("icWthWindy", context.getAssets().open("fossil_hr/icWthWindy.rle")); + if (includeWidget("widgetSteps") > 0) icons.put("icSteps", context.getAssets().open("fossil_hr/icSteps.rle")); + if (includeWidget("widgetHR") > 0) icons.put("icHeart", context.getAssets().open("fossil_hr/icHeart.rle")); + if (includeWidget("widgetBattery") > 0) icons.put("icBattCharging", context.getAssets().open("fossil_hr/icBattCharging.rle")); + if (includeWidget("widgetBattery") > 0) icons.put("icBattEmpty", context.getAssets().open("fossil_hr/icBattEmpty.rle")); + if (includeWidget("widgetBattery") > 0) icons.put("icBattery", context.getAssets().open("fossil_hr/icBattery.rle")); + if (includeWidget("widgetCalories") > 0) icons.put("icCalories", context.getAssets().open("fossil_hr/icCalories.rle")); + if (includeWidget("widgetActiveMins") > 0) icons.put("icActiveMins", context.getAssets().open("fossil_hr/icActiveMins.rle")); + if (includeWidget("widgetChanceOfRain") > 0) icons.put("icRainChance", context.getAssets().open("fossil_hr/icRainChance.rle")); } catch (IOException e) { LOG.warn("Unable to read asset file", e); } @@ -190,7 +189,7 @@ public class HybridHRWatchfaceFactory { LOG.warn("Could not generate image_layout", e); } try { - if (includeWidget("widgetBattery")) layout.put("battery_layout", getBatteryLayout()); + if (includeWidget("widgetBattery") > 0) layout.put("battery_layout", getBatteryLayout()); } catch (JSONException e) { LOG.warn("Could not generate battery_layout", e); } @@ -401,8 +400,20 @@ public class HybridHRWatchfaceFactory { pos.put("y", 120); background.put("pos", pos); layout.put(background); + int count_widget2ndTZ = 0; + int count_widgetCustom = 0; for (JSONObject widget : widgets) { - layout.put(widget); + if (widget.get("name").equals("widget2ndTZ")) { + widget.put("name", "widget2ndTZ" + count_widget2ndTZ); + layout.put(widget); + count_widget2ndTZ++; + } else if (widget.get("name").equals("widgetCustom")) { + widget.put("name", "widgetCustom" + count_widgetCustom); + layout.put(widget); + count_widgetCustom++; + } else { + layout.put(widget); + } } configuration.put("layout", layout); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceWidget.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceWidget.java index f0351404b..f5efaea91 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceWidget.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/HybridHRWatchfaceWidget.java @@ -59,10 +59,7 @@ public class HybridHRWatchfaceWidget { widgetTypes.put("widgetCalories", context.getString(R.string.watchface_widget_type_calories)); widgetTypes.put("widget2ndTZ", context.getString(R.string.watchface_widget_type_2nd_tz)); widgetTypes.put("widgetActiveMins", context.getString(R.string.watchface_widget_type_active_mins)); - widgetTypes.put("widgetCustom0", context.getString(R.string.watchface_widget_type_custom_0)); - widgetTypes.put("widgetCustom1", context.getString(R.string.watchface_widget_type_custom_1)); - widgetTypes.put("widgetCustom2", context.getString(R.string.watchface_widget_type_custom_2)); - widgetTypes.put("widgetCustom3", context.getString(R.string.watchface_widget_type_custom_3)); + widgetTypes.put("widgetCustom", context.getString(R.string.watchface_widget_type_custom)); // widgetTypes.put("widgetChanceOfRain", context.getString(R.string.watchface_widget_type_chance_rain)); // Disabled due to missing support in Gadgetbridge return widgetTypes; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java index 993b4b893..7a756713f 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/adapter/fossil_hr/FossilHRWatchAdapter.java @@ -1234,13 +1234,6 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter { .put("widgetCustom1._.config.upper_text", "1 up") .put("widgetCustom1._.config.lower_text", "1 low") - - .put("widgetCustom2._.config.upper_text", "2 up") - .put("widgetCustom2._.config.lower_text", "2 low") - - .put("widgetCustom3._.config.upper_text", "3 up") - .put("widgetCustom3._.config.lower_text", "3 low") - ) ); queueWrite(new JsonPutRequest(data, this)); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d3320de37..8e798c231 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1376,9 +1376,6 @@ 30 minutes 1 hour 3 hours - Custom widget 0 - Custom widget 1 - Custom widget 2 - Custom widget 3 + Custom widget diff --git a/external/build_fossil_hr_watchface.sh b/external/build_fossil_hr_watchface.sh index fa5047afb..5be14b9bd 100755 --- a/external/build_fossil_hr_watchface.sh +++ b/external/build_fossil_hr_watchface.sh @@ -14,9 +14,6 @@ $jerry generate -f '' widget_calories.js -o widgetCalories.bin $jerry generate -f '' widget_2nd_tz.js -o widget2ndTZ.bin $jerry generate -f '' widget_activemins.js -o widgetActiveMins.bin $jerry generate -f '' widget_chanceofrain.js -o widgetChanceOfRain.bin -$jerry generate -f '' widget_custom.js -o widgetCustom0.bin -cp widgetCustom0.bin widgetCustom1.bin -cp widgetCustom0.bin widgetCustom2.bin -cp widgetCustom0.bin widgetCustom3.bin +$jerry generate -f '' widget_custom.js -o widgetCustom.bin popd mv fossil-hr-watchface/*.bin ../app/src/main/assets/fossil_hr/