diff --git a/app/src/main/assets/fossil_hr/widgetCustom.bin b/app/src/main/assets/fossil_hr/widgetCustom.bin index 23465b1f4..6397773a4 100644 Binary files a/app/src/main/assets/fossil_hr/widgetCustom.bin and b/app/src/main/assets/fossil_hr/widgetCustom.bin differ 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 aa2732207..d210d1ab4 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 @@ -352,6 +352,7 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem if (layoutItem.getString("type").equals("comp")) { String widgetName = layoutItem.getString("name"); String widgetTimezone = null; + int widgetUpdateTimeout = -1; switch (widgetName) { case "dateSSE": widgetName = "widgetDate"; @@ -381,24 +382,35 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem widgetName = "widget2ndTZ"; break; } + int widgetColor = layoutItem.getString("color").equals("white") ? HybridHRWatchfaceWidget.COLOR_WHITE : HybridHRWatchfaceWidget.COLOR_BLACK; if (widgetName.startsWith("widget2ndTZ")) { try { widgetName = "widget2ndTZ"; JSONObject widgetData = layoutItem.getJSONObject("data"); widgetTimezone = widgetData.getString("tzName"); + widgets.add(new HybridHRWatchfaceWidget(widgetName, + layoutItem.getJSONObject("pos").getInt("x"), + layoutItem.getJSONObject("pos").getInt("y"), + widgetColor, + widgetTimezone)); } catch (JSONException e) { LOG.error("Couldn't determine tzName!", e); } - } - if (widgetName.startsWith("widgetCustom")) { + } else if (widgetName.startsWith("widgetCustom")) { widgetName = "widgetCustom"; + JSONObject widgetData = layoutItem.getJSONObject("data"); + widgetUpdateTimeout = widgetData.getInt("update_timeout"); + widgets.add(new HybridHRWatchfaceWidget(widgetName, + layoutItem.getJSONObject("pos").getInt("x"), + layoutItem.getJSONObject("pos").getInt("y"), + widgetColor, + widgetUpdateTimeout)); + } else { + widgets.add(new HybridHRWatchfaceWidget(widgetName, + layoutItem.getJSONObject("pos").getInt("x"), + layoutItem.getJSONObject("pos").getInt("y"), + widgetColor)); } - int widgetColor = layoutItem.getString("color").equals("white") ? HybridHRWatchfaceWidget.COLOR_WHITE : HybridHRWatchfaceWidget.COLOR_BLACK; - widgets.add(new HybridHRWatchfaceWidget(widgetName, - layoutItem.getJSONObject("pos").getInt("x"), - layoutItem.getJSONObject("pos").getInt("y"), - widgetColor, - widgetTimezone)); } } } catch (JSONException e) { @@ -596,7 +608,14 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem } else { tzSpinner.setSelection(Arrays.asList(timezonesList).indexOf("Etc/UTC")); } - // Show timezone spinner only when 2nd TZ widget is selected + // Set update timeout value + final LinearLayout updateTimeoutLayout = layout.findViewById(R.id.watchface_widget_update_timeout_layout); + updateTimeoutLayout.setVisibility(View.GONE); + final EditText updateTimeout = layout.findViewById(R.id.watchface_widget_update_timeout); + if ((widget != null) && (widget.getUpdateTimeout() >= 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