Fossil HR: Make width of custom widget configurable

This commit is contained in:
Arjan Schrijver 2022-01-10 22:07:33 +01:00 committed by Gitea
parent edd1b950a9
commit 795c800dd4
5 changed files with 72 additions and 14 deletions

View File

@ -394,6 +394,8 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
widgets.add(new HybridHRWatchfaceWidget(widgetName, widgets.add(new HybridHRWatchfaceWidget(widgetName,
layoutItem.getJSONObject("pos").getInt("x"), layoutItem.getJSONObject("pos").getInt("x"),
layoutItem.getJSONObject("pos").getInt("y"), layoutItem.getJSONObject("pos").getInt("y"),
layoutItem.getJSONObject("size").getInt("w"),
layoutItem.getJSONObject("size").getInt("h"),
widgetColor, widgetColor,
widgetTimezone)); widgetTimezone));
} catch (JSONException e) { } catch (JSONException e) {
@ -408,6 +410,8 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
widgets.add(new HybridHRWatchfaceWidget(widgetName, widgets.add(new HybridHRWatchfaceWidget(widgetName,
layoutItem.getJSONObject("pos").getInt("x"), layoutItem.getJSONObject("pos").getInt("x"),
layoutItem.getJSONObject("pos").getInt("y"), layoutItem.getJSONObject("pos").getInt("y"),
layoutItem.getJSONObject("size").getInt("w"),
layoutItem.getJSONObject("size").getInt("h"),
widgetColor, widgetColor,
widgetUpdateTimeout, widgetUpdateTimeout,
widgetTimeoutHideText, widgetTimeoutHideText,
@ -416,6 +420,8 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
widgets.add(new HybridHRWatchfaceWidget(widgetName, widgets.add(new HybridHRWatchfaceWidget(widgetName,
layoutItem.getJSONObject("pos").getInt("x"), layoutItem.getJSONObject("pos").getInt("x"),
layoutItem.getJSONObject("pos").getInt("y"), layoutItem.getJSONObject("pos").getInt("y"),
layoutItem.getJSONObject("size").getInt("w"),
layoutItem.getJSONObject("size").getInt("h"),
widgetColor)); widgetColor));
} }
} }
@ -603,6 +609,13 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
posY.setText("120"); 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 // Populate timezone spinner
String[] timezonesList = TimeZone.getAvailableIDs(); String[] timezonesList = TimeZone.getAvailableIDs();
final Spinner tzSpinner = layout.findViewById(R.id.watchface_widget_timezone_spinner); 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); timezoneLayout.setVisibility(View.GONE);
} }
if (selectedType.equals("widgetCustom")) { if (selectedType.equals("widgetCustom")) {
sizeLayout.setVisibility(View.VISIBLE);
updateTimeoutLayout.setVisibility(View.VISIBLE); updateTimeoutLayout.setVisibility(View.VISIBLE);
} else { } else {
sizeLayout.setVisibility(View.GONE);
updateTimeoutLayout.setVisibility(View.GONE); updateTimeoutLayout.setVisibility(View.GONE);
} }
} }
@ -678,6 +693,12 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
if (selectedPosX > 240) selectedPosX = 240; if (selectedPosX > 240) selectedPosX = 240;
if (selectedPosY < 1) selectedPosY = 1; if (selectedPosY < 1) selectedPosY = 1;
if (selectedPosY > 240) selectedPosY = 240; 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 selectedType = widgetTypesArray.get(typeSpinner.getSelectedItemPosition());
String selectedTZ = tzSpinner.getSelectedItem().toString(); String selectedTZ = tzSpinner.getSelectedItem().toString();
int selectedUpdateTimeout = 0; int selectedUpdateTimeout = 0;
@ -694,11 +715,11 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
boolean selectedTimeoutShowCircle = timeoutShowCircle.isChecked(); boolean selectedTimeoutShowCircle = timeoutShowCircle.isChecked();
HybridHRWatchfaceWidget widgetConfig; HybridHRWatchfaceWidget widgetConfig;
if (selectedType.equals("widget2ndTZ")) { 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")) { } 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 { } else {
widgetConfig = new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY, colorSpinner.getSelectedItemPosition()); widgetConfig = new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY, 76, 76, colorSpinner.getSelectedItemPosition());
} }
if (index >= 0) { if (index >= 0) {
widgets.set(index, widgetConfig); widgets.set(index, widgetConfig);

View File

@ -105,8 +105,8 @@ public class HybridHRWatchfaceFactory {
return; return;
} }
JSONObject size = new JSONObject(); JSONObject size = new JSONObject();
size.put("w", 76); size.put("w", widgetDesc.getWidth());
size.put("h", 76); size.put("h", widgetDesc.getHeight());
widget.put("size", size); widget.put("size", size);
JSONObject pos = new JSONObject(); JSONObject pos = new JSONObject();
pos.put("x", widgetDesc.getPosX()); pos.put("x", widgetDesc.getPosX());
@ -336,8 +336,8 @@ public class HybridHRWatchfaceFactory {
complicationContent.put("inversion", "#$e"); complicationContent.put("inversion", "#$e");
dimension = new JSONObject(); dimension = new JSONObject();
dimension.put("type", "rigid"); dimension.put("type", "rigid");
dimension.put("width", 76); dimension.put("width", "#size.w");
dimension.put("height", 76); dimension.put("height", "#size.h");
complicationContent.put("dimension", dimension); complicationContent.put("dimension", dimension);
placement = new JSONObject(); placement = new JSONObject();
placement.put("type", "relative"); placement.put("type", "relative");

View File

@ -31,7 +31,9 @@ public class HybridHRWatchfaceWidget {
private String widgetType; private String widgetType;
private int posX; private int posX;
private int posY; private int posY;
private int color = 0; private int width;
private int height;
private int color;
private String timezone; private String timezone;
private int updateTimeout = -1; private int updateTimeout = -1;
private boolean timeoutHideText = true; private boolean timeoutHideText = true;
@ -40,18 +42,20 @@ public class HybridHRWatchfaceWidget {
public static int COLOR_WHITE = 0; public static int COLOR_WHITE = 0;
public static int COLOR_BLACK = 1; 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.widgetType = widgetType;
this.posX = posX; this.posX = posX;
this.posY = posY; this.posY = posY;
this.width = width;
this.height = height;
this.color = color; this.color = color;
} }
public HybridHRWatchfaceWidget(String widgetType, int posX, int posY, int color, String timezone) { public HybridHRWatchfaceWidget(String widgetType, int posX, int posY, int width, int height, int color, String timezone) {
this(widgetType, posX, posY, color); this(widgetType, posX, posY, width, height, color);
this.timezone = timezone; this.timezone = timezone;
} }
public HybridHRWatchfaceWidget(String widgetType, int posX, int posY, int color, int updateTimeout, boolean timeoutHideText, boolean timeoutShowCircle) { public HybridHRWatchfaceWidget(String widgetType, int posX, int posY, int width, int height, int color, int updateTimeout, boolean timeoutHideText, boolean timeoutShowCircle) {
this(widgetType, posX, posY, color); this(widgetType, posX, posY, width, height, color);
this.updateTimeout = updateTimeout; this.updateTimeout = updateTimeout;
this.timeoutHideText = timeoutHideText; this.timeoutHideText = timeoutHideText;
this.timeoutShowCircle = timeoutShowCircle; this.timeoutShowCircle = timeoutShowCircle;
@ -100,6 +104,20 @@ public class HybridHRWatchfaceWidget {
this.posY = posY; 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() { public int getColor() {
return color; return color;
} }

View File

@ -76,6 +76,23 @@
android:text="@string/watchface_dialog_widget_preset_right"/> android:text="@string/watchface_dialog_widget_preset_right"/>
</LinearLayout> </LinearLayout>
<LinearLayout
android:id="@+id/watchface_widget_size_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/watchface_dialog_widget_width" />
<EditText
android:id="@+id/watchface_widget_width"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:text="76"/>
</LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/watchface_widget_timezone_layout" android:id="@+id/watchface_widget_timezone_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -104,7 +121,8 @@
android:id="@+id/watchface_widget_update_timeout" android:id="@+id/watchface_widget_update_timeout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:inputType="number"/> android:inputType="number"
android:text="60"/>
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@ -1493,4 +1493,5 @@
<string name="menuitem_menu">Menu</string> <string name="menuitem_menu">Menu</string>
<string name="fossil_hr_button_config_info">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.</string> <string name="fossil_hr_button_config_info">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.</string>
<string name="watchface_dialog_widget_width">Width:</string>
</resources> </resources>