From 2e3c409e02dbbe472073a05904069b23823a2782 Mon Sep 17 00:00:00 2001 From: Arjan Schrijver Date: Sun, 8 Aug 2021 22:47:25 +0200 Subject: [PATCH] Fossil Hybrid HR: Add timezone selector for 2nd TZ widget --- .../assets/fossil_hr/openSourceWatchface.bin | Bin 3160 -> 3210 bytes app/src/main/assets/fossil_hr/widget2ndTZ.bin | Bin 1872 -> 1880 bytes .../HybridHRWatchfaceDesignerActivity.java | 55 ++++++++++++++++-- .../qhybrid/HybridHRWatchfaceFactory.java | 16 +++++ .../qhybrid/HybridHRWatchfaceWidget.java | 12 +++- .../dialog_hybridhr_watchface_widget.xml | 17 +++++- external/fossil-hr-watchface | 2 +- 7 files changed, 94 insertions(+), 8 deletions(-) diff --git a/app/src/main/assets/fossil_hr/openSourceWatchface.bin b/app/src/main/assets/fossil_hr/openSourceWatchface.bin index eeaa332bc96c51bd8642c2014068d598910d1f77..32b54f2e2b9c985717d2a18d86a8a789b253aa48 100644 GIT binary patch delta 788 zcmX|9O>YuW6uocw7@k035XwNcQrdB5tfX!14AK&bca+3V4 zy;X?5go*w|h~7tu{+^s3Bvy#g0>vrJOQrr*w!RZA5vc~zPzAu|Wv~g(5{VpiLbV%i=%m7;3)}e}yI-`8Sd&azx>=?8_Y*hiu9j z1#8w=u<~8Qwsd37Di}4Z_>6C{=A)25r$w#MuM4a`)fd?+^!&unv!$u8GkvNHEHTxW zh<6&)m<%nVgkzOTfNxhTm;>OiU{E5UZ2J9)`decu+@O3N<%?o6uNkFAX2-m5UI$K{51+b^R^Ga*;U0 zyoK6r@D9A&;5(=XCcPVY2k<;F&hpCe0r?GP6ES{@08Hp9@7ROy;};U}gw%JD2L#~n z64|6?t1-R589AL7h{Ybx!##p~&_Hk>b%;f?UyL4?1;R!;0->&Eg@jO~_7CzK9GfVXj?TGfX70Un$6w2rc7E^h@THCaU*{zM-Flk> zzUjcF0UV`)KPTsJa?21{Ko+`LsYG?r_@E?kx(G;zyadz=z^DiWC3-H|V{8&xf;yN2 z+Gg_#j91Vv64}IsI1>7N#xq1S`_t0JdQ0Tq<*kO7PK&_R&S~$vcJ3x%^xtI zGmZIPx4y&-AIFw6MpzuMJBgH(8j6dAyTMYbP0rkd qVzs0N&L?;h{Y`IGYfpKSP=x=Cn$@p!TS%>9bOtSXoEn^&!_+@}*@LeD diff --git a/app/src/main/assets/fossil_hr/widget2ndTZ.bin b/app/src/main/assets/fossil_hr/widget2ndTZ.bin index bed2417d25edd990dde171baeb338d65b4de7b47..1aa07387ebeeff23a8efdc4bfcdd324b0aefb2f7 100644 GIT binary patch delta 463 zcmYk2xk|)P6hLpxjL(J1%(yG!hGX0s3rj((w2B`P1`T1rBu%VGut+5+`2foxmSS(0 z)<&=q!N%G@@Z2zh4-R*EcYk%>o!jFBGb|Dsk?#?aaumj}$FadQL|jMY>cN({9&E3k^6vAs2PMlbR=>;6cq=^VP0_WvKD8P&op^Fn2P)sifgF_&2< zK7Ss1>}!Q;E#Hbpzccaue9}?_3_Xo~JL_#qjo*jmb4cIew3UCzG}&3Do=6!%lZZX!BVvV delta 455 zcmYk2J4?hs6oqfhuA}Z6-|sgfG1rW`xf;BY6_OM2``A774q;8r+m(u(HD|AA0=`wFP>!VBR zVum!?I{N&z@A+CC%3O3Dj+(`8pa#yO1iI<(@1j;0yZPsS*iVnzZIu^^hs`!M$bbjB ur`dsl+ojk0?Rhu;9 widgetTZAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, timezonesList); + tzSpinner.setAdapter(widgetTZAdapter); + if ((widget != null) && (Arrays.asList(timezonesList).contains(widget.getTimezone()))) { + tzSpinner.setSelection(Arrays.asList(timezonesList).indexOf(widget.getTimezone())); + } else { + tzSpinner.setSelection(Arrays.asList(timezonesList).indexOf("Etc/UTC")); + } + // Show timezone spinner only when 2nd TZ widget is selected + typeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + String selectedType = widgetTypesArray.get(typeSpinner.getSelectedItemPosition()); + if (selectedType.equals("widget2ndTZ")) { + timezoneLayout.setVisibility(View.VISIBLE); + } else { + timezoneLayout.setVisibility(View.GONE); + } + } + @Override + public void onNothingSelected(AdapterView parent) { } + }); + // Show dialog new AlertDialog.Builder(this) .setView(layout) .setNegativeButton(R.string.fossil_hr_edit_action_delete, new DialogInterface.OnClickListener() { @@ -570,10 +610,17 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem if (selectedPosY < 1) selectedPosY = 1; if (selectedPosY > 240) selectedPosY = 240; String selectedType = widgetTypesArray.get(typeSpinner.getSelectedItemPosition()); - if (index >= 0) { - widgets.set(index, new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY, colorSpinner.getSelectedItemPosition())); + String selectedTZ = tzSpinner.getSelectedItem().toString(); + HybridHRWatchfaceWidget widgetConfig; + if (selectedType.equals("widget2ndTZ")) { + widgetConfig = new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY, colorSpinner.getSelectedItemPosition(), selectedTZ); } else { - widgets.add(new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY, colorSpinner.getSelectedItemPosition())); + widgetConfig = new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY, colorSpinner.getSelectedItemPosition()); + } + if (index >= 0) { + widgets.set(index, widgetConfig); + } else { + widgets.add(widgetConfig); } renderWatchfacePreview(); } 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 f88526a3f..6754009d4 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 @@ -30,6 +30,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.LinkedHashMap; +import java.util.TimeZone; import nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.image.ImageConverter; @@ -70,11 +71,26 @@ public class HybridHRWatchfaceFactory { case "widgetCalories": case "widgetActiveMins": case "widgetChanceOfRain": + widget.put("type", "comp"); + widget.put("name", widgetDesc.getWidgetType()); + widget.put("goal_ring", false); + widget.put("color", widgetDesc.getColor() == HybridHRWatchfaceWidget.COLOR_WHITE ? "white" : "black"); + break; case "widget2ndTZ": widget.put("type", "comp"); widget.put("name", widgetDesc.getWidgetType()); widget.put("goal_ring", false); widget.put("color", widgetDesc.getColor() == HybridHRWatchfaceWidget.COLOR_WHITE ? "white" : "black"); + if (widgetDesc.getTimezone() != null) { + JSONObject data = new JSONObject(); + TimeZone tz = TimeZone.getTimeZone(widgetDesc.getTimezone()); + String tzShortName = widgetDesc.getTimezone().replaceAll(".*/", ""); + int tzOffsetMins = tz.getRawOffset() / 1000 / 60; + data.put("tzName", widgetDesc.getTimezone()); + data.put("loc", tzShortName); + data.put("utc", tzOffsetMins); + widget.put("data", data); + } break; default: LOG.warn("Invalid widget name: " + widgetDesc.getWidgetType()); 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 656150378..246157730 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 @@ -32,6 +32,7 @@ public class HybridHRWatchfaceWidget { private int posX; private int posY; private int color = 0; + private String timezone; public static int COLOR_WHITE = 0; public static int COLOR_BLACK = 1; @@ -42,6 +43,11 @@ public class HybridHRWatchfaceWidget { this.posY = posY; this.color = color; } + public HybridHRWatchfaceWidget(String widgetType, int posX, int posY, int color, String timezone) { + this(widgetType, posX, posY, color); + this.timezone = timezone; + } + public static LinkedHashMap getAvailableWidgetTypes(Context context) { LinkedHashMap widgetTypes = new LinkedHashMap<>(); @@ -73,7 +79,6 @@ public class HybridHRWatchfaceWidget { public int getPosX() { return posX; } - public int getPosY() { return posY; } @@ -81,7 +86,6 @@ public class HybridHRWatchfaceWidget { public void setPosX(int posX) { this.posX = posX; } - public void setPosY(int posY) { this.posY = posY; } @@ -89,4 +93,8 @@ public class HybridHRWatchfaceWidget { public int getColor() { return color; } + + public String getTimezone() { + return timezone; + } } diff --git a/app/src/main/res/layout/dialog_hybridhr_watchface_widget.xml b/app/src/main/res/layout/dialog_hybridhr_watchface_widget.xml index 272fd82c6..7ed49186f 100644 --- a/app/src/main/res/layout/dialog_hybridhr_watchface_widget.xml +++ b/app/src/main/res/layout/dialog_hybridhr_watchface_widget.xml @@ -76,4 +76,19 @@ android:text="@string/watchface_dialog_widget_preset_right"/> - \ No newline at end of file + + + + + + diff --git a/external/fossil-hr-watchface b/external/fossil-hr-watchface index 01bd1424d..15aeb1e72 160000 --- a/external/fossil-hr-watchface +++ b/external/fossil-hr-watchface @@ -1 +1 @@ -Subproject commit 01bd1424dc4c492ab25f3e2824be2aa8bf5b5256 +Subproject commit 15aeb1e72595fb285702878632d8a9e42b0eb181