mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-23 18:36:50 +01:00
Fossil Hybrid HR: Add update timeout to custom widget
This commit is contained in:
parent
dde34a35db
commit
d1062a30b2
Binary file not shown.
@ -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());
|
||||
}
|
||||
|
@ -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");
|
||||
|
@ -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<String, String> getAvailableWidgetTypes(Context context) {
|
||||
@ -98,4 +103,7 @@ public class HybridHRWatchfaceWidget {
|
||||
public String getTimezone() {
|
||||
return timezone;
|
||||
}
|
||||
public int getUpdateTimeout() {
|
||||
return updateTimeout;
|
||||
}
|
||||
}
|
||||
|
@ -84,11 +84,27 @@
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Time zone:" />
|
||||
android:text="@string/watchface_dialog_widget_timezone" />
|
||||
<Spinner
|
||||
android:id="@+id/watchface_widget_timezone_spinner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/watchface_widget_update_timeout_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_update_timeout" />
|
||||
<EditText
|
||||
android:id="@+id/watchface_widget_update_timeout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="number"/>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -1388,5 +1388,7 @@
|
||||
<string name="sony_automatic_power_off_3_hour">3 hours</string>
|
||||
<string name="sony_automatic_power_off_when_taken_off">When taken off</string>
|
||||
<string name="watchface_widget_type_custom">Custom widget</string>
|
||||
<string name="watchface_dialog_widget_timezone">Time zone:</string>
|
||||
<string name="watchface_dialog_widget_update_timeout">Update timeout in minutes:</string>
|
||||
|
||||
</resources>
|
||||
|
2
external/fossil-hr-watchface
vendored
2
external/fossil-hr-watchface
vendored
@ -1 +1 @@
|
||||
Subproject commit 6270e0478c1aa5cd3fde75567d9a1f00bdddb9c5
|
||||
Subproject commit 8855d1735b07939f483759cb7e836a8418f30515
|
Loading…
Reference in New Issue
Block a user