mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-29 05:16:51 +01:00
Fossil HR: Make width of custom widget configurable
This commit is contained in:
parent
edd1b950a9
commit
795c800dd4
@ -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);
|
||||
|
@ -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");
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -76,6 +76,23 @@
|
||||
android:text="@string/watchface_dialog_widget_preset_right"/>
|
||||
</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
|
||||
android:id="@+id/watchface_widget_timezone_layout"
|
||||
android:layout_width="match_parent"
|
||||
@ -104,7 +121,8 @@
|
||||
android:id="@+id/watchface_widget_update_timeout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="number"/>
|
||||
android:inputType="number"
|
||||
android:text="60"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -1493,4 +1493,5 @@
|
||||
|
||||
<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="watchface_dialog_widget_width">Width:</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user