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 mChartDirty = true;
private boolean supportsHeartrateChart = false; private boolean supportsHeartrateChart = true;
public boolean isChartDirty() { public boolean isChartDirty() {
return mChartDirty; return mChartDirty;
@ -119,6 +119,8 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
protected int AK_LIGHT_SLEEP_COLOR; protected int AK_LIGHT_SLEEP_COLOR;
protected int AK_NOT_WORN_COLOR; protected int AK_NOT_WORN_COLOR;
protected String HEARTRATE_LABEL;
protected AbstractChartFragment(String... intentFilterActions) { protected AbstractChartFragment(String... intentFilterActions) {
mIntentFilterActions = new HashSet<>(); mIntentFilterActions = new HashSet<>();
if (intentFilterActions != null) { 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_LIGHT_SLEEP_COLOR = getResources().getColor(R.color.chart_deep_sleep_light);
AK_NOT_WORN_COLOR = getResources().getColor(R.color.chart_not_worn_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); 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); 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); 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); colors.add(akActivity.color);
} }
activityEntries.add(createBarEntry(value, i)); activityEntries.add(createBarEntry(value, i));
if (hr) { if (hr && isValidHeartRateValue(sample.getCustomValue())) {
heartrateEntries.add(createLineEntry(sample.getCustomValue(), i)); heartrateEntries.add(createLineEntry(sample.getCustomValue(), i));
} }
@ -488,7 +492,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
barData.setGroupSpace(0); barData.setGroupSpace(0);
combinedData.setData(barData); combinedData.setData(barData);
if (hr) { if (hr && heartrateEntries.size() > 0) {
LineDataSet heartrateSet = createHeartrateSet(heartrateEntries, "Heart Rate"); LineDataSet heartrateSet = createHeartrateSet(heartrateEntries, "Heart Rate");
LineData lineData = new LineData(xLabels, heartrateSet); LineData lineData = new LineData(xLabels, heartrateSet);
combinedData.setData(lineData); 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. * 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); LineDataSet set1 = new LineDataSet(values, label);
set1.setColor(HEARTRATE_COLOR); set1.setColor(HEARTRATE_COLOR);
// set1.setColors(colors); // set1.setColors(colors);
// set1.setDrawCubic(true); set1.setDrawCubic(true);
// set1.setCubicIntensity(0.2f); set1.setCubicIntensity(0.1f);
// //set1.setDrawFilled(true); // //set1.setDrawFilled(true);
// set1.setDrawCircles(false); // set1.setDrawCircles(false);
set1.setLineWidth(2f); // set1.setLineWidth(2f);
// set1.setCircleSize(5f);
set1.setDrawCircles(false);
// set1.setCircleRadius(2f);
// set1.setDrawFilled(true);
set1.setLineWidth(0.8f);
// set1.setFillColor(ColorTemplate.getHoloBlue()); // set1.setFillColor(ColorTemplate.getHoloBlue());
set1.setDrawValues(false); set1.setDrawValues(true);
// set1.setHighLightColor(Color.rgb(128, 0, 255)); // set1.setHighLightColor(Color.rgb(128, 0, 255));
// set1.setColor(Color.rgb(89, 178, 44)); // set1.setColor(Color.rgb(89, 178, 44));
set1.setValueTextColor(CHART_TEXT_COLOR); set1.setValueTextColor(CHART_TEXT_COLOR);

View File

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

View File

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

View File

@ -11,7 +11,7 @@
<color name="secondarytext" type="color">#ff808080</color> <color name="secondarytext" type="color">#ff808080</color>
<color name="divider" type="color">#1f000000</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_light" type="color">#0071b7</color>
<color name="chart_deep_sleep_dark" type="color">#4c5aff</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="DEVINFO_HR_VER">"HR: "</string>
<string name="updatefirmwareoperation_update_in_progress">Firmware update in progress</string> <string name="updatefirmwareoperation_update_in_progress">Firmware update in progress</string>
<string name="updatefirmwareoperation_firmware_not_sent">Firmware not sent</string> <string name="updatefirmwareoperation_firmware_not_sent">Firmware not sent</string>
<string name="charts_legend_heartrate">Heart Rate</string>
</resources> </resources>