155 lines
5.1 KiB
Java
155 lines
5.1 KiB
Java
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.IntentFilter;
|
|
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 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 org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import java.util.List;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
|
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
|
|
|
|
public class LiveActivityFragment extends AbstractChartFragment {
|
|
private static final Logger LOG = LoggerFactory.getLogger(LiveActivityFragment.class);
|
|
|
|
private BarLineChartBase mStepsPerMinuteHistoryChart;
|
|
private PieChart mStepsPerMinuteCurrentChart;
|
|
|
|
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
|
@Override
|
|
public void onReceive(Context context, Intent intent) {
|
|
String action = intent.getAction();
|
|
switch (action) {
|
|
case DeviceService.ACTION_REALTIME_STEPS:
|
|
int steps = intent.getIntExtra(DeviceService.EXTRA_REALTIME_STEPS, 0);
|
|
updateCurrentSteps(steps);
|
|
break;
|
|
}
|
|
}
|
|
};
|
|
|
|
private void updateCurrentSteps(int steps) {
|
|
LOG.warn("STEPS: " + steps);
|
|
}
|
|
|
|
|
|
@Nullable
|
|
@Override
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
IntentFilter filterLocal = new IntentFilter();
|
|
filterLocal.addAction(DeviceService.ACTION_ENABLE_REALTIME_STEPS);
|
|
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mReceiver, filterLocal);
|
|
|
|
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);
|
|
|
|
setupHistoryChart(mStepsPerMinuteHistoryChart);
|
|
setupCurrentChart(mStepsPerMinuteCurrentChart);
|
|
|
|
return rootView;
|
|
}
|
|
|
|
@Override
|
|
public void onStart() {
|
|
super.onStart();
|
|
GBApplication.deviceService().onEnableRealtimeSteps(true);
|
|
}
|
|
|
|
@Override
|
|
public void onStop() {
|
|
super.onStop();
|
|
GBApplication.deviceService().onEnableRealtimeSteps(false);
|
|
}
|
|
|
|
@Override
|
|
public void onDestroyView() {
|
|
LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mReceiver);
|
|
super.onDestroyView();
|
|
}
|
|
|
|
private void setupCurrentChart(PieChart chart) {
|
|
chart.setBackgroundColor(BACKGROUND_COLOR);
|
|
chart.setDescriptionColor(DESCRIPTION_COLOR);
|
|
chart.setDescription("");
|
|
chart.setNoDataTextDescription("");
|
|
chart.setNoDataText("");
|
|
}
|
|
|
|
private void setupHistoryChart(BarLineChartBase chart) {
|
|
chart.setBackgroundColor(BACKGROUND_COLOR);
|
|
chart.setDescriptionColor(DESCRIPTION_COLOR);
|
|
chart.setDescription("");
|
|
|
|
configureBarLineChartDefaults(chart);
|
|
|
|
XAxis x = chart.getXAxis();
|
|
x.setDrawLabels(true);
|
|
x.setDrawGridLines(false);
|
|
x.setEnabled(true);
|
|
x.setTextColor(CHART_TEXT_COLOR);
|
|
x.setDrawLimitLinesBehindData(true);
|
|
|
|
YAxis y = chart.getAxisLeft();
|
|
y.setDrawGridLines(false);
|
|
y.setDrawTopYLabelEntry(false);
|
|
y.setTextColor(CHART_TEXT_COLOR);
|
|
|
|
y.setEnabled(true);
|
|
|
|
YAxis yAxisRight = chart.getAxisRight();
|
|
yAxisRight.setDrawGridLines(false);
|
|
yAxisRight.setEnabled(false);
|
|
yAxisRight.setDrawLabels(false);
|
|
yAxisRight.setDrawTopYLabelEntry(false);
|
|
yAxisRight.setTextColor(CHART_TEXT_COLOR);
|
|
}
|
|
|
|
@Override
|
|
public String getTitle() {
|
|
return getContext().getString(R.string.liveactivity_live_activity);
|
|
}
|
|
|
|
@Override
|
|
protected void refreshInBackground(DBHandler db, GBDevice device) {
|
|
|
|
}
|
|
|
|
@Override
|
|
protected void renderCharts() {
|
|
mStepsPerMinuteCurrentChart.animateXY(50, 50);
|
|
mStepsPerMinuteHistoryChart.invalidate();
|
|
}
|
|
|
|
@Override
|
|
protected List<ActivitySample> getSamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) {
|
|
throw new UnsupportedOperationException("no db access supported for live activity");
|
|
}
|
|
|
|
@Override
|
|
protected void setupLegend(Chart chart) {
|
|
// no legend
|
|
}
|
|
}
|