1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-28 11:35:48 +01:00

Fossil Hybrid HR: Add battery and calories widgets

This commit is contained in:
Arjan Schrijver 2021-07-27 14:50:06 +02:00 committed by Gitea
parent 4dd8af6d24
commit 478053288f
12 changed files with 117 additions and 1 deletions

View File

@ -0,0 +1 @@
                <0C><>

Binary file not shown.

View File

@ -0,0 +1 @@
x                    z ˙˙

View File

@ -0,0 +1,2 @@
9               
                       6 <0C><>

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View File

@ -341,7 +341,12 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
case "hrSSE":
widgetName = "widgetHR";
break;
case "batterySSE":
widgetName = "widgetBattery";
break;
case "caloriesSSE":
widgetName = "widgetCalories";
break;
}
int widgetColor = layoutItem.getString("color").equals("white") ? HybridHRWatchfaceWidget.COLOR_WHITE : HybridHRWatchfaceWidget.COLOR_BLACK;
widgets.add(new HybridHRWatchfaceWidget(widgetName,

View File

@ -90,6 +90,13 @@ public class HybridHRWatchfaceFactory {
widget.put("color", widgetDesc.getColor() == HybridHRWatchfaceWidget.COLOR_WHITE ? "white" : "black");
widget.put("bg", "_03.rle");
break;
case "widgetBattery":
case "widgetCalories":
widget.put("type", "comp");
widget.put("name", widgetDesc.getWidgetType());
widget.put("goal_ring", false);
widget.put("color", widgetDesc.getColor() == HybridHRWatchfaceWidget.COLOR_WHITE ? "white" : "black");
break;
default:
LOG.warn("Invalid widget name: " + widgetDesc.getWidgetType());
return;
@ -124,6 +131,8 @@ public class HybridHRWatchfaceFactory {
code.put("widgetWeather", context.getAssets().open("fossil_hr/widgetWeather.bin"));
code.put("widgetSteps", context.getAssets().open("fossil_hr/widgetSteps.bin"));
code.put("widgetHR", context.getAssets().open("fossil_hr/widgetHR.bin"));
code.put("widgetBattery", context.getAssets().open("fossil_hr/widgetBattery.bin"));
code.put("widgetCalories", context.getAssets().open("fossil_hr/widgetCalories.bin"));
} catch (IOException e) {
LOG.warn("Unable to read asset file", e);
}
@ -142,6 +151,10 @@ public class HybridHRWatchfaceFactory {
icons.put("icSteps", context.getAssets().open("fossil_hr/icSteps.rle"));
icons.put("icTrophy", context.getAssets().open("fossil_hr/icTrophy.rle"));
icons.put("icHeart", context.getAssets().open("fossil_hr/icHeart.rle"));
icons.put("icBattCharging", context.getAssets().open("fossil_hr/icBattCharging.rle"));
icons.put("icBattEmpty", context.getAssets().open("fossil_hr/icBattEmpty.rle"));
icons.put("icBattery", context.getAssets().open("fossil_hr/icBattery.rle"));
icons.put("icCalories", context.getAssets().open("fossil_hr/icCalories.rle"));
} catch (IOException e) {
LOG.warn("Unable to read asset file", e);
}
@ -156,6 +169,11 @@ public class HybridHRWatchfaceFactory {
} catch (JSONException e) {
LOG.warn("Could not generate image_layout", e);
}
try {
layout.put("battery_layout", getBatteryLayout());
} catch (JSONException e) {
LOG.warn("Could not generate battery_layout", e);
}
LinkedHashMap<String, String> displayName = new LinkedHashMap<>();
displayName.put("display_name", watchfaceName);
displayName.put("theme_class", "complications");
@ -169,6 +187,91 @@ public class HybridHRWatchfaceFactory {
return appWriter.getWapp();
}
private String getBatteryLayout() throws JSONException {
JSONArray batteryLayout = new JSONArray();
JSONObject complicationBackground = new JSONObject();
complicationBackground.put("id", 0);
complicationBackground.put("type", "complication_background");
complicationBackground.put("background", "#background");
complicationBackground.put("visible", true);
complicationBackground.put("inversion", false);
JSONObject goalRing = new JSONObject();
goalRing.put("is_enable", "#goal_ring");
goalRing.put("end_angle", "#fi");
goalRing.put("is_invert", "#$e");
complicationBackground.put("goal_ring", goalRing);
JSONObject dimension = new JSONObject();
dimension.put("type", "rigid");
dimension.put("width", "#size.w");
dimension.put("height", "#size.h");
complicationBackground.put("dimension", dimension);
JSONObject placement = new JSONObject();
placement.put("type", "absolute");
placement.put("left", "#pos.Ue");
placement.put("top", "#pos.Qe");
complicationBackground.put("placement", placement);
batteryLayout.put(complicationBackground);
JSONObject complicationContent = new JSONObject();
complicationContent.put("id", 1);
complicationContent.put("parent_id", 0);
complicationContent.put("type", "complication_content");
complicationContent.put("icon", "icBattery");
complicationContent.put("text_low", "#ci");
complicationContent.put("visible", true);
complicationContent.put("inversion", "#$e");
dimension = new JSONObject();
dimension.put("type", "rigid");
dimension.put("width", 76);
dimension.put("height", 76);
complicationContent.put("dimension", dimension);
placement = new JSONObject();
placement.put("type", "relative");
complicationContent.put("placement", placement);
batteryLayout.put(complicationContent);
JSONObject chargingStatus = new JSONObject();
chargingStatus.put("id", 2);
chargingStatus.put("parent_id", 1);
chargingStatus.put("type", "solid");
chargingStatus.put("color", "#nt");
chargingStatus.put("visible", true);
chargingStatus.put("inversion", false);
dimension = new JSONObject();
dimension.put("type", "rigid");
dimension.put("width", "#it");
dimension.put("height", 6);
chargingStatus.put("dimension", dimension);
placement = new JSONObject();
placement.put("type", "absolute");
placement.put("left", 29);
placement.put("top", 23);
chargingStatus.put("placement", placement);
batteryLayout.put(chargingStatus);
JSONObject image = new JSONObject();
image.put("id", 3);
image.put("parent_id", 1);
image.put("type", "image");
image.put("image_name", "icBattCharging");
image.put("draw_mode", 1);
image.put("visible", "#et");
image.put("inversion", false);
placement = new JSONObject();
placement.put("type", "absolute");
placement.put("left", 34);
placement.put("top", 21);
image.put("placement", placement);
dimension = new JSONObject();
dimension.put("width", 6);
dimension.put("height", 9);
image.put("dimension", dimension);
batteryLayout.put(image);
return batteryLayout.toString();
}
private String getComplicationLayout() throws JSONException {
JSONArray complicationLayout = new JSONArray();

View File

@ -49,6 +49,8 @@ public class HybridHRWatchfaceWidget {
widgetTypes.put("widgetWeather", context.getString(R.string.watchface_widget_type_weather));
widgetTypes.put("widgetSteps", context.getString(R.string.watchface_widget_type_steps));
widgetTypes.put("widgetHR", context.getString(R.string.watchface_widget_type_heart_rate));
widgetTypes.put("widgetBattery", context.getString(R.string.watchface_widget_type_battery));
widgetTypes.put("widgetCalories", context.getString(R.string.watchface_widget_type_calories));
return widgetTypes;
}

View File

@ -1246,4 +1246,6 @@
<string name="watchface_setting_wrist_flick_duration">Duration (in ms):</string>
<string name="watchface_cache_confirm_overwrite">A watchface with this name already exists in the cache. Do you want to overwrite it?</string>
<string name="watchface_upload_failed">Upload of the watchface failed. Please try again.</string>
<string name="watchface_widget_type_battery">Battery</string>
<string name="watchface_widget_type_calories">Calories</string>
</resources>