mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-18 06:37:47 +01:00
Fossil Hybrid HR: Make widget settings code more flexible
This commit is contained in:
parent
2405e68109
commit
d03ec5518b
@ -566,8 +566,8 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
|
|||||||
timezoneLayout.setVisibility(View.GONE);
|
timezoneLayout.setVisibility(View.GONE);
|
||||||
ArrayAdapter<String> widgetTZAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, timezonesList);
|
ArrayAdapter<String> widgetTZAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, timezonesList);
|
||||||
tzSpinner.setAdapter(widgetTZAdapter);
|
tzSpinner.setAdapter(widgetTZAdapter);
|
||||||
if ((widget != null) && (Arrays.asList(timezonesList).contains(widget.getTimezone()))) {
|
if (widget != null) {
|
||||||
tzSpinner.setSelection(Arrays.asList(timezonesList).indexOf(widget.getTimezone()));
|
tzSpinner.setSelection(Arrays.asList(timezonesList).indexOf(widget.getExtraConfigString("tzName", "Etc/UTC")));
|
||||||
} else {
|
} else {
|
||||||
tzSpinner.setSelection(Arrays.asList(timezonesList).indexOf("Etc/UTC"));
|
tzSpinner.setSelection(Arrays.asList(timezonesList).indexOf("Etc/UTC"));
|
||||||
}
|
}
|
||||||
@ -575,16 +575,16 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
|
|||||||
final LinearLayout updateTimeoutLayout = layout.findViewById(R.id.watchface_widget_update_timeout_layout);
|
final LinearLayout updateTimeoutLayout = layout.findViewById(R.id.watchface_widget_update_timeout_layout);
|
||||||
updateTimeoutLayout.setVisibility(View.GONE);
|
updateTimeoutLayout.setVisibility(View.GONE);
|
||||||
final EditText updateTimeout = layout.findViewById(R.id.watchface_widget_update_timeout);
|
final EditText updateTimeout = layout.findViewById(R.id.watchface_widget_update_timeout);
|
||||||
if ((widget != null) && (widget.getUpdateTimeout() >= 0)) {
|
if ((widget != null) && (widget.getExtraConfigInt("update_timeout", -1) > 0)) {
|
||||||
updateTimeout.setText(Integer.toString(widget.getUpdateTimeout()));
|
updateTimeout.setText(Integer.toString(widget.getExtraConfigInt("update_timeout", -1)));
|
||||||
}
|
}
|
||||||
final CheckBox timeoutHideText = layout.findViewById(R.id.watchface_widget_timeout_hide_text);
|
final CheckBox timeoutHideText = layout.findViewById(R.id.watchface_widget_timeout_hide_text);
|
||||||
if ((widget != null) && (widget.getTimeoutHideText())) {
|
if (widget != null) {
|
||||||
timeoutHideText.setChecked(widget.getTimeoutHideText());
|
timeoutHideText.setChecked(widget.getExtraConfigBoolean("timeout_hide_text", true));
|
||||||
}
|
}
|
||||||
final CheckBox timeoutShowCircle = layout.findViewById(R.id.watchface_widget_timeout_show_circle);
|
final CheckBox timeoutShowCircle = layout.findViewById(R.id.watchface_widget_timeout_show_circle);
|
||||||
if ((widget != null) && (widget.getTimeoutShowCircle())) {
|
if (widget != null) {
|
||||||
timeoutShowCircle.setChecked(widget.getTimeoutShowCircle());
|
timeoutShowCircle.setChecked(widget.getExtraConfigBoolean("timeout_show_circle", true));
|
||||||
}
|
}
|
||||||
// Show certain input fields only when the relevant TZ widget is selected
|
// Show certain input fields only when the relevant TZ widget is selected
|
||||||
typeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
typeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||||
@ -658,11 +658,25 @@ 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, 76, 76, colorSpinner.getSelectedItemPosition(), selectedTZ);
|
JSONObject extraConfig = new JSONObject();
|
||||||
|
try {
|
||||||
|
extraConfig.put("tzName", selectedTZ);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
LOG.warn("JSON error", e);
|
||||||
|
}
|
||||||
|
widgetConfig = new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY, 76, 76, colorSpinner.getSelectedItemPosition(), extraConfig);
|
||||||
} else if (selectedType.equals("widgetCustom")) {
|
} else if (selectedType.equals("widgetCustom")) {
|
||||||
widgetConfig = new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY, selectedWidth, 76, colorSpinner.getSelectedItemPosition(), selectedUpdateTimeout, selectedTimeoutHideText, selectedTimeoutShowCircle);
|
JSONObject extraConfig = new JSONObject();
|
||||||
|
try {
|
||||||
|
extraConfig.put("update_timeout", selectedUpdateTimeout);
|
||||||
|
extraConfig.put("timeout_hide_text", selectedTimeoutHideText);
|
||||||
|
extraConfig.put("timeout_show_circle", selectedTimeoutShowCircle);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
LOG.warn("JSON error", e);
|
||||||
|
}
|
||||||
|
widgetConfig = new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY, selectedWidth, 76, colorSpinner.getSelectedItemPosition(), extraConfig);
|
||||||
} else {
|
} else {
|
||||||
widgetConfig = new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY, 76, 76, colorSpinner.getSelectedItemPosition());
|
widgetConfig = new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY, 76, 76, colorSpinner.getSelectedItemPosition(), null);
|
||||||
}
|
}
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
widgets.set(index, widgetConfig);
|
widgets.set(index, widgetConfig);
|
||||||
|
@ -81,11 +81,11 @@ public class HybridHRWatchfaceFactory {
|
|||||||
widget.put("name", widgetDesc.getWidgetType());
|
widget.put("name", widgetDesc.getWidgetType());
|
||||||
widget.put("goal_ring", false);
|
widget.put("goal_ring", false);
|
||||||
widget.put("color", widgetDesc.getColor() == HybridHRWatchfaceWidget.COLOR_WHITE ? "white" : "black");
|
widget.put("color", widgetDesc.getColor() == HybridHRWatchfaceWidget.COLOR_WHITE ? "white" : "black");
|
||||||
if (widgetDesc.getUpdateTimeout() >= 0) {
|
if (widgetDesc.getExtraConfigInt("update_timeout", -1) >= 0) {
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
data.put("update_timeout", widgetDesc.getUpdateTimeout());
|
data.put("update_timeout", widgetDesc.getExtraConfigInt("update_timeout", -1));
|
||||||
data.put("timeout_hide_text", widgetDesc.getTimeoutHideText());
|
data.put("timeout_hide_text", widgetDesc.getExtraConfigBoolean("timeout_hide_text", true));
|
||||||
data.put("timeout_show_circle", widgetDesc.getTimeoutShowCircle());
|
data.put("timeout_show_circle", widgetDesc.getExtraConfigBoolean("timeout_show_circle", true));
|
||||||
widget.put("data", data);
|
widget.put("data", data);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -94,12 +94,12 @@ public class HybridHRWatchfaceFactory {
|
|||||||
widget.put("name", widgetDesc.getWidgetType());
|
widget.put("name", widgetDesc.getWidgetType());
|
||||||
widget.put("goal_ring", false);
|
widget.put("goal_ring", false);
|
||||||
widget.put("color", widgetDesc.getColor() == HybridHRWatchfaceWidget.COLOR_WHITE ? "white" : "black");
|
widget.put("color", widgetDesc.getColor() == HybridHRWatchfaceWidget.COLOR_WHITE ? "white" : "black");
|
||||||
if (widgetDesc.getTimezone() != null) {
|
if (widgetDesc.getExtraConfigString("tzName", null) != null) {
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
TimeZone tz = TimeZone.getTimeZone(widgetDesc.getTimezone());
|
TimeZone tz = TimeZone.getTimeZone(widgetDesc.getExtraConfigString("tzName", null));
|
||||||
String tzShortName = widgetDesc.getTimezone().replaceAll(".*/", "");
|
String tzShortName = widgetDesc.getExtraConfigString("tzName", null).replaceAll(".*/", "");
|
||||||
int tzOffsetMins = tz.getRawOffset() / 1000 / 60;
|
int tzOffsetMins = tz.getRawOffset() / 1000 / 60;
|
||||||
data.put("tzName", widgetDesc.getTimezone());
|
data.put("tzName", widgetDesc.getExtraConfigString("tzName", null));
|
||||||
data.put("loc", tzShortName);
|
data.put("loc", tzShortName);
|
||||||
data.put("utc", tzOffsetMins);
|
data.put("utc", tzOffsetMins);
|
||||||
widget.put("data", data);
|
widget.put("data", data);
|
||||||
@ -299,45 +299,20 @@ public class HybridHRWatchfaceFactory {
|
|||||||
widgetName = "widget2ndTZ";
|
widgetName = "widget2ndTZ";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int widgetColor = widgetJSON.getString("color").equals("white") ? HybridHRWatchfaceWidget.COLOR_WHITE : HybridHRWatchfaceWidget.COLOR_BLACK;
|
|
||||||
if (widgetName.startsWith("widget2ndTZ")) {
|
if (widgetName.startsWith("widget2ndTZ")) {
|
||||||
try {
|
widgetName = "widget2ndTZ";
|
||||||
widgetName = "widget2ndTZ";
|
|
||||||
JSONObject widgetData = widgetJSON.getJSONObject("data");
|
|
||||||
widgetTimezone = widgetData.getString("tzName");
|
|
||||||
parsedWidget = new HybridHRWatchfaceWidget(widgetName,
|
|
||||||
widgetJSON.getJSONObject("pos").getInt("x"),
|
|
||||||
widgetJSON.getJSONObject("pos").getInt("y"),
|
|
||||||
widgetJSON.getJSONObject("size").getInt("w"),
|
|
||||||
widgetJSON.getJSONObject("size").getInt("h"),
|
|
||||||
widgetColor,
|
|
||||||
widgetTimezone);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
LOG.error("Couldn't determine tzName!", e);
|
|
||||||
}
|
|
||||||
} else if (widgetName.startsWith("widgetCustom")) {
|
} else if (widgetName.startsWith("widgetCustom")) {
|
||||||
widgetName = "widgetCustom";
|
widgetName = "widgetCustom";
|
||||||
JSONObject widgetData = widgetJSON.getJSONObject("data");
|
|
||||||
widgetUpdateTimeout = widgetData.getInt("update_timeout");
|
|
||||||
widgetTimeoutHideText = widgetData.getBoolean("timeout_hide_text");
|
|
||||||
widgetTimeoutShowCircle = widgetData.getBoolean("timeout_show_circle");
|
|
||||||
parsedWidget = new HybridHRWatchfaceWidget(widgetName,
|
|
||||||
widgetJSON.getJSONObject("pos").getInt("x"),
|
|
||||||
widgetJSON.getJSONObject("pos").getInt("y"),
|
|
||||||
widgetJSON.getJSONObject("size").getInt("w"),
|
|
||||||
widgetJSON.getJSONObject("size").getInt("h"),
|
|
||||||
widgetColor,
|
|
||||||
widgetUpdateTimeout,
|
|
||||||
widgetTimeoutHideText,
|
|
||||||
widgetTimeoutShowCircle);
|
|
||||||
} else {
|
|
||||||
parsedWidget = new HybridHRWatchfaceWidget(widgetName,
|
|
||||||
widgetJSON.getJSONObject("pos").getInt("x"),
|
|
||||||
widgetJSON.getJSONObject("pos").getInt("y"),
|
|
||||||
widgetJSON.getJSONObject("size").getInt("w"),
|
|
||||||
widgetJSON.getJSONObject("size").getInt("h"),
|
|
||||||
widgetColor);
|
|
||||||
}
|
}
|
||||||
|
int widgetColor = widgetJSON.getString("color").equals("white") ? HybridHRWatchfaceWidget.COLOR_WHITE : HybridHRWatchfaceWidget.COLOR_BLACK;
|
||||||
|
JSONObject widgetData = widgetJSON.optJSONObject("data");
|
||||||
|
parsedWidget = new HybridHRWatchfaceWidget(widgetName,
|
||||||
|
widgetJSON.getJSONObject("pos").getInt("x"),
|
||||||
|
widgetJSON.getJSONObject("pos").getInt("y"),
|
||||||
|
widgetJSON.getJSONObject("size").getInt("w"),
|
||||||
|
widgetJSON.getJSONObject("size").getInt("h"),
|
||||||
|
widgetColor,
|
||||||
|
widgetData);
|
||||||
return parsedWidget;
|
return parsedWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,9 @@ import nodomain.freeyourgadget.gadgetbridge.R;
|
|||||||
|
|
||||||
import static nodomain.freeyourgadget.gadgetbridge.util.BitmapUtil.invertBitmapColors;
|
import static nodomain.freeyourgadget.gadgetbridge.util.BitmapUtil.invertBitmapColors;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
public class HybridHRWatchfaceWidget {
|
public class HybridHRWatchfaceWidget {
|
||||||
private String widgetType;
|
private String widgetType;
|
||||||
private int posX;
|
private int posX;
|
||||||
@ -34,33 +37,20 @@ public class HybridHRWatchfaceWidget {
|
|||||||
private int width;
|
private int width;
|
||||||
private int height;
|
private int height;
|
||||||
private int color;
|
private int color;
|
||||||
private String timezone;
|
private JSONObject extraConfig;
|
||||||
private int updateTimeout = -1;
|
|
||||||
private boolean timeoutHideText = true;
|
|
||||||
private boolean timeoutShowCircle = true;
|
|
||||||
|
|
||||||
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 width, int height, int color) {
|
public HybridHRWatchfaceWidget(String widgetType, int posX, int posY, int width, int height, int color, JSONObject extraConfig) {
|
||||||
this.widgetType = widgetType;
|
this.widgetType = widgetType;
|
||||||
this.posX = posX;
|
this.posX = posX;
|
||||||
this.posY = posY;
|
this.posY = posY;
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
this.extraConfig = extraConfig;
|
||||||
}
|
}
|
||||||
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 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static LinkedHashMap<String, String> getAvailableWidgetTypes(Context context) {
|
public static LinkedHashMap<String, String> getAvailableWidgetTypes(Context context) {
|
||||||
LinkedHashMap<String, String> widgetTypes = new LinkedHashMap<>();
|
LinkedHashMap<String, String> widgetTypes = new LinkedHashMap<>();
|
||||||
@ -125,16 +115,25 @@ public class HybridHRWatchfaceWidget {
|
|||||||
this.color = color;
|
this.color = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTimezone() {
|
public int getExtraConfigInt(String name, int fallback) {
|
||||||
return timezone;
|
if (extraConfig == null) {
|
||||||
|
return fallback;
|
||||||
|
} else {
|
||||||
|
return extraConfig.optInt(name, fallback);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public int getUpdateTimeout() {
|
public String getExtraConfigString(String name, String fallback) {
|
||||||
return updateTimeout;
|
if (extraConfig == null) {
|
||||||
|
return fallback;
|
||||||
|
} else {
|
||||||
|
return extraConfig.optString(name, fallback);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public boolean getTimeoutHideText() {
|
public Boolean getExtraConfigBoolean(String name, Boolean fallback) {
|
||||||
return timeoutHideText;
|
if (extraConfig == null) {
|
||||||
}
|
return fallback;
|
||||||
public boolean getTimeoutShowCircle() {
|
} else {
|
||||||
return timeoutShowCircle;
|
return extraConfig.optBoolean(name, fallback);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user