Enable heart rate charts #232

(And fix some charting issues)
here
cpfeiffer 2016-04-04 23:05:00 +02:00
parent a15b327ff1
commit 403f74e59b
5 changed files with 40 additions and 12 deletions

View File

@ -79,7 +79,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
}
};
private boolean mChartDirty = true;
private boolean supportsHeartrateChart = false;
private boolean supportsHeartrateChart = true;
public boolean isChartDirty() {
return mChartDirty;
@ -119,6 +119,8 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
protected int AK_LIGHT_SLEEP_COLOR;
protected int AK_NOT_WORN_COLOR;
protected String HEARTRATE_LABEL;
protected AbstractChartFragment(String... intentFilterActions) {
mIntentFilterActions = new HashSet<>();
if (intentFilterActions != null) {
@ -153,6 +155,8 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
AK_LIGHT_SLEEP_COLOR = getResources().getColor(R.color.chart_deep_sleep_light);
AK_NOT_WORN_COLOR = getResources().getColor(R.color.chart_not_worn_light);
HEARTRATE_LABEL = getContext().getString(R.string.charts_legend_heartrate);
akActivity = new ActivityConfig(ActivityKind.TYPE_ACTIVITY, getString(R.string.abstract_chart_fragment_kind_activity), AK_ACTIVITY_COLOR);
akLightSleep = new ActivityConfig(ActivityKind.TYPE_LIGHT_SLEEP, getString(R.string.abstract_chart_fragment_kind_light_sleep), AK_LIGHT_SLEEP_COLOR);
akDeepSleep = new ActivityConfig(ActivityKind.TYPE_DEEP_SLEEP, getString(R.string.abstract_chart_fragment_kind_deep_sleep), AK_DEEP_SLEEP_COLOR);
@ -445,7 +449,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
colors.add(akActivity.color);
}
activityEntries.add(createBarEntry(value, i));
if (hr) {
if (hr && isValidHeartRateValue(sample.getCustomValue())) {
heartrateEntries.add(createLineEntry(sample.getCustomValue(), i));
}
@ -488,7 +492,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
barData.setGroupSpace(0);
combinedData.setData(barData);
if (hr) {
if (hr && heartrateEntries.size() > 0) {
LineDataSet heartrateSet = createHeartrateSet(heartrateEntries, "Heart Rate");
LineData lineData = new LineData(xLabels, heartrateSet);
combinedData.setData(lineData);
@ -507,6 +511,10 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
}
}
protected boolean isValidHeartRateValue(int value) {
return value > 0 && value < 255;
}
/**
* Implement this to supply the samples to be displayed.
*
@ -550,14 +558,19 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
LineDataSet set1 = new LineDataSet(values, label);
set1.setColor(HEARTRATE_COLOR);
// set1.setColors(colors);
// set1.setDrawCubic(true);
// set1.setCubicIntensity(0.2f);
set1.setDrawCubic(true);
set1.setCubicIntensity(0.1f);
// //set1.setDrawFilled(true);
// set1.setDrawCircles(false);
set1.setLineWidth(2f);
// set1.setCircleSize(5f);
// set1.setLineWidth(2f);
set1.setDrawCircles(false);
// set1.setCircleRadius(2f);
// set1.setDrawFilled(true);
set1.setLineWidth(0.8f);
// set1.setFillColor(ColorTemplate.getHoloBlue());
set1.setDrawValues(false);
set1.setDrawValues(true);
// set1.setHighLightColor(Color.rgb(128, 0, 255));
// set1.setColor(Color.rgb(89, 178, 44));
set1.setValueTextColor(CHART_TEXT_COLOR);

View File

@ -70,6 +70,7 @@ public class ActivitySleepChartFragment extends AbstractChartFragment {
// y.setDrawLabels(false);
// TODO: make fixed max value optional
y.setAxisMaxValue(1f);
y.setAxisMinValue(0);
y.setDrawTopYLabelEntry(false);
y.setTextColor(CHART_TEXT_COLOR);
@ -82,6 +83,8 @@ public class ActivitySleepChartFragment extends AbstractChartFragment {
yAxisRight.setDrawLabels(true);
yAxisRight.setDrawTopYLabelEntry(true);
yAxisRight.setTextColor(CHART_TEXT_COLOR);
yAxisRight.setAxisMaxValue(250);
yAxisRight.setAxisMinValue(0);
// refresh immediately instead of use refreshIfVisible(), for perceived performance
refresh();
@ -125,6 +128,10 @@ public class ActivitySleepChartFragment extends AbstractChartFragment {
legendLabels.add(akDeepSleep.label);
legendColors.add(akNotWorn.color);
legendLabels.add(akNotWorn.label);
if (supportsHeartrate()) {
legendColors.add(HEARTRATE_COLOR);
legendLabels.add(HEARTRATE_LABEL);
}
chart.getLegend().setCustom(legendColors, legendLabels);
}

View File

@ -151,6 +151,7 @@ public class SleepChartFragment extends AbstractChartFragment {
// y.setDrawLabels(false);
// TODO: make fixed max value optional
y.setAxisMaxValue(1f);
y.setAxisMinValue(0);
y.setDrawTopYLabelEntry(false);
y.setTextColor(CHART_TEXT_COLOR);
@ -159,10 +160,12 @@ public class SleepChartFragment extends AbstractChartFragment {
YAxis yAxisRight = mActivityChart.getAxisRight();
yAxisRight.setDrawGridLines(false);
yAxisRight.setEnabled(false);
yAxisRight.setDrawLabels(false);
yAxisRight.setDrawTopYLabelEntry(false);
yAxisRight.setEnabled(supportsHeartrate());
yAxisRight.setDrawLabels(true);
yAxisRight.setDrawTopYLabelEntry(true);
yAxisRight.setTextColor(CHART_TEXT_COLOR);
yAxisRight.setAxisMaxValue(250);
yAxisRight.setAxisMinValue(0);
}
protected void setupLegend(Chart chart) {
@ -172,6 +175,10 @@ public class SleepChartFragment extends AbstractChartFragment {
legendLabels.add(akLightSleep.label);
legendColors.add(akDeepSleep.color);
legendLabels.add(akDeepSleep.label);
if (supportsHeartrate()) {
legendColors.add(HEARTRATE_COLOR);
legendLabels.add(HEARTRATE_LABEL);
}
chart.getLegend().setCustom(legendColors, legendLabels);
chart.getLegend().setTextColor(LEGEND_TEXT_COLOR);
}

View File

@ -11,7 +11,7 @@
<color name="secondarytext" type="color">#ff808080</color>
<color name="divider" type="color">#1f000000</color>
<color name="chart_heartrate" type="color">#b40000</color>
<color name="chart_heartrate" type="color">#ffab40</color>
<color name="chart_deep_sleep_light" type="color">#0071b7</color>
<color name="chart_deep_sleep_dark" type="color">#4c5aff</color>

View File

@ -239,5 +239,6 @@
<string name="DEVINFO_HR_VER">"HR: "</string>
<string name="updatefirmwareoperation_update_in_progress">Firmware update in progress</string>
<string name="updatefirmwareoperation_firmware_not_sent">Firmware not sent</string>
<string name="charts_legend_heartrate">Heart Rate</string>
</resources>