mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-13 03:07:32 +01:00
More WIP on live activity:
- keep screen on while live activity is visible - hide the date bar (prev&forward buttons) - live activity chart is still nowhere near usable
This commit is contained in:
parent
9a1f4875fc
commit
8f4e933e30
@ -6,8 +6,11 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.github.mikephil.charting.charts.BarLineChartBase;
|
||||
import com.github.mikephil.charting.charts.Chart;
|
||||
@ -145,19 +148,24 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||
}
|
||||
|
||||
private void setStartDate(Date date) {
|
||||
((ChartsHost) getHost()).setStartDate(date);
|
||||
getChartsHost().setStartDate(date);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected ChartsHost getChartsHost() {
|
||||
return (ChartsHost) getActivity();
|
||||
}
|
||||
|
||||
private void setEndDate(Date date) {
|
||||
((ChartsHost) getHost()).setEndDate(date);
|
||||
getChartsHost().setEndDate(date);
|
||||
}
|
||||
|
||||
public Date getStartDate() {
|
||||
return ((ChartsHost) getHost()).getStartDate();
|
||||
return getChartsHost().getStartDate();
|
||||
}
|
||||
|
||||
public Date getEndDate() {
|
||||
return ((ChartsHost) getHost()).getEndDate();
|
||||
return getChartsHost().getEndDate();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -169,11 +177,16 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||
@Override
|
||||
protected void onMadeVisibleInActivity() {
|
||||
super.onMadeVisibleInActivity();
|
||||
showDateBar(true);
|
||||
if (isChartDirty()) {
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
||||
protected void showDateBar(boolean show) {
|
||||
getChartsHost().getDateBar().setVisibility(show ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
@ -333,10 +346,13 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||
* #renderCharts
|
||||
*/
|
||||
protected void refresh() {
|
||||
if (((ChartsHost) getHost()).getDevice() != null) {
|
||||
mChartDirty = false;
|
||||
updateDateInfo(getStartDate(), getEndDate());
|
||||
createRefreshTask("Visualizing data", getActivity()).execute();
|
||||
ChartsHost chartsHost = getChartsHost();
|
||||
if (chartsHost != null) {
|
||||
if (chartsHost.getDevice() != null) {
|
||||
mChartDirty = false;
|
||||
updateDateInfo(getStartDate(), getEndDate());
|
||||
createRefreshTask("Visualizing data", getActivity()).execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -545,7 +561,10 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||
|
||||
@Override
|
||||
protected void doInBackground(DBHandler db) {
|
||||
refreshInBackground(db, ((ChartsHost) getHost()).getDevice());
|
||||
ChartsHost chartsHost = getChartsHost();
|
||||
if (chartsHost != null) {
|
||||
refreshInBackground(db, chartsHost.getDevice());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -582,9 +601,9 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||
|
||||
protected void updateDateInfo(Date from, Date to) {
|
||||
if (from.equals(to)) {
|
||||
((ChartsHost) getHost()).setDateInfo(DateTimeUtils.formatDate(from));
|
||||
getChartsHost().setDateInfo(DateTimeUtils.formatDate(from));
|
||||
} else {
|
||||
((ChartsHost) getHost()).setDateInfo(DateTimeUtils.formatDateRange(from, to));
|
||||
getChartsHost().setDateInfo(DateTimeUtils.formatDateRange(from, to));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ import android.support.v4.view.ViewPager;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
@ -59,6 +60,7 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
|
||||
}
|
||||
};
|
||||
private GBDevice mGBDevice;
|
||||
private ViewGroup dateBar;
|
||||
|
||||
private void refreshBusyState(GBDevice dev) {
|
||||
if (dev.isBusy()) {
|
||||
@ -95,6 +97,8 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
|
||||
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
|
||||
viewPager.setAdapter(getPagerAdapter());
|
||||
|
||||
dateBar = (ViewGroup) findViewById(R.id.charts_date_bar);
|
||||
|
||||
mProgressBar = (ProgressBar) findViewById(R.id.charts_progress);
|
||||
mPrevButton = (Button) findViewById(R.id.charts_previous);
|
||||
mPrevButton.setOnClickListener(new View.OnClickListener() {
|
||||
@ -188,6 +192,11 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
|
||||
return new SectionsPagerAdapter(fragmentManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViewGroup getDateBar() {
|
||||
return dateBar;
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@link FragmentStatePagerAdapter} that returns a fragment corresponding to
|
||||
* one of the sections/tabs/pages.
|
||||
|
@ -1,5 +1,7 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
||||
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
@ -17,4 +19,6 @@ public interface ChartsHost {
|
||||
Date getStartDate();
|
||||
Date getEndDate();
|
||||
void setDateInfo(String dateInfo);
|
||||
|
||||
ViewGroup getDateBar();
|
||||
}
|
||||
|
@ -4,29 +4,26 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.github.mikephil.charting.charts.BarLineChartBase;
|
||||
import com.github.mikephil.charting.charts.Chart;
|
||||
import com.github.mikephil.charting.charts.PieChart;
|
||||
import com.github.mikephil.charting.components.XAxis;
|
||||
import com.github.mikephil.charting.components.YAxis;
|
||||
import com.github.mikephil.charting.data.ChartData;
|
||||
import com.github.mikephil.charting.data.Entry;
|
||||
import com.github.mikephil.charting.data.PieData;
|
||||
import com.github.mikephil.charting.data.PieDataSet;
|
||||
import com.github.mikephil.charting.data.LineData;
|
||||
import com.github.mikephil.charting.data.LineDataSet;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -42,8 +39,8 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(LiveActivityFragment.class);
|
||||
private Entry totalStepsEntry;
|
||||
private Entry stepsPerMinuteEntry;
|
||||
private PieData mStepsPerMinuteData;
|
||||
private PieData mTotalStepsData;
|
||||
private LineDataSet mStepsPerMinuteData;
|
||||
private LineDataSet mTotalStepsData;
|
||||
|
||||
private class Steps {
|
||||
private int initialSteps;
|
||||
@ -109,8 +106,8 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
||||
|
||||
|
||||
private BarLineChartBase mStepsPerMinuteHistoryChart;
|
||||
private PieChart mStepsPerMinuteCurrentChart;
|
||||
private PieChart mStepsTotalChart;
|
||||
private BarLineChartBase mStepsPerMinuteCurrentChart;
|
||||
private BarLineChartBase mStepsTotalChart;
|
||||
|
||||
private Steps mSteps = new Steps();
|
||||
|
||||
@ -130,13 +127,18 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
||||
|
||||
private void refreshCurrentSteps(int steps, long timestamp) {
|
||||
mSteps.updateCurrentSteps(steps, timestamp);
|
||||
// Or: count down the steps until goal reached? And then flash GOAL REACHED -> Set stretch goal
|
||||
totalStepsEntry.setVal(mSteps.getTotalSteps());
|
||||
mStepsTotalChart.setCenterText(NumberFormat.getNumberInstance().format(mSteps.getTotalSteps()));
|
||||
LOG.info("Steps: " + steps + "total: " + mSteps.getTotalSteps() + " current: " + mSteps.getStepsPerMinute());
|
||||
// mStepsTotalChart.setCenterText(NumberFormat.getNumberInstance().format(mSteps.getTotalSteps()));
|
||||
mStepsPerMinuteCurrentChart.getAxisLeft().setAxisMaxValue(mSteps.getMaxStepsPerMinute());
|
||||
stepsPerMinuteEntry.setVal(mSteps.getStepsPerMinute());
|
||||
mStepsPerMinuteCurrentChart.setCenterText(NumberFormat.getNumberInstance().format(mSteps.getStepsPerMinute()));
|
||||
// mStepsPerMinuteCurrentChart.setCenterText(NumberFormat.getNumberInstance().format(mSteps.getStepsPerMinute()));
|
||||
|
||||
// mTotalStepsData.notifyDataChanged();
|
||||
// mStepsPerMinuteData.notifyDataChanged();
|
||||
mStepsTotalChart.getData().notifyDataChanged();
|
||||
mTotalStepsData.notifyDataSetChanged();
|
||||
mStepsPerMinuteCurrentChart.getData().notifyDataChanged();
|
||||
mStepsPerMinuteData.notifyDataSetChanged();
|
||||
|
||||
renderCharts();
|
||||
}
|
||||
@ -151,11 +153,11 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
||||
View rootView = inflater.inflate(R.layout.fragment_live_activity, container, false);
|
||||
|
||||
mStepsPerMinuteHistoryChart = (BarLineChartBase) rootView.findViewById(R.id.livechart_steps_per_minute_history);
|
||||
mStepsPerMinuteCurrentChart = (PieChart) rootView.findViewById(R.id.livechart_steps_per_minute_current);
|
||||
mStepsTotalChart = (PieChart) rootView.findViewById(R.id.livechart_steps_total);
|
||||
mStepsPerMinuteCurrentChart = (BarLineChartBase) rootView.findViewById(R.id.livechart_steps_per_minute_current);
|
||||
mStepsTotalChart = (BarLineChartBase) rootView.findViewById(R.id.livechart_steps_total);
|
||||
|
||||
totalStepsEntry = new Entry(10, 0);
|
||||
stepsPerMinuteEntry = new Entry(10, 0);
|
||||
totalStepsEntry = new Entry(0, 1);
|
||||
stepsPerMinuteEntry = new Entry(0, 1);
|
||||
|
||||
setupHistoryChart(mStepsPerMinuteHistoryChart);
|
||||
mStepsPerMinuteData = setupCurrentChart(mStepsPerMinuteCurrentChart, stepsPerMinuteEntry, "Steps/min");
|
||||
@ -165,15 +167,21 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
protected void onMadeVisibleInActivity() {
|
||||
GBApplication.deviceService().onEnableRealtimeSteps(true);
|
||||
super.onMadeVisibleInActivity();
|
||||
if (getActivity() != null) {
|
||||
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
protected void onMadeInvisibleInActivity() {
|
||||
GBApplication.deviceService().onEnableRealtimeSteps(false);
|
||||
if (getActivity() != null) {
|
||||
getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
}
|
||||
super.onMadeInvisibleInActivity();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -182,47 +190,57 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
private PieData setupCurrentChart(PieChart chart, Entry entry, String title) {
|
||||
private LineDataSet setupCurrentChart(BarLineChartBase chart, Entry entry, String title) {
|
||||
mStepsPerMinuteCurrentChart.getAxisLeft().setAxisMaxValue(300);
|
||||
return setupCommonChart(chart, entry, title);
|
||||
}
|
||||
|
||||
private LineDataSet setupCommonChart(BarLineChartBase chart, Entry entry, String title) {
|
||||
chart.setBackgroundColor(BACKGROUND_COLOR);
|
||||
chart.setDescriptionColor(DESCRIPTION_COLOR);
|
||||
chart.setDescription(title);
|
||||
chart.setNoDataTextDescription("");
|
||||
chart.setNoDataText("");
|
||||
chart.setDrawSliceText(false);
|
||||
chart.getAxisRight().setEnabled(false);
|
||||
// chart.setDrawSliceText(false);
|
||||
|
||||
PieData data = new PieData();
|
||||
List<Entry> entries = new ArrayList<>();
|
||||
List<String> xLabels = new ArrayList<>();
|
||||
List<Integer> colors = new ArrayList<>();
|
||||
|
||||
int value = 0;
|
||||
chart.setCenterText(NumberFormat.getNumberInstance().format(value));
|
||||
// chart.setCenterText(NumberFormat.getNumberInstance().format(value));
|
||||
entries.add(new Entry(0,0));
|
||||
entries.add(entry);
|
||||
entries.add(new Entry(0,2));
|
||||
colors.add(akActivity.color);
|
||||
//we don't want labels on the pie chart
|
||||
// data.addXValue("");
|
||||
xLabels.add("");
|
||||
xLabels.add("");
|
||||
xLabels.add("");
|
||||
|
||||
// entries.add(new Entry((20), 1));
|
||||
// colors.add(Color.GRAY);
|
||||
// //we don't want labels on the pie chart
|
||||
// data.addXValue("");
|
||||
|
||||
PieDataSet set = new PieDataSet(entries, "");
|
||||
LineDataSet set = new LineDataSet(entries, "");
|
||||
set.setColors(colors);
|
||||
data.setDataSet(set);
|
||||
LineData data = new LineData(xLabels, set);
|
||||
//this hides the values (numeric) added to the set. These would be shown aside the strings set with addXValue above
|
||||
// data.setDrawValues(false);
|
||||
chart.setData(data);
|
||||
|
||||
chart.getLegend().setEnabled(false);
|
||||
|
||||
return data;
|
||||
return set;
|
||||
}
|
||||
|
||||
private PieData setupTotalStepsChart(PieChart chart, Entry entry, String label) {
|
||||
return setupCurrentChart(chart, entry, label); // at the moment, these look the same
|
||||
private LineDataSet setupTotalStepsChart(BarLineChartBase chart, Entry entry, String label) {
|
||||
mStepsTotalChart.getAxisLeft().setAxisMaxValue(5000); // TODO: use daily goal - already reached steps
|
||||
return setupCommonChart(chart, entry, label); // at the moment, these look the same
|
||||
}
|
||||
|
||||
|
||||
private void setupHistoryChart(BarLineChartBase chart) {
|
||||
chart.setBackgroundColor(BACKGROUND_COLOR);
|
||||
chart.setDescriptionColor(DESCRIPTION_COLOR);
|
||||
@ -257,20 +275,27 @@ public class LiveActivityFragment extends AbstractChartFragment {
|
||||
return getContext().getString(R.string.liveactivity_live_activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void showDateBar(boolean show) {
|
||||
// never show the data bar
|
||||
super.showDateBar(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refresh() {
|
||||
// do nothing, we don't have any db interaction
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refreshInBackground(DBHandler db, GBDevice device) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderCharts() {
|
||||
mStepsTotalChart.invalidate();
|
||||
mStepsPerMinuteCurrentChart.invalidate();
|
||||
// mStepsPerMinuteCurrentChart.animateXY(50, 50);
|
||||
// mStepsTotalChart.animateXY(50, 50);
|
||||
// mStepsTotalChart.invalidate();
|
||||
// mStepsPerMinuteCurrentChart.invalidate();
|
||||
mStepsPerMinuteCurrentChart.animateY(150);
|
||||
mStepsTotalChart.animateY(150);
|
||||
// mStepsPerMinuteHistoryChart.invalidate();
|
||||
}
|
||||
|
||||
|
@ -46,11 +46,14 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
||||
|
||||
@Override
|
||||
protected void refreshInBackground(DBHandler db, GBDevice device) {
|
||||
Calendar day = Calendar.getInstance();
|
||||
day.setTime(((ChartsHost) getHost()).getEndDate());
|
||||
//NB: we could have omitted the day, but this way we can move things to the past easily
|
||||
refreshDaySteps(db, mTodayStepsChart, day, device);
|
||||
refreshWeekBeforeSteps(db, mWeekStepsChart, day, device);
|
||||
ChartsHost chartsHost = getChartsHost();
|
||||
if (chartsHost != null) {
|
||||
Calendar day = Calendar.getInstance();
|
||||
day.setTime(chartsHost.getEndDate());
|
||||
//NB: we could have omitted the day, but this way we can move things to the past easily
|
||||
refreshDaySteps(db, mTodayStepsChart, day, device);
|
||||
refreshWeekBeforeSteps(db, mWeekStepsChart, day, device);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -128,7 +131,7 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
||||
|
||||
View rootView = inflater.inflate(R.layout.fragment_sleepchart, container, false);
|
||||
|
||||
GBDevice device = ((ChartsHost) getHost()).getDevice();
|
||||
GBDevice device = getChartsHost().getDevice();
|
||||
if (device != null) {
|
||||
mTargetSteps = MiBandCoordinator.getFitnessGoal(device.getAddress());
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
tools:context="nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/charts_date_bar"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
@ -8,34 +8,34 @@
|
||||
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.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.LineChart>
|
||||
</com.github.mikephil.charting.charts.PieChart>
|
||||
|
||||
<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.LineChart>
|
||||
</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>
|
||||
|
||||
<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
|
||||
|
Loading…
x
Reference in New Issue
Block a user