From d1062a30b21d94a03cc25da176f33890f28665dc Mon Sep 17 00:00:00 2001 From: Arjan Schrijver Date: Wed, 17 Nov 2021 13:42:14 +0100 Subject: [PATCH] Fossil Hybrid HR: Add update timeout to custom widget --- .../main/assets/fossil_hr/widgetCustom.bin | Bin 618 -> 950 bytes .../HybridHRWatchfaceDesignerActivity.java | 52 +++++++++++++++--- .../qhybrid/HybridHRWatchfaceFactory.java | 5 ++ .../qhybrid/HybridHRWatchfaceWidget.java | 8 +++ .../dialog_hybridhr_watchface_widget.xml | 18 +++++- app/src/main/res/values/strings.xml | 2 + external/fossil-hr-watchface | 2 +- 7 files changed, 76 insertions(+), 11 deletions(-) diff --git a/app/src/main/assets/fossil_hr/widgetCustom.bin b/app/src/main/assets/fossil_hr/widgetCustom.bin index 23465b1f4a5c0b029b91ee8cec3307ef1f48a7ad..6397773a40d5fcc730e8e2c0b6650e86c1506d70 100644 GIT binary patch literal 950 zcmYjQJ#W)c6uth49Xp>+oL~f%+Ntiq0!l3v#DX9eV*W3E=|_jk$CZgBgks-CbU-Q+-M)_f z23X>71q@NQ0agmpAxiFmVTDN7h{nJMxI@!n6?p?NQ40)fL|?%32Uvs0_GQU_>Q?q8 zM|Bk2uj;;O_*8Q=zft!a&F3$jmfvmrw&nLaZ_$LOzSRX{$uL&n6B@+bn|i5HZq!Ic!&tX^E{+D;p!(f1%ive_9rz!YzGYeM_w^=x0OK~e z0liat7RjEZA-}it=ofj7?;xY!+~K$yItYFSto* zzSw0HT8ueJS5s!uBIMC| zFbX3EmBK376eqV3&7zgg2;;i literal 618 zcmYLHOK#gR6dY22`IAq*@FqaBO1kK(NCX7k6|IFXv+GJAB-&A-NP%=DYHvRW|Px^`;OQXD;8Xl?ums1ybwDV z2t4vWdE$x(kD(K5rpc&P8A!?pg5F zyB2?J?q8lK!A+P%`9;JePDc6REydzNM+gze_I}n^Kjt@>P;+|J*)z8~pCD#$w-AZ6 zH&6VVVD52`=HXyHLfsTPtJS0CBp-QGFUwVoP21{qX7rPB@om$Y7*(@9Fb=jWgA-J$ zGug3_&OZNVkHv6N)};yXpz5O1Yo3d>+6sJxhpsAfO~yR8`V3oT@`r4xa?PoQG8!`! wW!F~fIpa|s*y4QfJXk%D5q@_~oh{2s;{$K;*mAToB{{Y?8^eF7FcNwB52wa= 0)) { + updateTimeout.setText(Integer.toString(widget.getUpdateTimeout())); + } + // Show certain input fields only when the relevant TZ widget is selected typeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { @@ -606,6 +625,11 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem } else { timezoneLayout.setVisibility(View.GONE); } + if (selectedType.equals("widgetCustom")) { + updateTimeoutLayout.setVisibility(View.VISIBLE); + } else { + updateTimeoutLayout.setVisibility(View.GONE); + } } @Override public void onNothingSelected(AdapterView parent) { } @@ -641,9 +665,19 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem if (selectedPosY > 240) selectedPosY = 240; String selectedType = widgetTypesArray.get(typeSpinner.getSelectedItemPosition()); String selectedTZ = tzSpinner.getSelectedItem().toString(); + int selectedUpdateTimeout; + try { + selectedUpdateTimeout = Integer.parseInt(updateTimeout.getText().toString()); + } catch (NumberFormatException e) { + GB.toast(getString(R.string.watchface_toast_settings_incomplete), Toast.LENGTH_SHORT, GB.WARN); + LOG.warn("Error parsing input", e); + return; + } HybridHRWatchfaceWidget widgetConfig; if (selectedType.equals("widget2ndTZ")) { widgetConfig = new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY, colorSpinner.getSelectedItemPosition(), selectedTZ); + } else if (selectedType.equals("widgetCustom")) { + widgetConfig = new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY, colorSpinner.getSelectedItemPosition(), selectedUpdateTimeout); } else { widgetConfig = new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY, colorSpinner.getSelectedItemPosition()); } 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 c21f2106e..3db646d91 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 @@ -76,6 +76,11 @@ public class HybridHRWatchfaceFactory { widget.put("name", widgetDesc.getWidgetType()); widget.put("goal_ring", false); widget.put("color", widgetDesc.getColor() == HybridHRWatchfaceWidget.COLOR_WHITE ? "white" : "black"); + if (widgetDesc.getUpdateTimeout() >= 0) { + JSONObject data = new JSONObject(); + data.put("update_timeout", widgetDesc.getUpdateTimeout()); + widget.put("data", data); + } break; case "widget2ndTZ": widget.put("type", "comp"); 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 f5efaea91..b5fb96d25 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 @@ -33,6 +33,7 @@ public class HybridHRWatchfaceWidget { private int posY; private int color = 0; private String timezone; + private int updateTimeout = -1; public static int COLOR_WHITE = 0; public static int COLOR_BLACK = 1; @@ -47,6 +48,10 @@ public class HybridHRWatchfaceWidget { this(widgetType, posX, posY, color); this.timezone = timezone; } + public HybridHRWatchfaceWidget(String widgetType, int posX, int posY, int color, int updateTimeout) { + this(widgetType, posX, posY, color); + this.updateTimeout = updateTimeout; + } public static LinkedHashMap getAvailableWidgetTypes(Context context) { @@ -98,4 +103,7 @@ public class HybridHRWatchfaceWidget { public String getTimezone() { return timezone; } + public int getUpdateTimeout() { + return updateTimeout; + } } 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 7ed49186f..eb67c566c 100644 --- a/app/src/main/res/layout/dialog_hybridhr_watchface_widget.xml +++ b/app/src/main/res/layout/dialog_hybridhr_watchface_widget.xml @@ -84,11 +84,27 @@ + android:text="@string/watchface_dialog_widget_timezone" /> + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 665e7561f..1fe75a95c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1388,5 +1388,7 @@ 3 hours When taken off Custom widget + Time zone: + Update timeout in minutes: diff --git a/external/fossil-hr-watchface b/external/fossil-hr-watchface index 6270e0478..8855d1735 160000 --- a/external/fossil-hr-watchface +++ b/external/fossil-hr-watchface @@ -1 +1 @@ -Subproject commit 6270e0478c1aa5cd3fde75567d9a1f00bdddb9c5 +Subproject commit 8855d1735b07939f483759cb7e836a8418f30515