1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-06-08 14:18:08 +02:00

Fossil Hybrid HR: Add power saving feature

This commit is contained in:
Arjan Schrijver 2021-08-09 14:27:38 +02:00 committed by Gitea
parent 2e3c409e02
commit feadeb8139
7 changed files with 111 additions and 28 deletions

View File

@ -401,6 +401,12 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
if (watchfaceConfig.has("wrist_flick_move_minute")) {
watchfaceSettings.setWristFlickMoveMinute(watchfaceConfig.getInt("wrist_flick_move_minute"));
}
if (watchfaceConfig.has("powersave_display")) {
watchfaceSettings.setPowersaveDisplay(watchfaceConfig.getBoolean("powersave_display"));
}
if (watchfaceConfig.has("powersave_hands")) {
watchfaceSettings.setPowersaveHands(watchfaceConfig.getBoolean("powersave_hands"));
}
} catch (JSONException e) {
LOG.warn("JSON parsing error", e);
}
@ -643,6 +649,10 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
wristFlickMoveHourInput.setText(String.valueOf(watchfaceSettings.getWristFlickMoveHour()));
final EditText wristFlickMoveMinuteInput = layout.findViewById(R.id.watchface_setting_flick_minute);
wristFlickMoveMinuteInput.setText(String.valueOf(watchfaceSettings.getWristFlickMoveMinute()));
final CheckBox powersaveDisplayInput = layout.findViewById(R.id.watchface_setting_powersave_display);
powersaveDisplayInput.setChecked(watchfaceSettings.getPowersaveDisplay());
final CheckBox powersaveHandsInput = layout.findViewById(R.id.watchface_setting_powersave_hands);
powersaveHandsInput.setChecked(watchfaceSettings.getPowersaveHands());
new AlertDialog.Builder(this)
.setView(layout)
.setNegativeButton(R.string.fossil_hr_new_action_cancel, null)
@ -655,6 +665,8 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
watchfaceSettings.setWristFlickDuration(Integer.parseInt(wristFlickDurationInput.getText().toString()));
watchfaceSettings.setWristFlickMoveHour(Integer.parseInt(wristFlickMoveHourInput.getText().toString()));
watchfaceSettings.setWristFlickMoveMinute(Integer.parseInt(wristFlickMoveMinuteInput.getText().toString()));
watchfaceSettings.setPowersaveDisplay(powersaveDisplayInput.isChecked());
watchfaceSettings.setPowersaveHands(powersaveHandsInput.isChecked());
}
})
.setTitle(R.string.watchface_dialog_title_settings)

View File

@ -116,45 +116,57 @@ public class HybridHRWatchfaceFactory {
}
}
private boolean includeWidget(String name) {
for (JSONObject widget : this.widgets) {
try {
if (widget.get("name").equals(name)) {
return true;
}
} catch (JSONException e) {
}
}
return false;
}
public byte[] getWapp(Context context) throws IOException {
byte[] backgroundBytes = ImageConverter.encodeToRawImage(ImageConverter.get2BitsRAWImageBytes(background));
InputStream backgroundStream = new ByteArrayInputStream(backgroundBytes);
LinkedHashMap<String, InputStream> code = new LinkedHashMap<>();
try {
code.put(watchfaceName, context.getAssets().open("fossil_hr/openSourceWatchface.bin"));
code.put("widgetDate", context.getAssets().open("fossil_hr/widgetDate.bin"));
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"));
code.put("widgetActiveMins", context.getAssets().open("fossil_hr/widgetActiveMins.bin"));
code.put("widgetChanceOfRain", context.getAssets().open("fossil_hr/widgetChanceOfRain.bin"));
code.put("widget2ndTZ", context.getAssets().open("fossil_hr/widget2ndTZ.bin"));
if (includeWidget("widgetDate")) code.put("widgetDate", context.getAssets().open("fossil_hr/widgetDate.bin"));
if (includeWidget("widgetWeather")) code.put("widgetWeather", context.getAssets().open("fossil_hr/widgetWeather.bin"));
if (includeWidget("widgetSteps")) code.put("widgetSteps", context.getAssets().open("fossil_hr/widgetSteps.bin"));
if (includeWidget("widgetHR")) code.put("widgetHR", context.getAssets().open("fossil_hr/widgetHR.bin"));
if (includeWidget("widgetBattery")) code.put("widgetBattery", context.getAssets().open("fossil_hr/widgetBattery.bin"));
if (includeWidget("widgetCalories")) code.put("widgetCalories", context.getAssets().open("fossil_hr/widgetCalories.bin"));
if (includeWidget("widgetActiveMins")) code.put("widgetActiveMins", context.getAssets().open("fossil_hr/widgetActiveMins.bin"));
if (includeWidget("widgetChanceOfRain")) code.put("widgetChanceOfRain", context.getAssets().open("fossil_hr/widgetChanceOfRain.bin"));
if (includeWidget("widget2ndTZ")) code.put("widget2ndTZ", context.getAssets().open("fossil_hr/widget2ndTZ.bin"));
} catch (IOException e) {
LOG.warn("Unable to read asset file", e);
}
LinkedHashMap<String, InputStream> icons = new LinkedHashMap<>();
try {
icons.put("background.raw", backgroundStream);
icons.put("icWthClearDay", context.getAssets().open("fossil_hr/icWthClearDay.rle"));
icons.put("icWthClearNite", context.getAssets().open("fossil_hr/icWthClearNite.rle"));
icons.put("icWthCloudy", context.getAssets().open("fossil_hr/icWthCloudy.rle"));
icons.put("icWthPartCloudyDay", context.getAssets().open("fossil_hr/icWthPartCloudyDay.rle"));
icons.put("icWthPartCloudyNite", context.getAssets().open("fossil_hr/icWthPartCloudyNite.rle"));
icons.put("icWthRainy", context.getAssets().open("fossil_hr/icWthRainy.rle"));
icons.put("icWthSnowy", context.getAssets().open("fossil_hr/icWthSnowy.rle"));
icons.put("icWthStormy", context.getAssets().open("fossil_hr/icWthStormy.rle"));
icons.put("icWthWindy", context.getAssets().open("fossil_hr/icWthWindy.rle"));
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"));
icons.put("icActiveMins", context.getAssets().open("fossil_hr/icActiveMins.rle"));
icons.put("icRainChance", context.getAssets().open("fossil_hr/icRainChance.rle"));
if (includeWidget("widgetWeather")) icons.put("icWthClearDay", context.getAssets().open("fossil_hr/icWthClearDay.rle"));
if (includeWidget("widgetWeather")) icons.put("icWthClearNite", context.getAssets().open("fossil_hr/icWthClearNite.rle"));
if (includeWidget("widgetWeather")) icons.put("icWthCloudy", context.getAssets().open("fossil_hr/icWthCloudy.rle"));
if (includeWidget("widgetWeather")) icons.put("icWthPartCloudyDay", context.getAssets().open("fossil_hr/icWthPartCloudyDay.rle"));
if (includeWidget("widgetWeather")) icons.put("icWthPartCloudyNite", context.getAssets().open("fossil_hr/icWthPartCloudyNite.rle"));
if (includeWidget("widgetWeather")) icons.put("icWthRainy", context.getAssets().open("fossil_hr/icWthRainy.rle"));
if (includeWidget("widgetWeather")) icons.put("icWthSnowy", context.getAssets().open("fossil_hr/icWthSnowy.rle"));
if (includeWidget("widgetWeather")) icons.put("icWthStormy", context.getAssets().open("fossil_hr/icWthStormy.rle"));
if (includeWidget("widgetWeather")) icons.put("icWthWindy", context.getAssets().open("fossil_hr/icWthWindy.rle"));
if (includeWidget("widgetSteps")) icons.put("icSteps", context.getAssets().open("fossil_hr/icSteps.rle"));
if (includeWidget("widgetHR")) icons.put("icHeart", context.getAssets().open("fossil_hr/icHeart.rle"));
if (includeWidget("widgetBattery")) icons.put("icBattCharging", context.getAssets().open("fossil_hr/icBattCharging.rle"));
if (includeWidget("widgetBattery")) icons.put("icBattEmpty", context.getAssets().open("fossil_hr/icBattEmpty.rle"));
if (includeWidget("widgetBattery")) icons.put("icBattery", context.getAssets().open("fossil_hr/icBattery.rle"));
if (includeWidget("widgetCalories")) icons.put("icCalories", context.getAssets().open("fossil_hr/icCalories.rle"));
if (includeWidget("widgetActiveMins")) icons.put("icActiveMins", context.getAssets().open("fossil_hr/icActiveMins.rle"));
if (includeWidget("widgetChanceOfRain")) icons.put("icRainChance", context.getAssets().open("fossil_hr/icRainChance.rle"));
} catch (IOException e) {
LOG.warn("Unable to read asset file", e);
}
@ -170,7 +182,7 @@ public class HybridHRWatchfaceFactory {
LOG.warn("Could not generate image_layout", e);
}
try {
layout.put("battery_layout", getBatteryLayout());
if (includeWidget("widgetBattery")) layout.put("battery_layout", getBatteryLayout());
} catch (JSONException e) {
LOG.warn("Could not generate battery_layout", e);
}
@ -393,6 +405,8 @@ public class HybridHRWatchfaceFactory {
config.put("wrist_flick_duration", settings.getWristFlickDuration());
config.put("wrist_flick_move_hour", settings.getWristFlickMoveHour());
config.put("wrist_flick_move_minute", settings.getWristFlickMoveMinute());
config.put("powersave_display", settings.getPowersaveDisplay());
config.put("powersave_hands", settings.getPowersaveHands());
configuration.put("config", config);
return configuration.toString();

View File

@ -23,6 +23,8 @@ public class HybridHRWatchfaceSettings {
private int wristFlickDuration = 2200;
private int wristFlickMoveHour = 360;
private int wristFlickMoveMinute = -360;
private boolean powersaveDisplay = false;
private boolean powersaveHands = false;
public HybridHRWatchfaceSettings() {
}
@ -86,4 +88,20 @@ public class HybridHRWatchfaceSettings {
this.wristFlickMoveMinute = wristFlickMoveMinute;
}
}
public boolean getPowersaveDisplay() {
return powersaveDisplay;
}
public void setPowersaveDisplay(boolean powersaveDisplay) {
this.powersaveDisplay = powersaveDisplay;
}
public boolean getPowersaveHands() {
return powersaveHands;
}
public void setPowersaveHands(boolean powersaveHands) {
this.powersaveHands = powersaveHands;
}
}

View File

@ -119,4 +119,40 @@
android:inputType="number"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/watchface_setting_title_power_saving"
android:textSize="20dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/watchface_setting_power_saving_display" />
<CheckBox
android:id="@+id/watchface_setting_powersave_display"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/watchface_setting_power_saving_hands" />
<CheckBox
android:id="@+id/watchface_setting_powersave_hands"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>

View File

@ -1251,4 +1251,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_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>
</resources>

@ -1 +1 @@
Subproject commit 15aeb1e72595fb285702878632d8a9e42b0eb181
Subproject commit 8783cfcbbca8282825e25e577467123462175713