Use x-values instead of x indices for the charts
This commit is contained in:
parent
558c9e4664
commit
5a2ddaaec0
|
@ -87,7 +87,6 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||||
};
|
};
|
||||||
private boolean mChartDirty = true;
|
private boolean mChartDirty = true;
|
||||||
private AsyncTask refreshTask;
|
private AsyncTask refreshTask;
|
||||||
protected XIndexLabelFormatter xIndexFormatter = new XIndexLabelFormatter();
|
|
||||||
|
|
||||||
public boolean isChartDirty() {
|
public boolean isChartDirty() {
|
||||||
return mChartDirty;
|
return mChartDirty;
|
||||||
|
@ -344,6 +343,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void configureChartDefaults(Chart<?> chart) {
|
protected void configureChartDefaults(Chart<?> chart) {
|
||||||
|
chart.getXAxis().setValueFormatter(new TimestampValueFormatter());
|
||||||
chart.getDescription().setText("");
|
chart.getDescription().setText("");
|
||||||
|
|
||||||
// if enabled, the chart will always start at zero on the y-axis
|
// if enabled, the chart will always start at zero on the y-axis
|
||||||
|
@ -355,7 +355,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||||
// enable touch gestures
|
// enable touch gestures
|
||||||
chart.setTouchEnabled(true);
|
chart.setTouchEnabled(true);
|
||||||
|
|
||||||
chart.getXAxis().setValueFormatter(xIndexFormatter);
|
chart.getXAxis().setGranularity(60*5);
|
||||||
|
|
||||||
setupLegend(chart);
|
setupLegend(chart);
|
||||||
}
|
}
|
||||||
|
@ -408,13 +408,14 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||||
*/
|
*/
|
||||||
protected abstract void renderCharts();
|
protected abstract void renderCharts();
|
||||||
|
|
||||||
protected DefaultChartsData refresh(GBDevice gbDevice, List<? extends ActivitySample> samples) {
|
protected DefaultChartsData<CombinedData> refresh(GBDevice gbDevice, List<? extends ActivitySample> samples) {
|
||||||
Calendar cal = GregorianCalendar.getInstance();
|
// Calendar cal = GregorianCalendar.getInstance();
|
||||||
cal.clear();
|
// cal.clear();
|
||||||
Date date;
|
int tsOffset = 0;
|
||||||
String dateStringFrom = "";
|
// Date date;
|
||||||
String dateStringTo = "";
|
// String dateStringFrom = "";
|
||||||
ArrayList<String> xLabels = null;
|
// String dateStringTo = "";
|
||||||
|
// ArrayList<String> xLabels = null;
|
||||||
|
|
||||||
LOG.info("" + getTitle() + ": number of samples:" + samples.size());
|
LOG.info("" + getTitle() + ": number of samples:" + samples.size());
|
||||||
CombinedData combinedData;
|
CombinedData combinedData;
|
||||||
|
@ -424,11 +425,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||||
|
|
||||||
int last_type = ActivityKind.TYPE_UNKNOWN;
|
int last_type = ActivityKind.TYPE_UNKNOWN;
|
||||||
|
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
|
||||||
SimpleDateFormat annotationDateFormat = new SimpleDateFormat("HH:mm");
|
|
||||||
|
|
||||||
int numEntries = samples.size();
|
int numEntries = samples.size();
|
||||||
xLabels = new ArrayList<>(numEntries);
|
|
||||||
List<BarEntry> activityEntries = new ArrayList<>(numEntries);
|
List<BarEntry> activityEntries = new ArrayList<>(numEntries);
|
||||||
boolean hr = supportsHeartrate(gbDevice);
|
boolean hr = supportsHeartrate(gbDevice);
|
||||||
List<Entry> heartrateEntries = hr ? new ArrayList<Entry>(numEntries) : null;
|
List<Entry> heartrateEntries = hr ? new ArrayList<Entry>(numEntries) : null;
|
||||||
|
@ -438,18 +435,27 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||||
for (int i = 0; i < numEntries; i++) {
|
for (int i = 0; i < numEntries; i++) {
|
||||||
ActivitySample sample = samples.get(i);
|
ActivitySample sample = samples.get(i);
|
||||||
int type = sample.getKind();
|
int type = sample.getKind();
|
||||||
|
int ts;
|
||||||
// determine start and end dates
|
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
cal.setTimeInMillis(sample.getTimestamp() * 1000L); // make sure it's converted to long
|
tsOffset = sample.getTimestamp();
|
||||||
date = cal.getTime();
|
ts = 0;
|
||||||
dateStringFrom = dateFormat.format(date);
|
} else {
|
||||||
} else if (i == samples.size() - 1) {
|
ts = sample.getTimestamp() - tsOffset;
|
||||||
cal.setTimeInMillis(sample.getTimestamp() * 1000L); // same here
|
|
||||||
date = cal.getTime();
|
|
||||||
dateStringTo = dateFormat.format(date);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// System.out.println(ts);
|
||||||
|
// ts = i;
|
||||||
|
// determine start and end dates
|
||||||
|
// if (i == 0) {
|
||||||
|
// cal.setTimeInMillis(ts * 1000L); // make sure it's converted to long
|
||||||
|
// date = cal.getTime();
|
||||||
|
// dateStringFrom = dateFormat.format(date);
|
||||||
|
// } else if (i == samples.size() - 1) {
|
||||||
|
// cal.setTimeInMillis(ts * 1000L); // same here
|
||||||
|
// date = cal.getTime();
|
||||||
|
// dateStringTo = dateFormat.format(date);
|
||||||
|
// }
|
||||||
|
|
||||||
float movement = sample.getIntensity();
|
float movement = sample.getIntensity();
|
||||||
|
|
||||||
float value = movement;
|
float value = movement;
|
||||||
|
@ -474,23 +480,23 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||||
// value = ((float) movement) / movement_divisor;
|
// value = ((float) movement) / movement_divisor;
|
||||||
colors.add(akActivity.color);
|
colors.add(akActivity.color);
|
||||||
}
|
}
|
||||||
activityEntries.add(createBarEntry(value, i));
|
activityEntries.add(createBarEntry(value, ts));
|
||||||
if (hr && isValidHeartRateValue(sample.getHeartRate())) {
|
if (hr && isValidHeartRateValue(sample.getHeartRate())) {
|
||||||
if (lastHrSampleIndex > -1 && i - lastHrSampleIndex > HeartRateUtils.MAX_HR_MEASUREMENTS_GAP_MINUTES) {
|
if (lastHrSampleIndex > -1 && ts - lastHrSampleIndex > 60*HeartRateUtils.MAX_HR_MEASUREMENTS_GAP_MINUTES) {
|
||||||
heartrateEntries.add(createLineEntry(0, lastHrSampleIndex + 1));
|
heartrateEntries.add(createLineEntry(0, lastHrSampleIndex + 1));
|
||||||
heartrateEntries.add(createLineEntry(0, i - 1));
|
heartrateEntries.add(createLineEntry(0, ts - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
heartrateEntries.add(createLineEntry(sample.getHeartRate(), i));
|
heartrateEntries.add(createLineEntry(sample.getHeartRate(), ts));
|
||||||
lastHrSampleIndex = i;
|
lastHrSampleIndex = ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
String xLabel = "";
|
String xLabel = "";
|
||||||
if (annotate) {
|
if (annotate) {
|
||||||
cal.setTimeInMillis(sample.getTimestamp() * 1000L);
|
// cal.setTimeInMillis((ts + tsOffset) * 1000L);
|
||||||
date = cal.getTime();
|
// date = cal.getTime();
|
||||||
String dateString = annotationDateFormat.format(date);
|
// String dateString = annotationDateFormat.format(date);
|
||||||
xLabel = dateString;
|
// xLabel = dateString;
|
||||||
// if (last_type != type) {
|
// if (last_type != type) {
|
||||||
// if (isSleep(last_type) && !isSleep(type)) {
|
// if (isSleep(last_type) && !isSleep(type)) {
|
||||||
// // woken up
|
// // woken up
|
||||||
|
@ -508,9 +514,8 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||||
// chart.getXAxis().addLimitLine(line);
|
// chart.getXAxis().addLimitLine(line);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
last_type = type;
|
// last_type = type;
|
||||||
}
|
}
|
||||||
xLabels.add(xLabel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BarDataSet activitySet = createActivitySet(activityEntries, colors, "Activity");
|
BarDataSet activitySet = createActivitySet(activityEntries, colors, "Activity");
|
||||||
|
@ -520,6 +525,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||||
List<IBarDataSet> list = new ArrayList<>();
|
List<IBarDataSet> list = new ArrayList<>();
|
||||||
list.add(activitySet);
|
list.add(activitySet);
|
||||||
BarData barData = new BarData(list);
|
BarData barData = new BarData(list);
|
||||||
|
barData.setBarWidth(100f);
|
||||||
// barData.setGroupSpace(0);
|
// barData.setGroupSpace(0);
|
||||||
combinedData.setData(barData);
|
combinedData.setData(barData);
|
||||||
|
|
||||||
|
@ -532,11 +538,11 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||||
// chart.setDescription(getString(R.string.sleep_activity_date_range, dateStringFrom, dateStringTo));
|
// chart.setDescription(getString(R.string.sleep_activity_date_range, dateStringFrom, dateStringTo));
|
||||||
// chart.setDescriptionPosition(?, ?);
|
// chart.setDescriptionPosition(?, ?);
|
||||||
} else {
|
} else {
|
||||||
// combinedData = new CombinedData(Collections.<String>emptyList());
|
|
||||||
combinedData = new CombinedData();
|
combinedData = new CombinedData();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new DefaultChartsData(combinedData, xLabels);
|
IAxisValueFormatter xValueFormatter = new SampleXLabelFormatter(tsOffset);
|
||||||
|
return new DefaultChartsData(combinedData, xValueFormatter);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isValidHeartRateValue(int value) {
|
protected boolean isValidHeartRateValue(int value) {
|
||||||
|
@ -556,12 +562,12 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||||
|
|
||||||
protected abstract void setupLegend(Chart chart);
|
protected abstract void setupLegend(Chart chart);
|
||||||
|
|
||||||
protected BarEntry createBarEntry(float value, int index) {
|
protected BarEntry createBarEntry(float value, int xValue) {
|
||||||
return new BarEntry(index, value);
|
return new BarEntry(xValue, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Entry createLineEntry(float value, int index) {
|
protected Entry createLineEntry(float value, int xValue) {
|
||||||
return new Entry(index, value);
|
return new Entry(xValue, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected BarDataSet createActivitySet(List<BarEntry> values, List<Integer> colors, String label) {
|
protected BarDataSet createActivitySet(List<BarEntry> values, List<Integer> colors, String label) {
|
||||||
|
@ -702,7 +708,15 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<? extends ActivitySample> getSamples(DBHandler db, GBDevice device) {
|
protected List<? extends ActivitySample> getSamples(DBHandler db, GBDevice device) {
|
||||||
return getSamples(db, device, getTSStart(), getTSEnd());
|
List<? extends ActivitySample> samples = getSamples(db, device, getTSStart(), getTSEnd());
|
||||||
|
// List<ActivitySample> samples2 = new ArrayList<>();
|
||||||
|
// int min = Math.min(samples.size(), 10);
|
||||||
|
// int min = Math.min(samples.size(), 10);
|
||||||
|
// for (int i = 0; i < min; i++) {
|
||||||
|
// samples2.add(samples.get(i));
|
||||||
|
// }
|
||||||
|
// return samples2;
|
||||||
|
return samples;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getTSEnd() {
|
private int getTSEnd() {
|
||||||
|
@ -719,10 +733,15 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||||
|
|
||||||
public static class DefaultChartsData<T extends ChartData<?>> extends ChartsData {
|
public static class DefaultChartsData<T extends ChartData<?>> extends ChartsData {
|
||||||
private final T data;
|
private final T data;
|
||||||
|
private IAxisValueFormatter xValueFormatter;
|
||||||
|
|
||||||
public DefaultChartsData(T data, ArrayList<String> xLabels) {
|
public DefaultChartsData(T data, IAxisValueFormatter xValueFormatter) {
|
||||||
|
this.xValueFormatter = xValueFormatter;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
setxLabels(xLabels);
|
}
|
||||||
|
|
||||||
|
public IAxisValueFormatter getXValueFormatter() {
|
||||||
|
return xValueFormatter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T getData() {
|
public T getData() {
|
||||||
|
@ -730,14 +749,40 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class XIndexLabelFormatter implements IAxisValueFormatter {
|
protected static class SampleXLabelFormatter implements IAxisValueFormatter {
|
||||||
|
private final int tsOffset;
|
||||||
|
SimpleDateFormat annotationDateFormat = new SimpleDateFormat("HH:mm");
|
||||||
|
// SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
||||||
|
Calendar cal = GregorianCalendar.getInstance();
|
||||||
|
|
||||||
private ArrayList<String> xLabels;
|
public SampleXLabelFormatter(int tsOffset) {
|
||||||
|
this.tsOffset = tsOffset;
|
||||||
|
|
||||||
public void setxLabels(ArrayList<String> xLabels) {
|
}
|
||||||
this.xLabels = xLabels;
|
// TODO: this does not work. Cannot use precomputed labels
|
||||||
|
@Override
|
||||||
|
public String getFormattedValue(float value, AxisBase axis) {
|
||||||
|
cal.clear();
|
||||||
|
int ts = (int) value;
|
||||||
|
cal.setTimeInMillis((ts + tsOffset) * 1000L);
|
||||||
|
Date date = cal.getTime();
|
||||||
|
String dateString = annotationDateFormat.format(date);
|
||||||
|
return dateString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDecimalDigits() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static class PreformattedXIndexLabelFormatter implements IAxisValueFormatter {
|
||||||
|
private ArrayList<String> xLabels;
|
||||||
|
|
||||||
|
public PreformattedXIndexLabelFormatter(ArrayList<String> xLabels) {
|
||||||
|
this.xLabels = xLabels;
|
||||||
|
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public String getFormattedValue(float value, AxisBase axis) {
|
public String getFormattedValue(float value, AxisBase axis) {
|
||||||
int index = (int) value;
|
int index = (int) value;
|
||||||
|
|
|
@ -71,8 +71,8 @@ public class ActivitySleepChartFragment extends AbstractChartFragment {
|
||||||
y.setDrawGridLines(false);
|
y.setDrawGridLines(false);
|
||||||
// y.setDrawLabels(false);
|
// y.setDrawLabels(false);
|
||||||
// TODO: make fixed max value optional
|
// TODO: make fixed max value optional
|
||||||
y.setAxisMaxValue(1f);
|
y.setAxisMaximum(1f);
|
||||||
y.setAxisMinValue(0);
|
y.setAxisMinimum(0);
|
||||||
y.setDrawTopYLabelEntry(false);
|
y.setDrawTopYLabelEntry(false);
|
||||||
y.setTextColor(CHART_TEXT_COLOR);
|
y.setTextColor(CHART_TEXT_COLOR);
|
||||||
|
|
||||||
|
@ -85,8 +85,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(HeartRateUtils.MAX_HEART_RATE_VALUE);
|
yAxisRight.setAxisMaximum(HeartRateUtils.MAX_HEART_RATE_VALUE);
|
||||||
yAxisRight.setAxisMinValue(HeartRateUtils.MIN_HEART_RATE_VALUE);
|
yAxisRight.setAxisMinimum(HeartRateUtils.MIN_HEART_RATE_VALUE);
|
||||||
|
|
||||||
// refresh immediately instead of use refreshIfVisible(), for perceived performance
|
// refresh immediately instead of use refreshIfVisible(), for perceived performance
|
||||||
refresh();
|
refresh();
|
||||||
|
@ -118,13 +118,14 @@ public class ActivitySleepChartFragment extends AbstractChartFragment {
|
||||||
DefaultChartsData dcd = (DefaultChartsData) chartsData;
|
DefaultChartsData dcd = (DefaultChartsData) chartsData;
|
||||||
mChart.getLegend().setTextColor(LEGEND_TEXT_COLOR);
|
mChart.getLegend().setTextColor(LEGEND_TEXT_COLOR);
|
||||||
mChart.setData(null); // workaround for https://github.com/PhilJay/MPAndroidChart/issues/2317
|
mChart.setData(null); // workaround for https://github.com/PhilJay/MPAndroidChart/issues/2317
|
||||||
xIndexFormatter.setxLabels(dcd.getXLabels());
|
mChart.getXAxis().setValueFormatter(dcd.getXValueFormatter());
|
||||||
mChart.setData(dcd.getData());
|
mChart.setData(dcd.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderCharts() {
|
protected void renderCharts() {
|
||||||
mChart.animateX(ANIM_TIME, Easing.EasingOption.EaseInOutQuart);
|
mChart.animateX(ANIM_TIME, Easing.EasingOption.EaseInOutQuart);
|
||||||
|
// mChart.invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,15 +1,4 @@
|
||||||
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public abstract class ChartsData {
|
public abstract class ChartsData {
|
||||||
private ArrayList<String> xLabels;
|
|
||||||
|
|
||||||
public void setxLabels(ArrayList<String> xLabels) {
|
|
||||||
this.xLabels = xLabels;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<String> getXLabels() {
|
|
||||||
return xLabels;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
||||||
|
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
|
@ -69,6 +69,7 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
||||||
private List<Measurement> heartRateValues;
|
private List<Measurement> heartRateValues;
|
||||||
private LineDataSet mHeartRateSet;
|
private LineDataSet mHeartRateSet;
|
||||||
private int mHeartRate;
|
private int mHeartRate;
|
||||||
|
private long tsOffset = -1;
|
||||||
|
|
||||||
private class Steps {
|
private class Steps {
|
||||||
private int initialSteps;
|
private int initialSteps;
|
||||||
|
@ -154,12 +155,14 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
||||||
case DeviceService.ACTION_REALTIME_STEPS: {
|
case DeviceService.ACTION_REALTIME_STEPS: {
|
||||||
int steps = intent.getIntExtra(DeviceService.EXTRA_REALTIME_STEPS, 0);
|
int steps = intent.getIntExtra(DeviceService.EXTRA_REALTIME_STEPS, 0);
|
||||||
long timestamp = intent.getLongExtra(DeviceService.EXTRA_TIMESTAMP, System.currentTimeMillis());
|
long timestamp = intent.getLongExtra(DeviceService.EXTRA_TIMESTAMP, System.currentTimeMillis());
|
||||||
|
timestamp = adjust(timestamp);
|
||||||
addEntries(steps, timestamp);
|
addEntries(steps, timestamp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DeviceService.ACTION_HEARTRATE_MEASUREMENT: {
|
case DeviceService.ACTION_HEARTRATE_MEASUREMENT: {
|
||||||
int heartRate = intent.getIntExtra(DeviceService.EXTRA_HEART_RATE_VALUE, 0);
|
int heartRate = intent.getIntExtra(DeviceService.EXTRA_HEART_RATE_VALUE, 0);
|
||||||
long timestamp = intent.getLongExtra(DeviceService.EXTRA_TIMESTAMP, System.currentTimeMillis());
|
long timestamp = intent.getLongExtra(DeviceService.EXTRA_TIMESTAMP, System.currentTimeMillis());
|
||||||
|
timestamp = adjust(timestamp);
|
||||||
if (isValidHeartRateValue(heartRate)) {
|
if (isValidHeartRateValue(heartRate)) {
|
||||||
setCurrentHeartRate(heartRate, timestamp);
|
setCurrentHeartRate(heartRate, timestamp);
|
||||||
}
|
}
|
||||||
|
@ -169,6 +172,14 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private long adjust(long timestamp) {
|
||||||
|
if (tsOffset == -1) {
|
||||||
|
tsOffset = timestamp;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return timestamp - tsOffset;
|
||||||
|
}
|
||||||
|
|
||||||
private void setCurrentHeartRate(int heartRate, long timestamp) {
|
private void setCurrentHeartRate(int heartRate, long timestamp) {
|
||||||
addHistoryDataSet(true);
|
addHistoryDataSet(true);
|
||||||
mHeartRate = heartRate;
|
mHeartRate = heartRate;
|
||||||
|
@ -214,12 +225,12 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
||||||
if (stepsPerMinute < 0) {
|
if (stepsPerMinute < 0) {
|
||||||
stepsPerMinute = 0;
|
stepsPerMinute = 0;
|
||||||
}
|
}
|
||||||
mHistorySet.addEntry(new Entry(stepsPerMinute, timestamp));
|
mHistorySet.addEntry(new Entry(timestamp, stepsPerMinute));
|
||||||
int hr = getCurrentHeartRate();
|
int hr = getCurrentHeartRate();
|
||||||
if (hr < 0) {
|
if (hr < 0) {
|
||||||
hr = 0;
|
hr = 0;
|
||||||
}
|
}
|
||||||
mHeartRateSet.addEntry(new Entry(hr, timestamp));
|
mHeartRateSet.addEntry(new Entry(timestamp, hr));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean addHistoryDataSet(boolean force) {
|
private boolean addHistoryDataSet(boolean force) {
|
||||||
|
@ -251,8 +262,8 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
||||||
mTotalStepsChart = (CustomBarChart) rootView.findViewById(R.id.livechart_steps_total);
|
mTotalStepsChart = (CustomBarChart) rootView.findViewById(R.id.livechart_steps_total);
|
||||||
mStepsPerMinuteHistoryChart = (BarLineChartBase) rootView.findViewById(R.id.livechart_steps_per_minute_history);
|
mStepsPerMinuteHistoryChart = (BarLineChartBase) rootView.findViewById(R.id.livechart_steps_per_minute_history);
|
||||||
|
|
||||||
totalStepsEntry = new BarEntry(0, 1);
|
totalStepsEntry = new BarEntry(1, 0);
|
||||||
stepsPerMinuteEntry = new BarEntry(0, 1);
|
stepsPerMinuteEntry = new BarEntry(1, 0);
|
||||||
|
|
||||||
mStepsPerMinuteData = setupCurrentChart(mStepsPerMinuteCurrentChart, stepsPerMinuteEntry, getString(R.string.live_activity_current_steps_per_minute));
|
mStepsPerMinuteData = setupCurrentChart(mStepsPerMinuteCurrentChart, stepsPerMinuteEntry, getString(R.string.live_activity_current_steps_per_minute));
|
||||||
mTotalStepsData = setupTotalStepsChart(mTotalStepsChart, totalStepsEntry, getString(R.string.live_activity_total_steps));
|
mTotalStepsData = setupTotalStepsChart(mTotalStepsChart, totalStepsEntry, getString(R.string.live_activity_total_steps));
|
||||||
|
@ -304,7 +315,7 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
||||||
* Called in the UI thread.
|
* Called in the UI thread.
|
||||||
*/
|
*/
|
||||||
private void pulse() {
|
private void pulse() {
|
||||||
addEntries(System.currentTimeMillis());
|
addEntries(adjust(System.currentTimeMillis()));
|
||||||
|
|
||||||
LineData historyData = (LineData) mStepsPerMinuteHistoryChart.getData();
|
LineData historyData = (LineData) mStepsPerMinuteHistoryChart.getData();
|
||||||
if (historyData == null) {
|
if (historyData == null) {
|
||||||
|
@ -378,7 +389,7 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
||||||
|
|
||||||
entries.add(new BarEntry(0, 0));
|
entries.add(new BarEntry(0, 0));
|
||||||
entries.add(entry);
|
entries.add(entry);
|
||||||
entries.add(new BarEntry(0, 2));
|
entries.add(new BarEntry(2, 0));
|
||||||
colors.add(akActivity.color);
|
colors.add(akActivity.color);
|
||||||
colors.add(akActivity.color);
|
colors.add(akActivity.color);
|
||||||
colors.add(akActivity.color);
|
colors.add(akActivity.color);
|
||||||
|
@ -400,7 +411,7 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private BarDataSet setupTotalStepsChart(CustomBarChart chart, BarEntry entry, String label) {
|
private BarDataSet setupTotalStepsChart(CustomBarChart chart, BarEntry entry, String label) {
|
||||||
mTotalStepsChart.getAxisLeft().setAxisMaxValue(5000); // TODO: use daily goal - already reached steps
|
mTotalStepsChart.getAxisLeft().setAxisMaximum(5000); // TODO: use daily goal - already reached steps
|
||||||
return setupCommonChart(chart, entry, label); // at the moment, these look the same
|
return setupCommonChart(chart, entry, label); // at the moment, these look the same
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -430,7 +441,7 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
||||||
y.setDrawTopYLabelEntry(false);
|
y.setDrawTopYLabelEntry(false);
|
||||||
y.setTextColor(CHART_TEXT_COLOR);
|
y.setTextColor(CHART_TEXT_COLOR);
|
||||||
y.setEnabled(true);
|
y.setEnabled(true);
|
||||||
y.setAxisMinValue(0);
|
y.setAxisMinimum(0);
|
||||||
|
|
||||||
YAxis yAxisRight = chart.getAxisRight();
|
YAxis yAxisRight = chart.getAxisRight();
|
||||||
yAxisRight.setDrawGridLines(false);
|
yAxisRight.setDrawGridLines(false);
|
||||||
|
@ -438,8 +449,8 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
||||||
yAxisRight.setDrawLabels(true);
|
yAxisRight.setDrawLabels(true);
|
||||||
yAxisRight.setDrawTopYLabelEntry(false);
|
yAxisRight.setDrawTopYLabelEntry(false);
|
||||||
yAxisRight.setTextColor(CHART_TEXT_COLOR);
|
yAxisRight.setTextColor(CHART_TEXT_COLOR);
|
||||||
yAxisRight.setAxisMaxValue(HeartRateUtils.MAX_HEART_RATE_VALUE);
|
yAxisRight.setAxisMaximum(HeartRateUtils.MAX_HEART_RATE_VALUE);
|
||||||
yAxisRight.setAxisMinValue(HeartRateUtils.MIN_HEART_RATE_VALUE);
|
yAxisRight.setAxisMinimum(HeartRateUtils.MIN_HEART_RATE_VALUE);
|
||||||
|
|
||||||
mHistorySet = new LineDataSet(new ArrayList<Entry>(), getString(R.string.live_activity_steps_history));
|
mHistorySet = new LineDataSet(new ArrayList<Entry>(), getString(R.string.live_activity_steps_history));
|
||||||
mHistorySet.setAxisDependency(YAxis.AxisDependency.LEFT);
|
mHistorySet.setAxisDependency(YAxis.AxisDependency.LEFT);
|
||||||
|
|
|
@ -101,7 +101,7 @@ public class SleepChartFragment extends AbstractChartFragment {
|
||||||
mSleepAmountChart.setData(mcd.getPieData().getPieData());
|
mSleepAmountChart.setData(mcd.getPieData().getPieData());
|
||||||
|
|
||||||
mActivityChart.setData(null); // workaround for https://github.com/PhilJay/MPAndroidChart/issues/2317
|
mActivityChart.setData(null); // workaround for https://github.com/PhilJay/MPAndroidChart/issues/2317
|
||||||
xIndexFormatter.setxLabels(mcd.getChartsData().getXLabels());
|
mActivityChart.getXAxis().setValueFormatter(mcd.getChartsData().getXValueFormatter());
|
||||||
mActivityChart.setData(mcd.getChartsData().getData());
|
mActivityChart.setData(mcd.getChartsData().getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
||||||
|
|
||||||
|
import com.github.mikephil.charting.components.AxisBase;
|
||||||
|
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
|
||||||
|
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
|
||||||
|
public class TimestampValueFormatter implements IAxisValueFormatter {
|
||||||
|
private final Calendar cal;
|
||||||
|
// private DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
||||||
|
private DateFormat dateFormat;
|
||||||
|
|
||||||
|
public TimestampValueFormatter() {
|
||||||
|
this(new SimpleDateFormat("HH:mm"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public TimestampValueFormatter(DateFormat dateFormat) {
|
||||||
|
this.dateFormat = dateFormat;
|
||||||
|
cal = GregorianCalendar.getInstance();
|
||||||
|
cal.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFormattedValue(float value, AxisBase axis) {
|
||||||
|
cal.setTimeInMillis((int) value * 1000L);
|
||||||
|
Date date = cal.getTime();
|
||||||
|
String dateString = dateFormat.format(date);
|
||||||
|
return dateString;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDecimalDigits() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -66,7 +66,7 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
||||||
mWeekStepsChart.setData(null); // workaround for https://github.com/PhilJay/MPAndroidChart/issues/2317
|
mWeekStepsChart.setData(null); // workaround for https://github.com/PhilJay/MPAndroidChart/issues/2317
|
||||||
mWeekStepsChart.setData(mcd.getWeekBeforeStepsData().getData());
|
mWeekStepsChart.setData(mcd.getWeekBeforeStepsData().getData());
|
||||||
mWeekStepsChart.getLegend().setEnabled(false);
|
mWeekStepsChart.getLegend().setEnabled(false);
|
||||||
xIndexFormatter.setxLabels(mcd.getWeekBeforeStepsData().getXLabels());
|
mWeekStepsChart.getXAxis().setValueFormatter(mcd.getWeekBeforeStepsData().getXValueFormatter());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -75,7 +75,7 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
||||||
mTodayStepsChart.invalidate();
|
mTodayStepsChart.invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private DefaultChartsData refreshWeekBeforeSteps(DBHandler db, BarChart barChart, Calendar day, GBDevice device) {
|
private DefaultChartsData<BarData> refreshWeekBeforeSteps(DBHandler db, BarChart barChart, Calendar day, GBDevice device) {
|
||||||
|
|
||||||
ActivityAnalysis analysis = new ActivityAnalysis();
|
ActivityAnalysis analysis = new ActivityAnalysis();
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
||||||
barChart.getAxisLeft().removeAllLimitLines();
|
barChart.getAxisLeft().removeAllLimitLines();
|
||||||
barChart.getAxisLeft().addLimitLine(target);
|
barChart.getAxisLeft().addLimitLine(target);
|
||||||
|
|
||||||
return new DefaultChartsData(barData, labels);
|
return new DefaultChartsData(barData, new PreformattedXIndexLabelFormatter(labels));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -184,7 +184,6 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
||||||
x.setEnabled(true);
|
x.setEnabled(true);
|
||||||
x.setTextColor(CHART_TEXT_COLOR);
|
x.setTextColor(CHART_TEXT_COLOR);
|
||||||
x.setDrawLimitLinesBehindData(true);
|
x.setDrawLimitLinesBehindData(true);
|
||||||
x.setValueFormatter(xIndexFormatter);
|
|
||||||
x.setPosition(XAxis.XAxisPosition.BOTTOM);
|
x.setPosition(XAxis.XAxisPosition.BOTTOM);
|
||||||
|
|
||||||
YAxis y = mWeekStepsChart.getAxisLeft();
|
YAxis y = mWeekStepsChart.getAxisLeft();
|
||||||
|
|
Loading…
Reference in New Issue