mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-24 02:46: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")) {
|
if (layoutItem.getString("type").equals("comp")) {
|
||||||
String widgetName = layoutItem.getString("name");
|
String widgetName = layoutItem.getString("name");
|
||||||
String widgetTimezone = null;
|
String widgetTimezone = null;
|
||||||
|
int widgetUpdateTimeout = -1;
|
||||||
switch (widgetName) {
|
switch (widgetName) {
|
||||||
case "dateSSE":
|
case "dateSSE":
|
||||||
widgetName = "widgetDate";
|
widgetName = "widgetDate";
|
||||||
@ -381,24 +382,35 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
|
|||||||
widgetName = "widget2ndTZ";
|
widgetName = "widget2ndTZ";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
int widgetColor = layoutItem.getString("color").equals("white") ? HybridHRWatchfaceWidget.COLOR_WHITE : HybridHRWatchfaceWidget.COLOR_BLACK;
|
||||||
if (widgetName.startsWith("widget2ndTZ")) {
|
if (widgetName.startsWith("widget2ndTZ")) {
|
||||||
try {
|
try {
|
||||||
widgetName = "widget2ndTZ";
|
widgetName = "widget2ndTZ";
|
||||||
JSONObject widgetData = layoutItem.getJSONObject("data");
|
JSONObject widgetData = layoutItem.getJSONObject("data");
|
||||||
widgetTimezone = widgetData.getString("tzName");
|
widgetTimezone = widgetData.getString("tzName");
|
||||||
|
widgets.add(new HybridHRWatchfaceWidget(widgetName,
|
||||||
|
layoutItem.getJSONObject("pos").getInt("x"),
|
||||||
|
layoutItem.getJSONObject("pos").getInt("y"),
|
||||||
|
widgetColor,
|
||||||
|
widgetTimezone));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
LOG.error("Couldn't determine tzName!", e);
|
LOG.error("Couldn't determine tzName!", e);
|
||||||
}
|
}
|
||||||
}
|
} else if (widgetName.startsWith("widgetCustom")) {
|
||||||
if (widgetName.startsWith("widgetCustom")) {
|
|
||||||
widgetName = "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) {
|
} catch (JSONException e) {
|
||||||
@ -596,7 +608,14 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
|
|||||||
} else {
|
} else {
|
||||||
tzSpinner.setSelection(Arrays.asList(timezonesList).indexOf("Etc/UTC"));
|
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() {
|
typeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||||
@ -606,6 +625,11 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
|
|||||||
} else {
|
} else {
|
||||||
timezoneLayout.setVisibility(View.GONE);
|
timezoneLayout.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
if (selectedType.equals("widgetCustom")) {
|
||||||
|
updateTimeoutLayout.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
updateTimeoutLayout.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onNothingSelected(AdapterView<?> parent) { }
|
public void onNothingSelected(AdapterView<?> parent) { }
|
||||||
@ -641,9 +665,19 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
|
|||||||
if (selectedPosY > 240) selectedPosY = 240;
|
if (selectedPosY > 240) selectedPosY = 240;
|
||||||
String selectedType = widgetTypesArray.get(typeSpinner.getSelectedItemPosition());
|
String selectedType = widgetTypesArray.get(typeSpinner.getSelectedItemPosition());
|
||||||
String selectedTZ = tzSpinner.getSelectedItem().toString();
|
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;
|
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, colorSpinner.getSelectedItemPosition(), selectedTZ);
|
||||||
|
} else if (selectedType.equals("widgetCustom")) {
|
||||||
|
widgetConfig = new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY, colorSpinner.getSelectedItemPosition(), selectedUpdateTimeout);
|
||||||
} else {
|
} else {
|
||||||
widgetConfig = new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY, colorSpinner.getSelectedItemPosition());
|
widgetConfig = new HybridHRWatchfaceWidget(selectedType, selectedPosX, selectedPosY, colorSpinner.getSelectedItemPosition());
|
||||||
}
|
}
|
||||||
|
@ -76,6 +76,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) {
|
||||||
|
JSONObject data = new JSONObject();
|
||||||
|
data.put("update_timeout", widgetDesc.getUpdateTimeout());
|
||||||
|
widget.put("data", data);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "widget2ndTZ":
|
case "widget2ndTZ":
|
||||||
widget.put("type", "comp");
|
widget.put("type", "comp");
|
||||||
|
@ -33,6 +33,7 @@ public class HybridHRWatchfaceWidget {
|
|||||||
private int posY;
|
private int posY;
|
||||||
private int color = 0;
|
private int color = 0;
|
||||||
private String timezone;
|
private String timezone;
|
||||||
|
private int updateTimeout = -1;
|
||||||
|
|
||||||
public static int COLOR_WHITE = 0;
|
public static int COLOR_WHITE = 0;
|
||||||
public static int COLOR_BLACK = 1;
|
public static int COLOR_BLACK = 1;
|
||||||
@ -47,6 +48,10 @@ public class HybridHRWatchfaceWidget {
|
|||||||
this(widgetType, posX, posY, color);
|
this(widgetType, posX, posY, color);
|
||||||
this.timezone = timezone;
|
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) {
|
public static LinkedHashMap<String, String> getAvailableWidgetTypes(Context context) {
|
||||||
@ -98,4 +103,7 @@ public class HybridHRWatchfaceWidget {
|
|||||||
public String getTimezone() {
|
public String getTimezone() {
|
||||||
return timezone;
|
return timezone;
|
||||||
}
|
}
|
||||||
|
public int getUpdateTimeout() {
|
||||||
|
return updateTimeout;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,11 +84,27 @@
|
|||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Time zone:" />
|
android:text="@string/watchface_dialog_widget_timezone" />
|
||||||
<Spinner
|
<Spinner
|
||||||
android:id="@+id/watchface_widget_timezone_spinner"
|
android:id="@+id/watchface_widget_timezone_spinner"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
</LinearLayout>
|
</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>
|
</LinearLayout>
|
||||||
|
@ -1388,5 +1388,7 @@
|
|||||||
<string name="sony_automatic_power_off_3_hour">3 hours</string>
|
<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="sony_automatic_power_off_when_taken_off">When taken off</string>
|
||||||
<string name="watchface_widget_type_custom">Custom widget</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>
|
</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