mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Workout details: add power chart support
This commit is contained in:
+22
@@ -7,6 +7,7 @@ import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.UNIT_MINUTES_PER_KM;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.UNIT_SECONDS_PER_KM;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.UNIT_SPM;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryEntries.UNIT_WATT;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
@@ -47,6 +48,7 @@ public class DefaultWorkoutCharts {
|
||||
final List<Entry> speedDataPoints = new ArrayList<>();
|
||||
final List<Entry> cadenceDataPoints = new ArrayList<>();
|
||||
final List<Entry> elevationDataPoints = new ArrayList<>();
|
||||
final List<Entry> powerDataPoints = new ArrayList<>();
|
||||
boolean hasSpeedValues = false;
|
||||
boolean hasCadenceValues = false;
|
||||
boolean hasElevationValues = false;
|
||||
@@ -82,6 +84,9 @@ public class DefaultWorkoutCharts {
|
||||
if (!hasCadenceValues && point.getCadence() > 0) {
|
||||
hasCadenceValues = true;
|
||||
}
|
||||
if (point.getPower() >= 0) {
|
||||
powerDataPoints.add(new Entry(tsShorten, (float) point.getPower()));
|
||||
}
|
||||
}
|
||||
|
||||
if (!heartRateDataPoints.isEmpty()) {
|
||||
@@ -100,6 +105,10 @@ public class DefaultWorkoutCharts {
|
||||
charts.add(createElevationChart(context, elevationDataPoints));
|
||||
}
|
||||
|
||||
if (!powerDataPoints.isEmpty()) {
|
||||
charts.add(createPowerChart(context, powerDataPoints));
|
||||
}
|
||||
|
||||
return charts;
|
||||
}
|
||||
|
||||
@@ -201,6 +210,19 @@ public class DefaultWorkoutCharts {
|
||||
);
|
||||
}
|
||||
|
||||
private static WorkoutChart createPowerChart(final Context context,
|
||||
final List<Entry> powerDataPoints) {
|
||||
final String label = String.format("%s (%s)", context.getString(R.string.workout_power), getUnitString(context, UNIT_WATT));
|
||||
LineDataSet dataset = createLineDataSet(context, powerDataPoints, label, context.getResources().getColor(R.color.chart_line_power));
|
||||
final ValueFormatter integerFormatter = new ValueFormatter() {
|
||||
@Override
|
||||
public String getFormattedValue(float value) {
|
||||
return String.valueOf((int) value);
|
||||
}
|
||||
};
|
||||
return new WorkoutChart("power", context.getString(R.string.workout_power), ActivitySummaryEntries.GROUP_POWER, new LineData(dataset), integerFormatter, getUnitString(context, UNIT_WATT));
|
||||
}
|
||||
|
||||
public static String getUnitString(final Context context, final String unit) {
|
||||
final int resId = context.getResources().getIdentifier(unit, "string", context.getPackageName());
|
||||
if (resId != 0) {
|
||||
|
||||
@@ -41,6 +41,7 @@ public class ActivityPoint {
|
||||
private int heartRate;
|
||||
private float speed = -1;
|
||||
private int cadence = -1;
|
||||
private int power = -1;
|
||||
|
||||
// e.g. to describe a pause during the activity
|
||||
private @Nullable String description;
|
||||
@@ -100,4 +101,12 @@ public class ActivityPoint {
|
||||
public void setCadence(final int cadence) {
|
||||
this.cadence = cadence;
|
||||
}
|
||||
|
||||
public int getPower() {
|
||||
return power;
|
||||
}
|
||||
|
||||
public void setPower(final int power) {
|
||||
this.power = power;
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -347,6 +347,9 @@ public class FitRecord extends RecordData {
|
||||
if (getCadence() != null) {
|
||||
activityPoint.setCadence(getCadence());
|
||||
}
|
||||
if (getPower() != null) {
|
||||
activityPoint.setPower(getPower());
|
||||
}
|
||||
return activityPoint;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +93,7 @@
|
||||
<color name="chart_line_speed" type="color">#80D8FF</color>
|
||||
<color name="chart_line_elevation" type="color">#66BB6A</color>
|
||||
<color name="chart_line_heart_rate" type="color">#F44336</color>
|
||||
<color name="chart_line_power" type="color">#6A0DAD</color>
|
||||
<color name="chart_highline_dolor" type="color">#ffff8800</color>
|
||||
|
||||
<attr name="row_separator" format="color" />
|
||||
|
||||
Reference in New Issue
Block a user