1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-04 01:09:47 +01:00

Temporary backup with live activity

This commit is contained in:
cpfeiffer 2015-09-03 23:20:47 +02:00
parent 42420e676b
commit 9a1f4875fc
2 changed files with 70 additions and 30 deletions

View File

@ -46,16 +46,23 @@ public class LiveActivityFragment extends AbstractChartFragment {
private PieData mTotalStepsData; private PieData mTotalStepsData;
private class Steps { private class Steps {
private int initialSteps;
private int steps; private int steps;
private long lastTimestamp; private long lastTimestamp;
private int currentStepsPerMinute; private int currentStepsPerMinute;
private int maxStepsPerMinute;
public int getStepsPerMinute() { public int getStepsPerMinute() {
return currentStepsPerMinute; return currentStepsPerMinute;
} }
public int getTotalSteps() { public int getTotalSteps() {
return steps; return steps - initialSteps;
}
public int getMaxStepsPerMinute() {
return maxStepsPerMinute;
} }
public void updateCurrentSteps(int newSteps, long timestamp) { public void updateCurrentSteps(int newSteps, long timestamp) {
@ -63,6 +70,10 @@ public class LiveActivityFragment extends AbstractChartFragment {
if (steps == 0) { if (steps == 0) {
steps = newSteps; steps = newSteps;
lastTimestamp = timestamp; lastTimestamp = timestamp;
if (newSteps > 0) {
initialSteps = newSteps;
}
return; return;
} }
@ -70,6 +81,7 @@ public class LiveActivityFragment extends AbstractChartFragment {
int stepsDelta = newSteps - steps; int stepsDelta = newSteps - steps;
long timeDelta = timestamp - lastTimestamp; long timeDelta = timestamp - lastTimestamp;
currentStepsPerMinute = calculateStepsPerMinute(stepsDelta, timeDelta); currentStepsPerMinute = calculateStepsPerMinute(stepsDelta, timeDelta);
maxStepsPerMinute = Math.max(maxStepsPerMinute, currentStepsPerMinute);
steps = newSteps; steps = newSteps;
lastTimestamp = timestamp; lastTimestamp = timestamp;
} else { } else {
@ -123,8 +135,8 @@ public class LiveActivityFragment extends AbstractChartFragment {
stepsPerMinuteEntry.setVal(mSteps.getStepsPerMinute()); stepsPerMinuteEntry.setVal(mSteps.getStepsPerMinute());
mStepsPerMinuteCurrentChart.setCenterText(NumberFormat.getNumberInstance().format(mSteps.getStepsPerMinute())); mStepsPerMinuteCurrentChart.setCenterText(NumberFormat.getNumberInstance().format(mSteps.getStepsPerMinute()));
mTotalStepsData.notifyDataChanged(); // mTotalStepsData.notifyDataChanged();
mStepsPerMinuteData.notifyDataChanged(); // mStepsPerMinuteData.notifyDataChanged();
renderCharts(); renderCharts();
} }
@ -142,12 +154,12 @@ public class LiveActivityFragment extends AbstractChartFragment {
mStepsPerMinuteCurrentChart = (PieChart) rootView.findViewById(R.id.livechart_steps_per_minute_current); mStepsPerMinuteCurrentChart = (PieChart) rootView.findViewById(R.id.livechart_steps_per_minute_current);
mStepsTotalChart = (PieChart) rootView.findViewById(R.id.livechart_steps_total); mStepsTotalChart = (PieChart) rootView.findViewById(R.id.livechart_steps_total);
totalStepsEntry = new Entry(0, 0); totalStepsEntry = new Entry(10, 0);
stepsPerMinuteEntry = new Entry(0, 0); stepsPerMinuteEntry = new Entry(10, 0);
setupHistoryChart(mStepsPerMinuteHistoryChart); setupHistoryChart(mStepsPerMinuteHistoryChart);
mStepsPerMinuteData = setupCurrentChart(mStepsPerMinuteCurrentChart, stepsPerMinuteEntry); mStepsPerMinuteData = setupCurrentChart(mStepsPerMinuteCurrentChart, stepsPerMinuteEntry, "Steps/min");
mTotalStepsData = setupTotalStepsChart(mStepsTotalChart, totalStepsEntry); mTotalStepsData = setupTotalStepsChart(mStepsTotalChart, totalStepsEntry, "Total Steps");
return rootView; return rootView;
} }
@ -170,12 +182,13 @@ public class LiveActivityFragment extends AbstractChartFragment {
super.onDestroyView(); super.onDestroyView();
} }
private PieData setupCurrentChart(PieChart chart, Entry entry) { private PieData setupCurrentChart(PieChart chart, Entry entry, String title) {
chart.setBackgroundColor(BACKGROUND_COLOR); chart.setBackgroundColor(BACKGROUND_COLOR);
chart.setDescriptionColor(DESCRIPTION_COLOR); chart.setDescriptionColor(DESCRIPTION_COLOR);
chart.setDescription(""); chart.setDescription(title);
chart.setNoDataTextDescription(""); chart.setNoDataTextDescription("");
chart.setNoDataText(""); chart.setNoDataText("");
chart.setDrawSliceText(false);
PieData data = new PieData(); PieData data = new PieData();
List<Entry> entries = new ArrayList<>(); List<Entry> entries = new ArrayList<>();
@ -186,7 +199,7 @@ public class LiveActivityFragment extends AbstractChartFragment {
entries.add(entry); entries.add(entry);
colors.add(akActivity.color); colors.add(akActivity.color);
//we don't want labels on the pie chart //we don't want labels on the pie chart
data.addXValue(""); // data.addXValue("");
// entries.add(new Entry((20), 1)); // entries.add(new Entry((20), 1));
// colors.add(Color.GRAY); // colors.add(Color.GRAY);
@ -197,7 +210,7 @@ public class LiveActivityFragment extends AbstractChartFragment {
set.setColors(colors); set.setColors(colors);
data.setDataSet(set); data.setDataSet(set);
//this hides the values (numeric) added to the set. These would be shown aside the strings set with addXValue above //this hides the values (numeric) added to the set. These would be shown aside the strings set with addXValue above
data.setDrawValues(false); // data.setDrawValues(false);
chart.setData(data); chart.setData(data);
chart.getLegend().setEnabled(false); chart.getLegend().setEnabled(false);
@ -205,8 +218,8 @@ public class LiveActivityFragment extends AbstractChartFragment {
return data; return data;
} }
private PieData setupTotalStepsChart(PieChart chart, Entry entry) { private PieData setupTotalStepsChart(PieChart chart, Entry entry, String label) {
return setupCurrentChart(chart, entry); // at the moment, these look the same return setupCurrentChart(chart, entry, label); // at the moment, these look the same
} }
@ -244,16 +257,21 @@ public class LiveActivityFragment extends AbstractChartFragment {
return getContext().getString(R.string.liveactivity_live_activity); return getContext().getString(R.string.liveactivity_live_activity);
} }
@Override
protected void refresh() {
// do nothing, we don't have any db interaction
}
@Override @Override
protected void refreshInBackground(DBHandler db, GBDevice device) { protected void refreshInBackground(DBHandler db, GBDevice device) {
} }
@Override @Override
protected void renderCharts() { protected void renderCharts() {
mStepsPerMinuteCurrentChart.animateXY(50, 50); mStepsTotalChart.invalidate();
mStepsTotalChart.animateXY(50, 50); mStepsPerMinuteCurrentChart.invalidate();
mStepsPerMinuteHistoryChart.invalidate(); // mStepsPerMinuteCurrentChart.animateXY(50, 50);
// mStepsTotalChart.animateXY(50, 50);
// mStepsPerMinuteHistoryChart.invalidate();
} }
@Override @Override

View File

@ -3,6 +3,41 @@
android:orientation="vertical" android:layout_width="match_parent" android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!--
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/livechart_steps_total"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="20">
</com.github.mikephil.charting.charts.LineChart>
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/livechart_steps_per_minute_current"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="20">
</com.github.mikephil.charting.charts.LineChart>
-->
<com.github.mikephil.charting.charts.PieChart
android:id="@+id/livechart_steps_total"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="20">
</com.github.mikephil.charting.charts.PieChart>
<com.github.mikephil.charting.charts.PieChart
android:id="@+id/livechart_steps_per_minute_current"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="20">
</com.github.mikephil.charting.charts.PieChart>
</LinearLayout>
<com.github.mikephil.charting.charts.LineChart <com.github.mikephil.charting.charts.LineChart
android:id="@+id/livechart_steps_per_minute_history" android:id="@+id/livechart_steps_per_minute_history"
android:layout_width="fill_parent" android:layout_width="fill_parent"
@ -10,18 +45,5 @@
android:layout_weight="20"> android:layout_weight="20">
</com.github.mikephil.charting.charts.LineChart> </com.github.mikephil.charting.charts.LineChart>
<com.github.mikephil.charting.charts.PieChart
android:id="@+id/livechart_steps_per_minute_current"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="20">
</com.github.mikephil.charting.charts.PieChart>
<com.github.mikephil.charting.charts.PieChart
android:id="@+id/livechart_steps_total"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="20">
</com.github.mikephil.charting.charts.PieChart>
</LinearLayout> </LinearLayout>