From 6a680717022648eae1950963dd0ca17b43d8f99b Mon Sep 17 00:00:00 2001 From: a0z Date: Tue, 3 Dec 2024 09:11:50 +0100 Subject: [PATCH] Workout page: hr zones add colors --- .../entries/ActivitySummaryProgressEntry.java | 10 ++++++++++ .../devices/garmin/GarminWorkoutParser.java | 12 +++++++++++- .../zeppos/ZeppOsActivitySummaryParser.java | 19 ++++++++++++++++++- .../huami/zeppos/ZeppOsCoordinator.java | 2 +- .../devices/huawei/HuaweiBRCoordinator.java | 2 +- .../devices/huawei/HuaweiLECoordinator.java | 2 +- .../huawei/HuaweiSettingsCustomizer.java | 2 +- .../devices/huawei/HuaweiSupportProvider.java | 2 +- .../devices/huawei/HuaweiWorkoutGbParser.java | 15 +++++++++++++-- .../requests/GetWorkoutDataRequest.java | 2 +- .../requests/GetWorkoutPaceRequest.java | 2 +- .../GetWorkoutSwimSegmentsRequest.java | 2 +- .../requests/GetWorkoutTotalsRequest.java | 2 +- app/src/main/res/values/colors.xml | 6 ++++++ 14 files changed, 67 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/workouts/entries/ActivitySummaryProgressEntry.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/workouts/entries/ActivitySummaryProgressEntry.java index 85768ffc8..b1fbcb8e7 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/workouts/entries/ActivitySummaryProgressEntry.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/workouts/entries/ActivitySummaryProgressEntry.java @@ -1,6 +1,7 @@ package nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries; import android.content.Context; +import android.content.res.ColorStateList; import android.view.Gravity; import android.view.View; import android.widget.LinearLayout; @@ -11,6 +12,7 @@ import nodomain.freeyourgadget.gadgetbridge.activities.workouts.WorkoutValueForm public class ActivitySummaryProgressEntry extends ActivitySummarySimpleEntry { private final int progress; + private int color; public ActivitySummaryProgressEntry(final Object value, final String unit, final int progress) { this(null, value, unit, progress); @@ -21,6 +23,11 @@ public class ActivitySummaryProgressEntry extends ActivitySummarySimpleEntry { this.progress = progress; } + public ActivitySummaryProgressEntry(final Object value, final String unit, final int progress, final int color) { + this(null, value, unit, progress); + this.color = color; + } + public int getProgress() { return progress; } @@ -59,6 +66,9 @@ public class ActivitySummaryProgressEntry extends ActivitySummarySimpleEntry { progressBar.setIndeterminate(false); progressBar.setProgress(progress); progressBar.setVisibility(View.VISIBLE); + if (color != 0) { + progressBar.setProgressTintList(ColorStateList.valueOf(color)); + } LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); progressLayout.addView(progressBar, params); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/garmin/GarminWorkoutParser.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/garmin/GarminWorkoutParser.java index 97433a4b6..ae95af115 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/garmin/GarminWorkoutParser.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/garmin/GarminWorkoutParser.java @@ -16,6 +16,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Optional; +import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries.ActivitySummaryProgressEntry; import nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries.ActivitySummaryTableRowEntry; import nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries.ActivitySummaryValue; @@ -246,6 +247,14 @@ public class GarminWorkoutParser implements ActivitySummaryParser { continue; } final List zoneOrder = Arrays.asList(HR_ZONE_NA, HR_ZONE_WARM_UP, HR_ZONE_EASY, HR_ZONE_AEROBIC, HR_ZONE_THRESHOLD, HR_ZONE_MAXIMUM); + final int[] zoneColors = new int[]{ + 0, + context.getResources().getColor(R.color.hr_zone_warm_up_color), + context.getResources().getColor(R.color.hr_zone_easy_color), + context.getResources().getColor(R.color.hr_zone_aerobic_color), + context.getResources().getColor(R.color.hr_zone_threshold_color), + context.getResources().getColor(R.color.hr_zone_maximum_color), + }; for (int i = 0; i < zoneOrder.size(); i++) { double timeInZone = timeInZones[i] != null ? Math.rint(timeInZones[i]) : 0; summaryData.add( @@ -253,7 +262,8 @@ public class GarminWorkoutParser implements ActivitySummaryParser { new ActivitySummaryProgressEntry( timeInZone, UNIT_SECONDS, - (int) (100 * timeInZone / totalTime) + (int) (100 * timeInZone / totalTime), + zoneColors[i] ) ); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/zeppos/ZeppOsActivitySummaryParser.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/zeppos/ZeppOsActivitySummaryParser.java index 889a99f9d..fc6244ea1 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/zeppos/ZeppOsActivitySummaryParser.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/zeppos/ZeppOsActivitySummaryParser.java @@ -18,6 +18,8 @@ package nodomain.freeyourgadget.gadgetbridge.devices.huami.zeppos; import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.*; +import android.content.Context; + import com.google.protobuf.InvalidProtocolBufferException; import org.apache.commons.lang3.ArrayUtils; @@ -28,6 +30,7 @@ import java.util.Arrays; import java.util.Date; import java.util.List; +import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.activities.workouts.entries.ActivitySummaryProgressEntry; import nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiActivitySummaryParser; import nodomain.freeyourgadget.gadgetbridge.proto.HuamiProtos; @@ -39,12 +42,17 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.huami.zeppos.ZeppOsA public class ZeppOsActivitySummaryParser extends HuamiActivitySummaryParser { private static final Logger LOG = LoggerFactory.getLogger(ZeppOsActivitySummaryParser.class); + private final Context context; @Override public AbstractHuamiActivityDetailsParser getDetailsParser(final BaseActivitySummary summary) { return new ZeppOsActivityDetailsParser(summary); } + public ZeppOsActivitySummaryParser(final Context context) { + this.context = context; + } + @Override protected void parseBinaryData(final BaseActivitySummary summary, final Date startTime) { final byte[] rawData = summary.getRawSummaryData(); @@ -130,13 +138,22 @@ public class ZeppOsActivitySummaryParser extends HuamiActivitySummaryParser { .sum(); final List zoneOrder = Arrays.asList(HR_ZONE_NA, HR_ZONE_WARM_UP, HR_ZONE_FAT_BURN, HR_ZONE_AEROBIC, HR_ZONE_ANAEROBIC, HR_ZONE_EXTREME); + final int[] zoneColors = new int[]{ + 0, + context.getResources().getColor(R.color.hr_zone_warm_up_color), + context.getResources().getColor(R.color.hr_zone_easy_color), + context.getResources().getColor(R.color.hr_zone_aerobic_color), + context.getResources().getColor(R.color.hr_zone_threshold_color), + context.getResources().getColor(R.color.hr_zone_maximum_color), + }; for (int i = 0; i < zoneOrder.size(); i++) { summaryData.add( zoneOrder.get(i), new ActivitySummaryProgressEntry( summaryProto.getHeartRateZones().getZoneTime(i), UNIT_SECONDS, - (int) ((100 * summaryProto.getHeartRateZones().getZoneTime(i)) / totalTime) + (int) ((100 * summaryProto.getHeartRateZones().getZoneTime(i)) / totalTime), + zoneColors[i] ) ); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/zeppos/ZeppOsCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/zeppos/ZeppOsCoordinator.java index a8ae35d13..5fa92ea10 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/zeppos/ZeppOsCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huami/zeppos/ZeppOsCoordinator.java @@ -321,7 +321,7 @@ public abstract class ZeppOsCoordinator extends HuamiCoordinator { @Override public ActivitySummaryParser getActivitySummaryParser(final GBDevice device, final Context context) { - return new ZeppOsActivitySummaryParser(); + return new ZeppOsActivitySummaryParser(context); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiBRCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiBRCoordinator.java index 51acb6f8a..6a49b498c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiBRCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiBRCoordinator.java @@ -205,7 +205,7 @@ public abstract class HuaweiBRCoordinator extends AbstractBLClassicDeviceCoordin @Override public ActivitySummaryParser getActivitySummaryParser(final GBDevice device, final Context context) { - return new HuaweiWorkoutGbParser(device); + return new HuaweiWorkoutGbParser(device, context); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiLECoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiLECoordinator.java index 109c42f39..a9b7ad201 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiLECoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiLECoordinator.java @@ -214,7 +214,7 @@ public abstract class HuaweiLECoordinator extends AbstractBLEDeviceCoordinator i @Override public ActivitySummaryParser getActivitySummaryParser(final GBDevice device, final Context context) { - return new HuaweiWorkoutGbParser(device); + return new HuaweiWorkoutGbParser(device, context); } @Override diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiSettingsCustomizer.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiSettingsCustomizer.java index 85d289d5e..ed1ecf507 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiSettingsCustomizer.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/huawei/HuaweiSettingsCustomizer.java @@ -70,7 +70,7 @@ public class HuaweiSettingsCustomizer implements DeviceSpecificSettingsCustomize if (preference.getKey().equals("huawei_reparse_workout_data")) { if (((SwitchPreferenceCompat) preference).isChecked()) { GB.toast("Starting workout reparse", Toast.LENGTH_SHORT, 0); - new HuaweiWorkoutGbParser(handler.getDevice()).parseAllWorkouts(); + new HuaweiWorkoutGbParser(handler.getDevice(), handler.getContext()).parseAllWorkouts(); GB.toast("Workout reparse is complete", Toast.LENGTH_SHORT, 0); ((SwitchPreferenceCompat) preference).setChecked(false); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java index c58a531d7..e41cc59b6 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiSupportProvider.java @@ -2443,7 +2443,7 @@ public class HuaweiSupportProvider { return; } - new HuaweiWorkoutGbParser(getDevice()).parseWorkout(databaseId); + new HuaweiWorkoutGbParser(getDevice(), getContext()).parseWorkout(databaseId); LOG.debug("Completed workout GPS parsing and inserting"); syncState.stopWorkoutGpsDownload(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiWorkoutGbParser.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiWorkoutGbParser.java index 09e8266fe..ffe48cee2 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiWorkoutGbParser.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/HuaweiWorkoutGbParser.java @@ -16,6 +16,7 @@ along with this program. If not, see . */ package nodomain.freeyourgadget.gadgetbridge.service.devices.huawei; +import android.content.Context; import android.widget.Toast; import org.slf4j.Logger; @@ -76,9 +77,11 @@ public class HuaweiWorkoutGbParser implements ActivitySummaryParser { // TODO: Might be nicer to propagate the exceptions, so they can be handled upstream private final GBDevice gbDevice; + private final Context context; - public HuaweiWorkoutGbParser(final GBDevice gbDevice) { + public HuaweiWorkoutGbParser(final GBDevice gbDevice, final Context context) { this.gbDevice = gbDevice; + this.context = context; } @Override @@ -633,6 +636,13 @@ public class HuaweiWorkoutGbParser implements ActivitySummaryParser { if(HRZonesCfg != null) { final double totalTime = Arrays.stream(HRZones).sum(); final List zoneOrder = Arrays.asList(ActivitySummaryEntries.HR_ZONE_WARM_UP, ActivitySummaryEntries.HR_ZONE_FAT_BURN, ActivitySummaryEntries.HR_ZONE_AEROBIC, ActivitySummaryEntries.HR_ZONE_ANAEROBIC, ActivitySummaryEntries.HR_ZONE_EXTREME); + final int[] zoneColors = new int[]{ + context.getResources().getColor(R.color.hr_zone_warm_up_color), + context.getResources().getColor(R.color.hr_zone_easy_color), + context.getResources().getColor(R.color.hr_zone_aerobic_color), + context.getResources().getColor(R.color.hr_zone_threshold_color), + context.getResources().getColor(R.color.hr_zone_maximum_color), + }; for (int i = zoneOrder.size() - 1; i >= 0; i--) { double timeInZone = HRZones[i]; LOG.info("Zone: {} {}", zoneOrder.get(i), timeInZone); @@ -641,7 +651,8 @@ public class HuaweiWorkoutGbParser implements ActivitySummaryParser { new ActivitySummaryProgressEntry( timeInZone, ActivitySummaryEntries.UNIT_SECONDS, - (int) (100 * timeInZone / totalTime) + (int) (100 * timeInZone / totalTime), + zoneColors[i] ) ); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetWorkoutDataRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetWorkoutDataRequest.java index 1e587e0f2..98756abdc 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetWorkoutDataRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetWorkoutDataRequest.java @@ -123,7 +123,7 @@ public class GetWorkoutDataRequest extends Request { nextRequest.setFinalizeReq(this.finalizeReq); this.nextRequest(nextRequest); } else { - new HuaweiWorkoutGbParser(getDevice()).parseWorkout(this.databaseId); + new HuaweiWorkoutGbParser(getDevice(), getContext()).parseWorkout(this.databaseId); supportProvider.downloadWorkoutGpsFiles(this.workoutNumbers.workoutNumber, this.databaseId, new Runnable() { @Override public void run() { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetWorkoutPaceRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetWorkoutPaceRequest.java index d859ca2c9..b4261b3bd 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetWorkoutPaceRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetWorkoutPaceRequest.java @@ -100,7 +100,7 @@ public class GetWorkoutPaceRequest extends Request { nextRequest.setFinalizeReq(this.finalizeReq); this.nextRequest(nextRequest); } else { - new HuaweiWorkoutGbParser(getDevice()).parseWorkout(this.databaseId); + new HuaweiWorkoutGbParser(getDevice(), getContext()).parseWorkout(this.databaseId); supportProvider.downloadWorkoutGpsFiles(this.workoutNumbers.workoutNumber, this.databaseId, new Runnable() { @Override public void run() { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetWorkoutSwimSegmentsRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetWorkoutSwimSegmentsRequest.java index bbba995d4..d636870d9 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetWorkoutSwimSegmentsRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetWorkoutSwimSegmentsRequest.java @@ -74,7 +74,7 @@ public class GetWorkoutSwimSegmentsRequest extends Request { nextRequest.setFinalizeReq(this.finalizeReq); this.nextRequest(nextRequest); } else { - new HuaweiWorkoutGbParser(getDevice()).parseWorkout(this.databaseId); + new HuaweiWorkoutGbParser(getDevice(), getContext()).parseWorkout(this.databaseId); supportProvider.downloadWorkoutGpsFiles(this.workoutNumbers.workoutNumber, this.databaseId, new Runnable() { @Override public void run() { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetWorkoutTotalsRequest.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetWorkoutTotalsRequest.java index ed49bfdbd..ff520972d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetWorkoutTotalsRequest.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/huawei/requests/GetWorkoutTotalsRequest.java @@ -114,7 +114,7 @@ public class GetWorkoutTotalsRequest extends Request { nextRequest.setFinalizeReq(this.finalizeReq); this.nextRequest(nextRequest); } else { - new HuaweiWorkoutGbParser(getDevice()).parseWorkout(databaseId); + new HuaweiWorkoutGbParser(getDevice(), getContext()).parseWorkout(databaseId); supportProvider.downloadWorkoutGpsFiles(this.workoutNumbers.workoutNumber, databaseId, new Runnable() { @Override public void run() { diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 5e22dfab8..f9b4f6ce8 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -70,6 +70,12 @@ #19808080 #19808080 + #92a4ad + #80D8FF + #66BB6A + #FF7043 + #F44336 + #FFEDEDED #545254