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 ead718bab..0a3b5cd87 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 @@ -394,6 +394,8 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem widgets.add(new HybridHRWatchfaceWidget(widgetName, layoutItem.getJSONObject("pos").getInt("x"), layoutItem.getJSONObject("pos").getInt("y"), + layoutItem.getJSONObject("size").getInt("w"), + layoutItem.getJSONObject("size").getInt("h"), widgetColor, widgetTimezone)); } catch (JSONException e) { @@ -408,6 +410,8 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem widgets.add(new HybridHRWatchfaceWidget(widgetName, layoutItem.getJSONObject("pos").getInt("x"), layoutItem.getJSONObject("pos").getInt("y"), + layoutItem.getJSONObject("size").getInt("w"), + layoutItem.getJSONObject("size").getInt("h"), widgetColor, widgetUpdateTimeout, widgetTimeoutHideText, @@ -416,6 +420,8 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem widgets.add(new HybridHRWatchfaceWidget(widgetName, layoutItem.getJSONObject("pos").getInt("x"), layoutItem.getJSONObject("pos").getInt("y"), + layoutItem.getJSONObject("size").getInt("w"), + layoutItem.getJSONObject("size").getInt("h"), widgetColor)); } } @@ -603,6 +609,13 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem posY.setText("120"); } }); + // Set widget size + final LinearLayout sizeLayout = layout.findViewById(R.id.watchface_widget_size_layout); + sizeLayout.setVisibility(View.GONE); + final EditText widgetWidth = layout.findViewById(R.id.watchface_widget_width); + if ((widget != null) && (widget.getWidth() >= 0)) { + widgetWidth.setText(Integer.toString(widget.getWidth())); + } // Populate timezone spinner String[] timezonesList = TimeZone.getAvailableIDs(); final Spinner tzSpinner = layout.findViewById(R.id.watchface_widget_timezone_spinner); @@ -641,8 +654,10 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem timezoneLayout.setVisibility(View.GONE); } if (selectedType.equals("widgetCustom")) { + sizeLayout.setVisibility(View.VISIBLE); updateTimeoutLayout.setVisibility(View.VISIBLE); } else { + sizeLayout.setVisibility(View.GONE); updateTimeoutLayout.setVisibility(View.GONE); } } @@ -678,6 +693,12 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem if (selectedPosX > 240) selectedPosX = 240; if (selectedPosY < 1) selectedPosY = 1; if (selectedPosY > 240) selectedPosY = 240; + int selectedWidth = 76; + try { + selectedWidth = Integer.parseInt(widgetWidth.getText().toString()); + } catch (NumberFormatException e) { + LOG.warn("Error parsing input", e); + } String selectedType = widgetTypesArray.get(typeSpinner.getSelectedItemPosition()); String selectedTZ = tzSpinner.getSelectedItem().toString(); int selectedUpdateTimeout = 0; @@ -694,11 +715,11 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem boolean selectedTimeoutShowCircle = timeoutShowCircle.isChecked(); HybridHRWatchfaceWidget widgetConfig; if (selectedType.equals("widget2ndTZ")) { - widgetConfig = new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY, colorSpinner.getSelectedItemPosition(), selectedTZ); + widgetConfig = new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY, 76, 76, colorSpinner.getSelectedItemPosition(), selectedTZ); } else if (selectedType.equals("widgetCustom")) { - widgetConfig = new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY, colorSpinner.getSelectedItemPosition(), selectedUpdateTimeout, selectedTimeoutHideText, selectedTimeoutShowCircle); + widgetConfig = new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY, selectedWidth, 76, colorSpinner.getSelectedItemPosition(), selectedUpdateTimeout, selectedTimeoutHideText, selectedTimeoutShowCircle); } else { - widgetConfig = new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY, colorSpinner.getSelectedItemPosition()); + widgetConfig = new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY, 76, 76, colorSpinner.getSelectedItemPosition()); } if (index >= 0) { widgets.set(index, widgetConfig); 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 2ab3ffd8c..b0cdfd227 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 @@ -105,8 +105,8 @@ public class HybridHRWatchfaceFactory { return; } JSONObject size = new JSONObject(); - size.put("w", 76); - size.put("h", 76); + size.put("w", widgetDesc.getWidth()); + size.put("h", widgetDesc.getHeight()); widget.put("size", size); JSONObject pos = new JSONObject(); pos.put("x", widgetDesc.getPosX()); @@ -336,8 +336,8 @@ public class HybridHRWatchfaceFactory { complicationContent.put("inversion", "#$e"); dimension = new JSONObject(); dimension.put("type", "rigid"); - dimension.put("width", 76); - dimension.put("height", 76); + dimension.put("width", "#size.w"); + dimension.put("height", "#size.h"); complicationContent.put("dimension", dimension); placement = new JSONObject(); placement.put("type", "relative"); 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 921966dda..63aa3fe2e 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 @@ -31,7 +31,9 @@ public class HybridHRWatchfaceWidget { private String widgetType; private int posX; private int posY; - private int color = 0; + private int width; + private int height; + private int color; private String timezone; private int updateTimeout = -1; private boolean timeoutHideText = true; @@ -40,18 +42,20 @@ public class HybridHRWatchfaceWidget { public static int COLOR_WHITE = 0; public static int COLOR_BLACK = 1; - public HybridHRWatchfaceWidget(String widgetType, int posX, int posY, int color) { + public HybridHRWatchfaceWidget(String widgetType, int posX, int posY, int width, int height, int color) { this.widgetType = widgetType; this.posX = posX; this.posY = posY; + this.width = width; + this.height = height; this.color = color; } - public HybridHRWatchfaceWidget(String widgetType, int posX, int posY, int color, String timezone) { - this(widgetType, posX, posY, color); + public HybridHRWatchfaceWidget(String widgetType, int posX, int posY, int width, int height, int color, String timezone) { + this(widgetType, posX, posY, width, height, color); this.timezone = timezone; } - public HybridHRWatchfaceWidget(String widgetType, int posX, int posY, int color, int updateTimeout, boolean timeoutHideText, boolean timeoutShowCircle) { - this(widgetType, posX, posY, color); + public HybridHRWatchfaceWidget(String widgetType, int posX, int posY, int width, int height, int color, int updateTimeout, boolean timeoutHideText, boolean timeoutShowCircle) { + this(widgetType, posX, posY, width, height, color); this.updateTimeout = updateTimeout; this.timeoutHideText = timeoutHideText; this.timeoutShowCircle = timeoutShowCircle; @@ -100,6 +104,20 @@ public class HybridHRWatchfaceWidget { this.posY = posY; } + public int getWidth() { + return width; + } + public int getHeight() { + return height; + } + + public void setWidth(int width) { + this.width = width; + } + public void setHeight(int height) { + this.height = height; + } + public int getColor() { return color; } 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 7883b0e08..c91273ca3 100644 --- a/app/src/main/res/layout/dialog_hybridhr_watchface_widget.xml +++ b/app/src/main/res/layout/dialog_hybridhr_watchface_widget.xml @@ -76,6 +76,23 @@ android:text="@string/watchface_dialog_widget_preset_right"/> + + + + + + android:inputType="number" + android:text="60"/> Menu Some buttons cannot be configured because their functions are hard-coded in the watch firmware.\n\nWarning: long-pressing the upper button when a watchface from the official Fossil app is installed will also toggle between showing/hiding widgets. + Width: