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|<%}*0i6vcn9opu;YDO34qi}F#Z(-9jWFjEUe5u_~$0lGk4ktU536NAPO7H(?X zjB!W0bf=5i8rfc}qW|Z)sRq4^ zh%NM%qHEI;U0C|LEz)6@7FPPae0_1i7KtBbkFXNo&|Z}_OKU0mo8TvQgmMw^Y8Dq! zlfgo^I8>M@4z~+tF;kc;W($>K?wPhC>ibb=M2{Dvzix=-F1{&d_oL3}Wqnvob?X_C z>Ef*D?cy=C!z$HF(_#^&r&RK$K`ntSfinaCEI1>yF(yIIfjSTFJk%DzUjV}bH3zN@ zei>?a!B2u)0a*cK5&T6^m%tAK@FStwel#@PTLvQq>OD~JgAoI_A3P;ogd9B0ML&tQ zvjR@ANWgdi>M9s(;5-Cl9lZ4`?kdPC)M_AOP|Jg#=W+(44z(%p>Od;g=uUzY2U!Oh z;0^FLKyHAu2`1`5xhKXP+NE`FSs+gDUOp1wInd#|R8d9WC{u(KinUSJknf`&1Aau%45QrgB7iyvoD^|vZ8%mt9J(im1}Wnv5o+`-(2X{YH)zMMDjcXGbxygA<{?(&)4WNKPm~~JjfD+3t){xlmmYpqz%3UkqJ>6A_x2t zsG06PjMwP5J?U~QPK7>`atz_7e`R&CRux0ya_q6vialOx*!fT9hG?H?{zNuuYd4c( zeW0hr@`>h8_xzlgANXS;-`D5b&A1pEG-fc*TD`Pdy-19No?2Q89zwJTstn#E2p@w# z1=bv>Wr$Y5e*#to!V1V$kdxrM5LUsefy#hi2UQ2zfUp5k1B`J^TX5 zBA6nm5||R```ch&mcf)ktb$wvk%7?ed64TM(-5aYRX|rjRw0b`Ql}@P2Brp9!LNg^ zgV^{(Xn+Qk=MWORWzY?Wr#C@wIc&A<(BtSm^>Ad>EQbwc{cW(>3;QDpT!2@PWRj3Y z2&*8PV4|0~rz@+Fa5W+E1>zm>cR@=KEthmwmuk6s;uc9&R{hX6&<5RhPO1Z82XqHS z7gQH)&d}~2=-z+r(UQ244WcDTmcgumDuJql1e-bpMKDFMtDqZT8lcj>!s$uUglG*UAzKH% z0m-IA$hN=&+H(kbT@CcM!_zyUTMpZ{9D0y`6dsQxO*lkK`bF$_Lw*RC$h>*vBa$Mf znvk@?rms`a*OHKPwLyA?CFnrb0UbaRIMcs#1uiA%{-+;KgXx0qxhC5K6@m^S3BiWs vo~jR7AN20u+0%*lJzr)tjxWaXARb=D>7;n;SBTHfhXZ*= 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