Fossil/Skagen Hybrids: Add UV index and chance of rain widgets

Note: this needs support from weather apps, for example:
https://github.com/TylerWilliamson/QuickWeather/pull/69
This commit is contained in:
Arjan Schrijver 2023-06-18 22:11:07 +02:00
parent ff563022f5
commit 2081463a4f
11 changed files with 66 additions and 5 deletions

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

@ -47,7 +47,7 @@ public class FossilAppWriter {
this.mContext = context;
if (this.mContext == null) throw new AssertionError("context cannot be null");
this.version = version;
if (!this.version.matches("^[0-9]\\.[0-9]$")) throw new AssertionError("Version must be in x.x format");
if (!this.version.matches("^[0-9]\\.[0-9]+$")) throw new AssertionError("Version must be in x.x format");
this.code = code;
if (this.code.size() == 0) throw new AssertionError("At least one code file InputStream must be supplied");
this.icons = icons;

View File

@ -103,11 +103,12 @@ public class HybridHRWatchfaceFactory {
case "widgetCalories":
case "widgetActiveMins":
case "widgetChanceOfRain":
case "widgetUV":
widget.put("type", "comp");
widget.put("name", widgetDesc.getWidgetType());
widget.put("goal_ring", false);
widget.put("color", widgetDesc.getColor() == HybridHRWatchfaceWidget.COLOR_WHITE ? "white" : "black");
if (widgetDesc.getBackground() != "") {
if (!widgetDesc.getBackground().equals("")) {
widget.put("bg", widgetDesc.getBackground() + widgetDesc.getColor() + ".rle");
}
break;
@ -184,6 +185,7 @@ public class HybridHRWatchfaceFactory {
if (includeWidget("widgetCalories") > 0) code.put("widgetCalories", context.getAssets().open("fossil_hr/widgetCalories.bin"));
if (includeWidget("widgetActiveMins") > 0) code.put("widgetActiveMins", context.getAssets().open("fossil_hr/widgetActiveMins.bin"));
if (includeWidget("widgetChanceOfRain") > 0) code.put("widgetChanceOfRain", context.getAssets().open("fossil_hr/widgetChanceOfRain.bin"));
if (includeWidget("widgetUV") > 0) code.put("widgetUV", context.getAssets().open("fossil_hr/widgetUV.bin"));
for (int i=0; i<includeWidget("widget2ndTZ"); i++) {
code.put("widget2ndTZ" + i, context.getAssets().open("fossil_hr/widget2ndTZ.bin"));
}

View File

@ -76,8 +76,9 @@ public class HybridHRWatchfaceWidget implements Serializable {
widgetTypes.put("widgetCalories", context.getString(R.string.watchface_widget_type_calories));
widgetTypes.put("widget2ndTZ", context.getString(R.string.watchface_widget_type_2nd_tz));
widgetTypes.put("widgetActiveMins", context.getString(R.string.watchface_widget_type_active_mins));
widgetTypes.put("widgetChanceOfRain", context.getString(R.string.watchface_widget_type_chance_rain));
widgetTypes.put("widgetUV", context.getString(R.string.watchface_widget_type_uv_index));
widgetTypes.put("widgetCustom", context.getString(R.string.watchface_widget_type_custom));
// widgetTypes.put("widgetChanceOfRain", context.getString(R.string.watchface_widget_type_chance_rain)); // Disabled due to missing support in Gadgetbridge
return widgetTypes;
}

View File

@ -22,7 +22,7 @@ import java.util.Map;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
public final class QHybridConstants {
public static final String HYBRIDHR_WATCHFACE_VERSION = "1.9";
public static final String HYBRIDHR_WATCHFACE_VERSION = "1.10";
public static final int HYBRID_HR_WATCHFACE_WIDGET_SIZE = 76;
public static Map<String, String> KNOWN_WAPP_VERSIONS = new HashMap<String, String>() {

View File

@ -1502,6 +1502,46 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
}
}
public void onSendChanceOfRain(WeatherSpec weatherSpec) {
long ts = System.currentTimeMillis();
ts /= 1000;
try {
JSONObject rainObject = new JSONObject()
.put("res", new JSONObject()
.put("set", new JSONObject()
.put("widgetChanceOfRain._.config.info", new JSONObject()
.put("alive", ts + 60 * 15)
.put("rain", weatherSpec.precipProbability)
)
)
);
queueWrite(new JsonPutRequest(rainObject, this));
} catch (JSONException e) {
LOG.error("JSON exception: ", e);
}
}
public void onSendUVIndex(WeatherSpec weatherSpec) {
long ts = System.currentTimeMillis();
ts /= 1000;
try {
JSONObject rainObject = new JSONObject()
.put("res", new JSONObject()
.put("set", new JSONObject()
.put("widgetUV._.config.info", new JSONObject()
.put("alive", ts + 60 * 15)
.put("uv", Math.round(weatherSpec.uvIndex))
)
)
);
queueWrite(new JsonPutRequest(rainObject, this));
} catch (JSONException e) {
LOG.error("JSON exception: ", e);
}
}
@Override
public void factoryReset() {
queueWrite(new FactoryResetRequest());
@ -1810,6 +1850,22 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
} else {
LOG.info("no weather data available - ignoring request");
}
} else if (request.has("widgetChanceOfRain._.config.info")) {
LOG.info("Got widgetChanceOfRain request");
WeatherSpec weatherSpec = Weather.getInstance().getWeatherSpec();
if (weatherSpec != null) {
onSendChanceOfRain(weatherSpec);
} else {
LOG.info("no weather data available - ignoring request");
}
} else if (request.has("widgetUV._.config.info")) {
LOG.info("Got widgetUV request");
WeatherSpec weatherSpec = Weather.getInstance().getWeatherSpec();
if (weatherSpec != null) {
onSendUVIndex(weatherSpec);
} else {
LOG.info("no weather data available - ignoring request");
}
} else if (request.has("commuteApp._.config.commute_info")) {
String action = request.getJSONObject("commuteApp._.config.commute_info")
.getString("dest");

View File

@ -1779,6 +1779,7 @@
<string name="watchface_widget_type_2nd_tz">2nd time zone</string>
<string name="watchface_widget_type_active_mins">Active minutes</string>
<string name="watchface_widget_type_chance_rain">Chance of rain</string>
<string name="watchface_widget_type_uv_index">UV index</string>
<string name="watchface_setting_title_power_saving">Power saving</string>
<string name="watchface_setting_power_saving_display">Disable display updates while off wrist</string>
<string name="watchface_setting_power_saving_hands">Disable hands movement while off wrist</string>

View File

@ -16,6 +16,7 @@ $jerry generate -f '' widget_calories.js -o widgetCalories.bin
$jerry generate -f '' widget_2nd_tz.js -o widget2ndTZ.bin
$jerry generate -f '' widget_activemins.js -o widgetActiveMins.bin
$jerry generate -f '' widget_chanceofrain.js -o widgetChanceOfRain.bin
$jerry generate -f '' widget_uv.js -o widgetUV.bin
$jerry generate -f '' widget_custom.js -o widgetCustom.bin
popd
mv fossil-hr-watchface/*.bin ../app/src/main/assets/fossil_hr/

@ -1 +1 @@
Subproject commit 1a58411e8fe32d1a1a80982fdc5775b4529cf8d1
Subproject commit b66f0629e78e87df8cb7c793f972e3bee57cd44d