mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 21:06:50 +01:00
Some work in enabling the history of step count
Doesn't work yet.
This commit is contained in:
parent
2149b18ae3
commit
c9e91bd708
@ -20,6 +20,9 @@ import com.github.mikephil.charting.components.YAxis;
|
|||||||
import com.github.mikephil.charting.data.BarData;
|
import com.github.mikephil.charting.data.BarData;
|
||||||
import com.github.mikephil.charting.data.BarDataSet;
|
import com.github.mikephil.charting.data.BarDataSet;
|
||||||
import com.github.mikephil.charting.data.BarEntry;
|
import com.github.mikephil.charting.data.BarEntry;
|
||||||
|
import com.github.mikephil.charting.data.Entry;
|
||||||
|
import com.github.mikephil.charting.data.LineData;
|
||||||
|
import com.github.mikephil.charting.data.LineDataSet;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -41,6 +44,7 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
|||||||
private BarEntry stepsPerMinuteEntry;
|
private BarEntry stepsPerMinuteEntry;
|
||||||
private BarDataSet mStepsPerMinuteData;
|
private BarDataSet mStepsPerMinuteData;
|
||||||
private BarDataSet mTotalStepsData;
|
private BarDataSet mTotalStepsData;
|
||||||
|
private LineDataSet mHistorySet = new LineDataSet(new ArrayList<Entry>(), "History");
|
||||||
|
|
||||||
private class Steps {
|
private class Steps {
|
||||||
private int initialSteps;
|
private int initialSteps;
|
||||||
@ -136,11 +140,17 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
|||||||
mStepsPerMinuteCurrentChart.setSingleEntryYValue(mSteps.getStepsPerMinute());
|
mStepsPerMinuteCurrentChart.setSingleEntryYValue(mSteps.getStepsPerMinute());
|
||||||
// stepsPerMinuteEntry.setVal(mSteps.getStepsPerMinute());
|
// stepsPerMinuteEntry.setVal(mSteps.getStepsPerMinute());
|
||||||
// mStepsPerMinuteCurrentChart.setCenterText(NumberFormat.getNumberInstance().format(mSteps.getStepsPerMinute()));
|
// mStepsPerMinuteCurrentChart.setCenterText(NumberFormat.getNumberInstance().format(mSteps.getStepsPerMinute()));
|
||||||
|
mStepsPerMinuteHistoryChart.getData().addEntry(new Entry(mSteps.getStepsPerMinute(), mHistorySet.getEntryCount()), 0);
|
||||||
|
mStepsPerMinuteHistoryChart.getData().addXValue("");
|
||||||
|
mHistorySet.addColor(akActivity.color);
|
||||||
|
|
||||||
|
|
||||||
mTotalStepsChart.getData().notifyDataChanged();
|
mTotalStepsChart.getData().notifyDataChanged();
|
||||||
mTotalStepsData.notifyDataSetChanged();
|
mTotalStepsData.notifyDataSetChanged();
|
||||||
mStepsPerMinuteCurrentChart.getData().notifyDataChanged();
|
mStepsPerMinuteCurrentChart.getData().notifyDataChanged();
|
||||||
mStepsPerMinuteData.notifyDataSetChanged();
|
mStepsPerMinuteData.notifyDataSetChanged();
|
||||||
|
mStepsPerMinuteHistoryChart.getData().notifyDataChanged();
|
||||||
|
mHistorySet.notifyDataSetChanged();
|
||||||
|
|
||||||
renderCharts();
|
renderCharts();
|
||||||
}
|
}
|
||||||
@ -150,20 +160,21 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
|||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
IntentFilter filterLocal = new IntentFilter();
|
IntentFilter filterLocal = new IntentFilter();
|
||||||
filterLocal.addAction(DeviceService.ACTION_REALTIME_STEPS);
|
filterLocal.addAction(DeviceService.ACTION_REALTIME_STEPS);
|
||||||
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mReceiver, filterLocal);
|
|
||||||
|
|
||||||
View rootView = inflater.inflate(R.layout.fragment_live_activity, container, false);
|
View rootView = inflater.inflate(R.layout.fragment_live_activity, container, false);
|
||||||
|
|
||||||
mStepsPerMinuteHistoryChart = (BarLineChartBase) rootView.findViewById(R.id.livechart_steps_per_minute_history);
|
|
||||||
mStepsPerMinuteCurrentChart = (CustomBarChart) rootView.findViewById(R.id.livechart_steps_per_minute_current);
|
mStepsPerMinuteCurrentChart = (CustomBarChart) rootView.findViewById(R.id.livechart_steps_per_minute_current);
|
||||||
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);
|
||||||
|
|
||||||
totalStepsEntry = new BarEntry(0, 1);
|
totalStepsEntry = new BarEntry(0, 1);
|
||||||
stepsPerMinuteEntry = new BarEntry(0, 1);
|
stepsPerMinuteEntry = new BarEntry(0, 1);
|
||||||
|
|
||||||
setupHistoryChart(mStepsPerMinuteHistoryChart);
|
|
||||||
mStepsPerMinuteData = setupCurrentChart(mStepsPerMinuteCurrentChart, stepsPerMinuteEntry, "Steps/min");
|
mStepsPerMinuteData = setupCurrentChart(mStepsPerMinuteCurrentChart, stepsPerMinuteEntry, "Steps/min");
|
||||||
mTotalStepsData = setupTotalStepsChart(mTotalStepsChart, totalStepsEntry, "Total Steps");
|
mTotalStepsData = setupTotalStepsChart(mTotalStepsChart, totalStepsEntry, "Total Steps");
|
||||||
|
setupHistoryChart(mStepsPerMinuteHistoryChart);
|
||||||
|
|
||||||
|
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mReceiver, filterLocal);
|
||||||
|
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
@ -244,11 +255,12 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setupHistoryChart(BarLineChartBase chart) {
|
private void setupHistoryChart(BarLineChartBase chart) {
|
||||||
|
configureBarLineChartDefaults(chart);
|
||||||
|
|
||||||
chart.setBackgroundColor(BACKGROUND_COLOR);
|
chart.setBackgroundColor(BACKGROUND_COLOR);
|
||||||
chart.setDescriptionColor(DESCRIPTION_COLOR);
|
chart.setDescriptionColor(DESCRIPTION_COLOR);
|
||||||
chart.setDescription("");
|
chart.setDescription("");
|
||||||
|
chart.setNoDataText("Start your activity");
|
||||||
configureBarLineChartDefaults(chart);
|
|
||||||
|
|
||||||
XAxis x = chart.getXAxis();
|
XAxis x = chart.getXAxis();
|
||||||
x.setDrawLabels(true);
|
x.setDrawLabels(true);
|
||||||
@ -270,6 +282,16 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
|||||||
yAxisRight.setDrawLabels(false);
|
yAxisRight.setDrawLabels(false);
|
||||||
yAxisRight.setDrawTopYLabelEntry(false);
|
yAxisRight.setDrawTopYLabelEntry(false);
|
||||||
yAxisRight.setTextColor(CHART_TEXT_COLOR);
|
yAxisRight.setTextColor(CHART_TEXT_COLOR);
|
||||||
|
|
||||||
|
LineData data = new LineData();
|
||||||
|
data.addDataSet(mHistorySet);
|
||||||
|
// add dummy value because we get ArrayIndexOutOfBoundsExceptions without ;(
|
||||||
|
mHistorySet.addEntry(new Entry(0, 0));
|
||||||
|
mHistorySet.addColor(akActivity.color);
|
||||||
|
data.addXValue("");
|
||||||
|
chart.setData(data);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -294,11 +316,9 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderCharts() {
|
protected void renderCharts() {
|
||||||
// mTotalStepsChart.invalidate();
|
|
||||||
// mStepsPerMinuteCurrentChart.invalidate();
|
|
||||||
mStepsPerMinuteCurrentChart.animateY(150);
|
mStepsPerMinuteCurrentChart.animateY(150);
|
||||||
mTotalStepsChart.animateY(150);
|
mTotalStepsChart.animateY(150);
|
||||||
// mStepsPerMinuteHistoryChart.invalidate();
|
mStepsPerMinuteHistoryChart.invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user