2015-08-03 23:09:49 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
2015-06-11 23:34:16 +02:00
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
2015-07-11 00:03:41 +02:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2015-06-11 23:34:16 +02:00
|
|
|
|
2015-08-03 01:17:02 +02:00
|
|
|
import com.github.mikephil.charting.animation.Easing;
|
2015-06-11 23:34:16 +02:00
|
|
|
import com.github.mikephil.charting.charts.BarLineChartBase;
|
2015-07-14 00:29:32 +02:00
|
|
|
import com.github.mikephil.charting.charts.Chart;
|
2015-06-11 23:34:16 +02:00
|
|
|
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.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
2015-08-03 01:17:02 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
2015-08-17 02:22:16 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
2015-07-27 23:49:53 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
2015-06-11 23:34:16 +02:00
|
|
|
|
|
|
|
|
2015-07-11 00:03:41 +02:00
|
|
|
public class ActivitySleepChartFragment extends AbstractChartFragment {
|
|
|
|
protected static final Logger LOG = LoggerFactory.getLogger(ActivitySleepChartFragment.class);
|
2015-06-11 23:34:16 +02:00
|
|
|
|
|
|
|
private BarLineChartBase mChart;
|
|
|
|
|
|
|
|
private int mSmartAlarmFrom = -1;
|
|
|
|
private int mSmartAlarmTo = -1;
|
|
|
|
private int mTimestampFrom = -1;
|
|
|
|
private int mSmartAlarmGoneOff = -1;
|
|
|
|
|
|
|
|
@Override
|
2015-07-11 00:03:41 +02:00
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
|
|
Bundle savedInstanceState) {
|
|
|
|
View rootView = inflater.inflate(R.layout.fragment_charts, container, false);
|
2015-06-11 23:34:16 +02:00
|
|
|
|
2015-07-14 00:29:32 +02:00
|
|
|
mChart = (BarLineChartBase) rootView.findViewById(R.id.activitysleepchart);
|
2015-06-11 23:34:16 +02:00
|
|
|
|
2015-07-11 00:03:41 +02:00
|
|
|
setupChart();
|
2015-06-11 23:34:16 +02:00
|
|
|
|
2015-07-11 00:03:41 +02:00
|
|
|
return rootView;
|
|
|
|
}
|
2015-06-11 23:34:16 +02:00
|
|
|
|
2015-08-25 00:33:37 +02:00
|
|
|
@Override
|
|
|
|
public String getTitle() {
|
|
|
|
return getString(R.string.activity_sleepchart_activity_and_sleep);
|
|
|
|
}
|
|
|
|
|
2015-07-11 00:03:41 +02:00
|
|
|
private void setupChart() {
|
|
|
|
mChart.setBackgroundColor(BACKGROUND_COLOR);
|
|
|
|
mChart.setDescriptionColor(DESCRIPTION_COLOR);
|
|
|
|
configureBarLineChartDefaults(mChart);
|
2015-06-11 23:34:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
XAxis x = mChart.getXAxis();
|
|
|
|
x.setDrawLabels(true);
|
|
|
|
x.setDrawGridLines(false);
|
|
|
|
x.setEnabled(true);
|
2015-07-11 00:03:41 +02:00
|
|
|
x.setTextColor(CHART_TEXT_COLOR);
|
2015-06-18 23:41:54 +02:00
|
|
|
x.setDrawLimitLinesBehindData(true);
|
2015-06-11 23:34:16 +02:00
|
|
|
|
|
|
|
YAxis y = mChart.getAxisLeft();
|
|
|
|
y.setDrawGridLines(false);
|
2015-06-16 21:04:44 +02:00
|
|
|
// y.setDrawLabels(false);
|
2015-06-17 00:05:55 +02:00
|
|
|
// TODO: make fixed max value optional
|
|
|
|
y.setAxisMaxValue(1f);
|
2015-06-11 23:34:16 +02:00
|
|
|
y.setDrawTopYLabelEntry(false);
|
2015-07-11 00:03:41 +02:00
|
|
|
y.setTextColor(CHART_TEXT_COLOR);
|
2015-06-11 23:34:16 +02:00
|
|
|
|
|
|
|
// y.setLabelCount(5);
|
|
|
|
y.setEnabled(true);
|
|
|
|
|
|
|
|
YAxis yAxisRight = mChart.getAxisRight();
|
|
|
|
yAxisRight.setDrawGridLines(false);
|
|
|
|
yAxisRight.setEnabled(false);
|
|
|
|
yAxisRight.setDrawLabels(false);
|
|
|
|
yAxisRight.setDrawTopYLabelEntry(false);
|
2015-07-11 00:03:41 +02:00
|
|
|
yAxisRight.setTextColor(CHART_TEXT_COLOR);
|
2015-06-11 23:34:16 +02:00
|
|
|
|
2015-08-25 00:33:37 +02:00
|
|
|
// refreshIfVisible();
|
2015-08-03 01:17:02 +02:00
|
|
|
refresh();
|
2015-06-11 23:34:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-08-17 02:22:16 +02:00
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
String action = intent.getAction();
|
|
|
|
if (action.equals(ChartsHost.REFRESH)) {
|
|
|
|
// TODO: use LimitLines to visualize smart alarms?
|
|
|
|
mSmartAlarmFrom = intent.getIntExtra("smartalarm_from", -1);
|
|
|
|
mSmartAlarmTo = intent.getIntExtra("smartalarm_to", -1);
|
|
|
|
mTimestampFrom = intent.getIntExtra("recording_base_timestamp", -1);
|
|
|
|
mSmartAlarmGoneOff = intent.getIntExtra("alarm_gone_off", -1);
|
|
|
|
refresh();
|
|
|
|
} else {
|
|
|
|
super.onReceive(context, intent);
|
|
|
|
}
|
2015-06-11 23:34:16 +02:00
|
|
|
}
|
|
|
|
|
2015-08-03 01:17:02 +02:00
|
|
|
@Override
|
2015-08-25 00:33:37 +02:00
|
|
|
protected void refreshInBackground(DBHandler db, GBDevice device) {
|
|
|
|
List<ActivitySample> samples = getSamples(db, device);
|
|
|
|
refresh(device, mChart, samples);
|
2015-08-03 01:17:02 +02:00
|
|
|
|
|
|
|
mChart.getLegend().setTextColor(LEGEND_TEXT_COLOR);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void renderCharts() {
|
|
|
|
mChart.animateX(500, Easing.EasingOption.EaseInOutQuart);
|
|
|
|
}
|
|
|
|
|
2015-07-14 00:29:32 +02:00
|
|
|
protected void setupLegend(Chart chart) {
|
2015-06-17 00:05:55 +02:00
|
|
|
List<Integer> legendColors = new ArrayList<>(3);
|
|
|
|
List<String> legendLabels = new ArrayList<>(3);
|
|
|
|
legendColors.add(akActivity.color);
|
|
|
|
legendLabels.add(akActivity.label);
|
|
|
|
legendColors.add(akLightSleep.color);
|
|
|
|
legendLabels.add(akLightSleep.label);
|
|
|
|
legendColors.add(akDeepSleep.color);
|
|
|
|
legendLabels.add(akDeepSleep.label);
|
|
|
|
chart.getLegend().setColors(legendColors);
|
|
|
|
chart.getLegend().setLabels(legendLabels);
|
|
|
|
}
|
2015-07-13 21:54:46 +02:00
|
|
|
|
|
|
|
@Override
|
2015-08-03 01:17:02 +02:00
|
|
|
protected List<ActivitySample> getSamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) {
|
|
|
|
return getAllSamples(db, device, tsFrom, tsTo);
|
2015-07-13 21:54:46 +02:00
|
|
|
}
|
2015-06-11 23:34:16 +02:00
|
|
|
}
|