2015-08-03 23:09:49 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
2015-07-11 00:03:41 +02:00
|
|
|
|
2015-08-17 02:22:16 +02:00
|
|
|
import android.content.BroadcastReceiver;
|
2015-08-03 01:17:02 +02:00
|
|
|
import android.content.Context;
|
2015-08-17 02:22:16 +02:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.IntentFilter;
|
2016-04-08 23:02:50 +02:00
|
|
|
import android.os.AsyncTask;
|
2015-08-17 02:22:16 +02:00
|
|
|
import android.os.Bundle;
|
2015-09-04 21:55:29 +02:00
|
|
|
import android.support.annotation.Nullable;
|
2015-08-16 23:27:18 +02:00
|
|
|
import android.support.v4.app.FragmentActivity;
|
2015-08-17 02:22:16 +02:00
|
|
|
import android.support.v4.content.LocalBroadcastManager;
|
2015-09-04 21:55:29 +02:00
|
|
|
import android.view.View;
|
2015-07-11 00:03:41 +02:00
|
|
|
|
|
|
|
import com.github.mikephil.charting.charts.BarLineChartBase;
|
|
|
|
import com.github.mikephil.charting.charts.Chart;
|
2016-02-27 11:18:16 +01:00
|
|
|
import com.github.mikephil.charting.components.YAxis;
|
2015-07-12 23:42:23 +02:00
|
|
|
import com.github.mikephil.charting.data.BarData;
|
2015-07-11 00:03:41 +02:00
|
|
|
import com.github.mikephil.charting.data.BarDataSet;
|
|
|
|
import com.github.mikephil.charting.data.BarEntry;
|
2016-02-26 23:45:17 +01:00
|
|
|
import com.github.mikephil.charting.data.CombinedData;
|
|
|
|
import com.github.mikephil.charting.data.Entry;
|
|
|
|
import com.github.mikephil.charting.data.LineData;
|
|
|
|
import com.github.mikephil.charting.data.LineDataSet;
|
2016-03-07 22:45:44 +01:00
|
|
|
import com.github.mikephil.charting.interfaces.datasets.IBarDataSet;
|
2015-07-11 00:03:41 +02:00
|
|
|
|
2015-07-12 23:42:23 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
2015-07-11 00:03:41 +02:00
|
|
|
import java.util.ArrayList;
|
2015-08-17 02:22:16 +02:00
|
|
|
import java.util.Arrays;
|
2015-07-11 00:03:41 +02:00
|
|
|
import java.util.Calendar;
|
2016-03-07 23:17:02 +01:00
|
|
|
import java.util.Collections;
|
2015-07-12 23:42:23 +02:00
|
|
|
import java.util.Date;
|
|
|
|
import java.util.GregorianCalendar;
|
2015-08-17 02:22:16 +02:00
|
|
|
import java.util.HashSet;
|
2015-07-11 00:03:41 +02:00
|
|
|
import java.util.List;
|
2015-08-17 02:22:16 +02:00
|
|
|
import java.util.Set;
|
2015-07-11 00:03:41 +02:00
|
|
|
|
2016-04-23 23:24:56 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
2015-07-12 21:48:48 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
2015-08-25 00:33:37 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBFragment;
|
2016-04-12 23:12:15 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.activities.HeartRateUtils;
|
2015-08-03 01:17:02 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.database.DBAccess;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
2015-08-17 02:22:16 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
2015-08-03 23:09:49 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
2016-05-16 23:36:54 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
|
2015-08-17 02:22:16 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
2016-05-13 23:47:47 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.HeartRateSample;
|
2015-08-17 02:22:16 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
2015-07-12 23:42:23 +02:00
|
|
|
|
2015-08-25 22:45:07 +02:00
|
|
|
/**
|
|
|
|
* A base class fragment to be used with ChartsActivity. The fragment can supply
|
|
|
|
* a title to be displayed in the activity by returning non-null in #getTitle()
|
|
|
|
* Broadcast events can be received by overriding #onReceive(Context,Intent).
|
|
|
|
* The chart can be refreshed by calling #refresh()
|
|
|
|
* Implement refreshInBackground(DBHandler, GBDevice) to fetch the samples from the DB,
|
|
|
|
* and add the samples to the chart. The actual rendering, which must be performed in the UI
|
|
|
|
* thread, must be done in #renderCharts().
|
|
|
|
* Access functionality of the hosting activity with #getHost()
|
2015-08-29 11:31:48 +02:00
|
|
|
* <p/>
|
2015-08-25 22:45:07 +02:00
|
|
|
* The hosting ChartsHost activity provides a section for displaying a date or date range
|
|
|
|
* being the basis for the chart, as well as two buttons for moving backwards and forward
|
|
|
|
* in time. The date is held by the activity, so that it can be shared by multiple chart
|
|
|
|
* fragments. It is still the responsibility of the (currently visible) chart fragment
|
|
|
|
* to set the desired date in the ChartsActivity via #setDateRange(Date,Date).
|
|
|
|
* The default implementations #handleDatePrev(Date,Date) and #handleDateNext(Date,Date)
|
|
|
|
* shift the date by one day.
|
|
|
|
*/
|
2015-08-25 00:33:37 +02:00
|
|
|
public abstract class AbstractChartFragment extends AbstractGBFragment {
|
2015-11-23 23:04:46 +01:00
|
|
|
protected final int ANIM_TIME = 350;
|
2015-08-25 01:03:58 +02:00
|
|
|
|
2015-08-25 22:45:07 +02:00
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(AbstractChartFragment.class);
|
2015-07-11 00:03:41 +02:00
|
|
|
|
2015-08-17 02:22:16 +02:00
|
|
|
private final Set<String> mIntentFilterActions;
|
2015-11-23 23:04:46 +01:00
|
|
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
2015-08-17 02:22:16 +02:00
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
AbstractChartFragment.this.onReceive(context, intent);
|
|
|
|
}
|
|
|
|
};
|
2015-08-25 00:33:37 +02:00
|
|
|
private boolean mChartDirty = true;
|
2016-04-08 23:02:50 +02:00
|
|
|
private AsyncTask refreshTask;
|
2015-08-25 00:33:37 +02:00
|
|
|
|
|
|
|
public boolean isChartDirty() {
|
|
|
|
return mChartDirty;
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract String getTitle();
|
2016-02-29 20:54:39 +01:00
|
|
|
|
2016-06-19 23:22:28 +02:00
|
|
|
public boolean supportsHeartrate(GBDevice device) {
|
|
|
|
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
|
|
|
|
return coordinator != null && coordinator.supportsHeartRateMeasurement(device);
|
2016-02-26 23:45:17 +01:00
|
|
|
}
|
2015-07-12 23:42:23 +02:00
|
|
|
|
2015-07-27 23:49:53 +02:00
|
|
|
protected static final class ActivityConfig {
|
|
|
|
public final int type;
|
2015-07-11 00:03:41 +02:00
|
|
|
public final String label;
|
2015-11-23 23:04:46 +01:00
|
|
|
public final Integer color;
|
2015-07-11 00:03:41 +02:00
|
|
|
|
2015-07-27 23:49:53 +02:00
|
|
|
public ActivityConfig(int kind, String label, Integer color) {
|
|
|
|
this.type = kind;
|
2015-07-11 00:03:41 +02:00
|
|
|
this.label = label;
|
|
|
|
this.color = color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-04 00:17:24 +02:00
|
|
|
protected ActivityConfig akActivity;
|
|
|
|
protected ActivityConfig akLightSleep;
|
|
|
|
protected ActivityConfig akDeepSleep;
|
|
|
|
protected ActivityConfig akNotWorn;
|
2015-08-28 14:54:49 +02:00
|
|
|
|
2015-07-11 00:03:41 +02:00
|
|
|
|
2015-08-28 14:35:22 +02:00
|
|
|
protected int BACKGROUND_COLOR;
|
|
|
|
protected int DESCRIPTION_COLOR;
|
|
|
|
protected int CHART_TEXT_COLOR;
|
|
|
|
protected int LEGEND_TEXT_COLOR;
|
2016-02-26 23:45:17 +01:00
|
|
|
protected int HEARTRATE_COLOR;
|
2016-04-12 23:12:15 +02:00
|
|
|
protected int HEARTRATE_FILL_COLOR;
|
2015-08-28 14:35:22 +02:00
|
|
|
protected int AK_ACTIVITY_COLOR;
|
|
|
|
protected int AK_DEEP_SLEEP_COLOR;
|
|
|
|
protected int AK_LIGHT_SLEEP_COLOR;
|
2015-08-28 14:54:49 +02:00
|
|
|
protected int AK_NOT_WORN_COLOR;
|
2015-07-11 00:03:41 +02:00
|
|
|
|
2016-04-04 23:05:00 +02:00
|
|
|
protected String HEARTRATE_LABEL;
|
|
|
|
|
2015-08-17 02:22:16 +02:00
|
|
|
protected AbstractChartFragment(String... intentFilterActions) {
|
|
|
|
mIntentFilterActions = new HashSet<>();
|
|
|
|
if (intentFilterActions != null) {
|
|
|
|
mIntentFilterActions.addAll(Arrays.asList(intentFilterActions));
|
|
|
|
mIntentFilterActions.add(ChartsHost.DATE_NEXT);
|
|
|
|
mIntentFilterActions.add(ChartsHost.DATE_PREV);
|
|
|
|
mIntentFilterActions.add(ChartsHost.REFRESH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
2015-10-04 00:17:24 +02:00
|
|
|
init();
|
2015-08-28 14:35:22 +02:00
|
|
|
|
2015-08-17 02:22:16 +02:00
|
|
|
IntentFilter filter = new IntentFilter();
|
|
|
|
for (String action : mIntentFilterActions) {
|
|
|
|
filter.addAction(action);
|
|
|
|
}
|
|
|
|
LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mReceiver, filter);
|
|
|
|
}
|
|
|
|
|
2015-10-04 00:17:24 +02:00
|
|
|
protected void init() {
|
2016-04-23 23:24:56 +02:00
|
|
|
BACKGROUND_COLOR = GBApplication.getBackgroundColor(getContext());
|
|
|
|
LEGEND_TEXT_COLOR = DESCRIPTION_COLOR = GBApplication.getTextColor(getContext());
|
2015-08-28 14:35:22 +02:00
|
|
|
CHART_TEXT_COLOR = getResources().getColor(R.color.secondarytext);
|
2016-02-26 23:45:17 +01:00
|
|
|
HEARTRATE_COLOR = getResources().getColor(R.color.chart_heartrate);
|
2016-04-12 23:12:15 +02:00
|
|
|
HEARTRATE_FILL_COLOR = getResources().getColor(R.color.chart_heartrate_fill);
|
2015-08-28 14:35:22 +02:00
|
|
|
AK_ACTIVITY_COLOR = getResources().getColor(R.color.chart_activity_light);
|
|
|
|
AK_DEEP_SLEEP_COLOR = getResources().getColor(R.color.chart_light_sleep_light);
|
|
|
|
AK_LIGHT_SLEEP_COLOR = getResources().getColor(R.color.chart_deep_sleep_light);
|
2015-08-28 14:54:49 +02:00
|
|
|
AK_NOT_WORN_COLOR = getResources().getColor(R.color.chart_not_worn_light);
|
2015-08-28 14:35:22 +02:00
|
|
|
|
2016-04-04 23:05:00 +02:00
|
|
|
HEARTRATE_LABEL = getContext().getString(R.string.charts_legend_heartrate);
|
|
|
|
|
2015-10-04 00:17:24 +02:00
|
|
|
akActivity = new ActivityConfig(ActivityKind.TYPE_ACTIVITY, getString(R.string.abstract_chart_fragment_kind_activity), AK_ACTIVITY_COLOR);
|
|
|
|
akLightSleep = new ActivityConfig(ActivityKind.TYPE_LIGHT_SLEEP, getString(R.string.abstract_chart_fragment_kind_light_sleep), AK_LIGHT_SLEEP_COLOR);
|
|
|
|
akDeepSleep = new ActivityConfig(ActivityKind.TYPE_DEEP_SLEEP, getString(R.string.abstract_chart_fragment_kind_deep_sleep), AK_DEEP_SLEEP_COLOR);
|
|
|
|
akNotWorn = new ActivityConfig(ActivityKind.TYPE_NOT_WORN, getString(R.string.abstract_chart_fragment_kind_not_worn), AK_NOT_WORN_COLOR);
|
2015-08-28 14:35:22 +02:00
|
|
|
}
|
|
|
|
|
2015-08-25 00:54:16 +02:00
|
|
|
private void setStartDate(Date date) {
|
2015-09-04 21:55:29 +02:00
|
|
|
getChartsHost().setStartDate(date);
|
2015-08-25 00:54:16 +02:00
|
|
|
}
|
|
|
|
|
2015-09-04 21:55:29 +02:00
|
|
|
@Nullable
|
|
|
|
protected ChartsHost getChartsHost() {
|
|
|
|
return (ChartsHost) getActivity();
|
|
|
|
}
|
2016-02-29 20:54:39 +01:00
|
|
|
|
2015-08-25 00:54:16 +02:00
|
|
|
private void setEndDate(Date date) {
|
2015-09-04 21:55:29 +02:00
|
|
|
getChartsHost().setEndDate(date);
|
2015-08-17 02:22:16 +02:00
|
|
|
}
|
|
|
|
|
2015-08-25 00:54:16 +02:00
|
|
|
public Date getStartDate() {
|
2015-09-04 21:55:29 +02:00
|
|
|
return getChartsHost().getStartDate();
|
2015-08-17 02:22:16 +02:00
|
|
|
}
|
|
|
|
|
2015-08-25 00:54:16 +02:00
|
|
|
public Date getEndDate() {
|
2015-09-04 21:55:29 +02:00
|
|
|
return getChartsHost().getEndDate();
|
2015-08-17 02:22:16 +02:00
|
|
|
}
|
|
|
|
|
2015-08-25 00:33:37 +02:00
|
|
|
/**
|
|
|
|
* Called when this fragment has been fully scrolled into the activity.
|
|
|
|
*
|
|
|
|
* @see #isVisibleInActivity()
|
|
|
|
* @see #onMadeInvisibleInActivity()
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onMadeVisibleInActivity() {
|
|
|
|
super.onMadeVisibleInActivity();
|
2015-09-04 21:55:29 +02:00
|
|
|
showDateBar(true);
|
2015-08-25 00:33:37 +02:00
|
|
|
if (isChartDirty()) {
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-04 21:55:29 +02:00
|
|
|
protected void showDateBar(boolean show) {
|
|
|
|
getChartsHost().getDateBar().setVisibility(show ? View.VISIBLE : View.GONE);
|
|
|
|
}
|
|
|
|
|
2015-08-17 02:22:16 +02:00
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(mReceiver);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void onReceive(Context context, Intent intent) {
|
|
|
|
String action = intent.getAction();
|
|
|
|
if (ChartsHost.REFRESH.equals(action)) {
|
|
|
|
refresh();
|
|
|
|
} else if (ChartsHost.DATE_NEXT.equals(action)) {
|
2015-08-25 00:54:16 +02:00
|
|
|
handleDateNext(getStartDate(), getEndDate());
|
2015-08-17 02:22:16 +02:00
|
|
|
} else if (ChartsHost.DATE_PREV.equals(action)) {
|
2015-08-25 00:54:16 +02:00
|
|
|
handleDatePrev(getStartDate(), getEndDate());
|
2015-08-17 02:22:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-25 22:45:07 +02:00
|
|
|
/**
|
|
|
|
* Default implementation shifts the dates by one day, if visible
|
|
|
|
* and calls #refreshIfVisible().
|
2015-08-29 11:31:48 +02:00
|
|
|
*
|
2015-08-25 22:45:07 +02:00
|
|
|
* @param startDate
|
|
|
|
* @param endDate
|
|
|
|
*/
|
2015-08-17 02:22:16 +02:00
|
|
|
protected void handleDatePrev(Date startDate, Date endDate) {
|
2015-08-25 00:54:16 +02:00
|
|
|
if (isVisibleInActivity()) {
|
2015-08-25 22:45:07 +02:00
|
|
|
if (!shiftDates(startDate, endDate, -1)) {
|
|
|
|
return;
|
|
|
|
}
|
2015-08-25 00:54:16 +02:00
|
|
|
}
|
2015-08-25 00:33:37 +02:00
|
|
|
refreshIfVisible();
|
2015-08-17 02:22:16 +02:00
|
|
|
}
|
|
|
|
|
2015-08-25 22:45:07 +02:00
|
|
|
/**
|
|
|
|
* Default implementation shifts the dates by one day, if visible
|
|
|
|
* and calls #refreshIfVisible().
|
2015-08-29 11:31:48 +02:00
|
|
|
*
|
2015-08-25 22:45:07 +02:00
|
|
|
* @param startDate
|
|
|
|
* @param endDate
|
|
|
|
*/
|
2015-08-17 02:22:16 +02:00
|
|
|
protected void handleDateNext(Date startDate, Date endDate) {
|
2015-08-25 00:54:16 +02:00
|
|
|
if (isVisibleInActivity()) {
|
2015-08-25 22:45:07 +02:00
|
|
|
if (!shiftDates(startDate, endDate, +1)) {
|
|
|
|
return;
|
|
|
|
}
|
2015-08-25 00:54:16 +02:00
|
|
|
}
|
2015-08-25 00:33:37 +02:00
|
|
|
refreshIfVisible();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void refreshIfVisible() {
|
|
|
|
if (isVisibleInActivity()) {
|
|
|
|
refresh();
|
|
|
|
} else {
|
|
|
|
mChartDirty = true;
|
|
|
|
}
|
2015-08-17 02:22:16 +02:00
|
|
|
}
|
|
|
|
|
2015-08-25 22:45:07 +02:00
|
|
|
/**
|
|
|
|
* Shifts the given dates by offset days. offset may be positive or negative.
|
2015-08-29 11:31:48 +02:00
|
|
|
*
|
2015-08-25 22:45:07 +02:00
|
|
|
* @param startDate
|
|
|
|
* @param endDate
|
2015-08-29 11:31:48 +02:00
|
|
|
* @param offset a positive or negative number of days to shift the dates
|
2015-08-25 22:45:07 +02:00
|
|
|
* @return true if the shift was successful and false otherwise
|
|
|
|
*/
|
|
|
|
protected boolean shiftDates(Date startDate, Date endDate, int offset) {
|
2015-08-17 02:22:16 +02:00
|
|
|
Date newStart = DateTimeUtils.shiftByDays(startDate, offset);
|
|
|
|
Date newEnd = DateTimeUtils.shiftByDays(endDate, offset);
|
|
|
|
|
2015-08-25 22:45:07 +02:00
|
|
|
return setDateRange(newStart, newEnd);
|
2015-08-17 02:22:16 +02:00
|
|
|
}
|
|
|
|
|
2015-07-20 23:11:16 +02:00
|
|
|
protected Integer getColorFor(int activityKind) {
|
|
|
|
switch (activityKind) {
|
2015-08-03 23:09:49 +02:00
|
|
|
case ActivityKind.TYPE_DEEP_SLEEP:
|
2015-07-20 23:11:16 +02:00
|
|
|
return akDeepSleep.color;
|
2015-08-03 23:09:49 +02:00
|
|
|
case ActivityKind.TYPE_LIGHT_SLEEP:
|
2015-07-20 23:11:16 +02:00
|
|
|
return akLightSleep.color;
|
2015-08-03 23:09:49 +02:00
|
|
|
case ActivityKind.TYPE_ACTIVITY:
|
2015-07-25 21:52:52 +02:00
|
|
|
return akActivity.color;
|
2015-07-20 23:11:16 +02:00
|
|
|
}
|
|
|
|
return akActivity.color;
|
|
|
|
}
|
|
|
|
|
2016-06-16 21:54:53 +02:00
|
|
|
protected SampleProvider<? extends AbstractActivitySample> getProvider(DBHandler db, GBDevice device) {
|
2015-07-27 23:49:53 +02:00
|
|
|
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
|
2016-06-27 20:41:20 +02:00
|
|
|
return coordinator.getSampleProvider(device, db.getDaoSession());
|
2015-07-11 00:03:41 +02:00
|
|
|
}
|
|
|
|
|
2015-08-03 01:17:02 +02:00
|
|
|
/**
|
|
|
|
* Returns all kinds of samples for the given device.
|
|
|
|
* To be called from a background thread.
|
2015-08-29 11:31:48 +02:00
|
|
|
*
|
2015-08-03 01:17:02 +02:00
|
|
|
* @param device
|
|
|
|
* @param tsFrom
|
|
|
|
* @param tsTo
|
|
|
|
*/
|
2016-05-16 23:36:54 +02:00
|
|
|
protected List<? extends ActivitySample> getAllSamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) {
|
|
|
|
SampleProvider<? extends ActivitySample> provider = getProvider(db, device);
|
|
|
|
return provider.getAllActivitySamples(tsFrom, tsTo);
|
2015-07-12 23:42:23 +02:00
|
|
|
}
|
2015-07-11 00:03:41 +02:00
|
|
|
|
2015-09-01 22:37:20 +02:00
|
|
|
private int getTSLast24Hours(int tsTo) {
|
|
|
|
return (tsTo) - (24 * 60 * 60); // -24 hours
|
2015-07-12 23:42:23 +02:00
|
|
|
}
|
|
|
|
|
2016-06-16 21:54:53 +02:00
|
|
|
protected List<? extends AbstractActivitySample> getActivitySamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) {
|
|
|
|
SampleProvider<? extends AbstractActivitySample> provider = getProvider(db, device);
|
2016-05-16 23:36:54 +02:00
|
|
|
return provider.getActivitySamples(tsFrom, tsTo);
|
2015-07-11 00:03:41 +02:00
|
|
|
}
|
|
|
|
|
2015-07-12 23:42:23 +02:00
|
|
|
|
2016-05-16 23:36:54 +02:00
|
|
|
protected List<? extends ActivitySample> getSleepSamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) {
|
|
|
|
SampleProvider<? extends ActivitySample> provider = getProvider(db, device);
|
|
|
|
return provider.getSleepSamples(tsFrom, tsTo);
|
2015-07-11 00:03:41 +02:00
|
|
|
}
|
|
|
|
|
2016-05-16 23:36:54 +02:00
|
|
|
protected List<? extends ActivitySample> getTestSamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) {
|
2015-07-11 00:03:41 +02:00
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
|
cal.clear();
|
|
|
|
cal.set(2015, Calendar.JUNE, 10, 6, 40);
|
|
|
|
// ignore provided date ranges
|
2015-09-01 22:30:02 +02:00
|
|
|
tsTo = (int) ((cal.getTimeInMillis() / 1000));
|
2015-07-11 00:03:41 +02:00
|
|
|
tsFrom = tsTo - (24 * 60 * 60);
|
|
|
|
|
2016-05-16 23:36:54 +02:00
|
|
|
SampleProvider<? extends ActivitySample> provider = getProvider(db, device);
|
|
|
|
return provider.getAllActivitySamples(tsFrom, tsTo);
|
2015-07-11 00:03:41 +02:00
|
|
|
}
|
|
|
|
|
2015-07-12 21:48:48 +02:00
|
|
|
protected void configureChartDefaults(Chart<?> chart) {
|
2016-04-11 23:18:12 +02:00
|
|
|
chart.setDescription("");
|
|
|
|
|
2015-07-11 00:03:41 +02:00
|
|
|
// if enabled, the chart will always start at zero on the y-axis
|
2015-07-12 21:48:48 +02:00
|
|
|
chart.setNoDataText(getString(R.string.chart_no_data_synchronize));
|
2015-07-11 00:03:41 +02:00
|
|
|
|
|
|
|
// disable value highlighting
|
2015-11-13 23:57:04 +01:00
|
|
|
chart.setHighlightPerTapEnabled(false);
|
2015-07-11 00:03:41 +02:00
|
|
|
|
|
|
|
// enable touch gestures
|
2015-07-12 21:48:48 +02:00
|
|
|
chart.setTouchEnabled(true);
|
2016-04-11 23:18:12 +02:00
|
|
|
|
|
|
|
setupLegend(chart);
|
2015-07-11 00:03:41 +02:00
|
|
|
}
|
|
|
|
|
2015-07-12 21:48:48 +02:00
|
|
|
protected void configureBarLineChartDefaults(BarLineChartBase<?> chart) {
|
|
|
|
configureChartDefaults(chart);
|
2015-07-11 00:03:41 +02:00
|
|
|
|
|
|
|
// enable scaling and dragging
|
2015-07-12 21:48:48 +02:00
|
|
|
chart.setDragEnabled(true);
|
|
|
|
chart.setScaleEnabled(true);
|
2015-07-11 00:03:41 +02:00
|
|
|
|
|
|
|
// if disabled, scaling can be done on x- and y-axis separately
|
2015-07-12 23:42:23 +02:00
|
|
|
// chart.setPinchZoom(true);
|
2015-07-11 00:03:41 +02:00
|
|
|
|
2015-07-12 21:48:48 +02:00
|
|
|
chart.setDrawGridBackground(false);
|
2015-07-11 00:03:41 +02:00
|
|
|
}
|
|
|
|
|
2015-08-03 01:17:02 +02:00
|
|
|
/**
|
|
|
|
* This method will invoke a background task to read the data from the
|
|
|
|
* database, analyze it, prepare it for the charts and eventually call
|
|
|
|
* #renderCharts
|
|
|
|
*/
|
|
|
|
protected void refresh() {
|
2015-09-04 21:55:29 +02:00
|
|
|
ChartsHost chartsHost = getChartsHost();
|
|
|
|
if (chartsHost != null) {
|
|
|
|
if (chartsHost.getDevice() != null) {
|
|
|
|
mChartDirty = false;
|
|
|
|
updateDateInfo(getStartDate(), getEndDate());
|
2016-04-08 23:02:50 +02:00
|
|
|
if (refreshTask != null && refreshTask.getStatus() != AsyncTask.Status.FINISHED) {
|
|
|
|
refreshTask.cancel(true);
|
|
|
|
}
|
|
|
|
refreshTask = createRefreshTask("Visualizing data", getActivity()).execute();
|
2015-09-04 21:55:29 +02:00
|
|
|
}
|
2015-08-25 00:33:37 +02:00
|
|
|
}
|
2015-08-03 01:17:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method reads the data from the database, analyzes and prepares it for
|
|
|
|
* the charts. This will be called from a background task, so there must not be
|
2016-04-11 23:18:12 +02:00
|
|
|
* any UI access. #updateChartsInUIThread and #renderCharts will be automatically called after this method.
|
2015-08-03 01:17:02 +02:00
|
|
|
*/
|
2016-04-11 23:18:12 +02:00
|
|
|
protected abstract ChartsData refreshInBackground(ChartsHost chartsHost, DBHandler db, GBDevice device);
|
2015-08-03 01:17:02 +02:00
|
|
|
|
|
|
|
/**
|
2015-08-25 22:45:07 +02:00
|
|
|
* Triggers the actual (re-) rendering of the chart.
|
2015-08-03 01:17:02 +02:00
|
|
|
* Always called from the UI thread.
|
|
|
|
*/
|
|
|
|
protected abstract void renderCharts();
|
|
|
|
|
2016-05-16 23:36:54 +02:00
|
|
|
protected DefaultChartsData refresh(GBDevice gbDevice, List<? extends ActivitySample> samples) {
|
2015-07-12 23:42:23 +02:00
|
|
|
Calendar cal = GregorianCalendar.getInstance();
|
|
|
|
cal.clear();
|
|
|
|
Date date;
|
|
|
|
String dateStringFrom = "";
|
|
|
|
String dateStringTo = "";
|
|
|
|
|
2015-09-09 21:15:29 +02:00
|
|
|
LOG.info("" + getTitle() + ": number of samples:" + samples.size());
|
2016-04-11 23:18:12 +02:00
|
|
|
CombinedData combinedData;
|
2015-07-12 23:42:23 +02:00
|
|
|
if (samples.size() > 1) {
|
|
|
|
boolean annotate = true;
|
|
|
|
boolean use_steps_as_movement;
|
|
|
|
|
2015-07-27 23:49:53 +02:00
|
|
|
int last_type = ActivityKind.TYPE_UNKNOWN;
|
2015-07-12 23:42:23 +02:00
|
|
|
|
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
|
|
|
SimpleDateFormat annotationDateFormat = new SimpleDateFormat("HH:mm");
|
|
|
|
|
|
|
|
int numEntries = samples.size();
|
|
|
|
List<String> xLabels = new ArrayList<>(numEntries);
|
|
|
|
List<BarEntry> activityEntries = new ArrayList<>(numEntries);
|
2016-06-19 23:22:28 +02:00
|
|
|
boolean hr = supportsHeartrate(gbDevice);
|
2016-02-26 23:45:17 +01:00
|
|
|
List<Entry> heartrateEntries = hr ? new ArrayList<Entry>(numEntries) : null;
|
2015-07-12 23:42:23 +02:00
|
|
|
List<Integer> colors = new ArrayList<>(numEntries); // this is kinda inefficient...
|
2016-04-13 21:38:35 +02:00
|
|
|
int lastHrSampleIndex = -1;
|
2015-07-12 23:42:23 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < numEntries; i++) {
|
2015-07-27 23:49:53 +02:00
|
|
|
ActivitySample sample = samples.get(i);
|
|
|
|
int type = sample.getKind();
|
2015-07-12 23:42:23 +02:00
|
|
|
|
|
|
|
// determine start and end dates
|
|
|
|
if (i == 0) {
|
|
|
|
cal.setTimeInMillis(sample.getTimestamp() * 1000L); // make sure it's converted to long
|
|
|
|
date = cal.getTime();
|
|
|
|
dateStringFrom = dateFormat.format(date);
|
|
|
|
} else if (i == samples.size() - 1) {
|
|
|
|
cal.setTimeInMillis(sample.getTimestamp() * 1000L); // same here
|
|
|
|
date = cal.getTime();
|
|
|
|
dateStringTo = dateFormat.format(date);
|
|
|
|
}
|
|
|
|
|
2015-07-27 23:49:53 +02:00
|
|
|
float movement = sample.getIntensity();
|
2015-07-12 23:42:23 +02:00
|
|
|
|
2015-07-27 23:49:53 +02:00
|
|
|
float value = movement;
|
2015-08-28 14:54:49 +02:00
|
|
|
switch (type) {
|
|
|
|
case ActivityKind.TYPE_DEEP_SLEEP:
|
|
|
|
value += SleepUtils.Y_VALUE_DEEP_SLEEP;
|
|
|
|
colors.add(akDeepSleep.color);
|
|
|
|
break;
|
|
|
|
case ActivityKind.TYPE_LIGHT_SLEEP:
|
2015-07-12 23:42:23 +02:00
|
|
|
colors.add(akLightSleep.color);
|
2015-08-28 14:54:49 +02:00
|
|
|
break;
|
|
|
|
case ActivityKind.TYPE_NOT_WORN:
|
|
|
|
value = SleepUtils.Y_VALUE_DEEP_SLEEP; //a small value, just to show something on the graphs
|
|
|
|
colors.add(akNotWorn.color);
|
|
|
|
break;
|
|
|
|
default:
|
2015-07-27 23:49:53 +02:00
|
|
|
// short steps = sample.getSteps();
|
|
|
|
// if (use_steps_as_movement && steps != 0) {
|
|
|
|
// // I'm not sure using steps for this is actually a good idea
|
|
|
|
// movement = steps;
|
|
|
|
// }
|
|
|
|
// value = ((float) movement) / movement_divisor;
|
2015-07-12 23:42:23 +02:00
|
|
|
colors.add(akActivity.color);
|
|
|
|
}
|
2015-08-28 14:54:49 +02:00
|
|
|
activityEntries.add(createBarEntry(value, i));
|
2016-05-13 23:47:47 +02:00
|
|
|
if (hr && isValidHeartRateValue(((HeartRateSample)sample).getHeartRate())) {
|
2016-04-13 21:38:35 +02:00
|
|
|
if (lastHrSampleIndex > -1 && i - lastHrSampleIndex > HeartRateUtils.MAX_HR_MEASUREMENTS_GAP_MINUTES) {
|
|
|
|
heartrateEntries.add(createLineEntry(0, lastHrSampleIndex + 1));
|
|
|
|
heartrateEntries.add(createLineEntry(0, i - 1));
|
|
|
|
}
|
|
|
|
|
2016-05-13 23:47:47 +02:00
|
|
|
heartrateEntries.add(createLineEntry(((HeartRateSample)sample).getHeartRate(), i));
|
2016-04-13 21:38:35 +02:00
|
|
|
lastHrSampleIndex = i;
|
2016-02-26 23:45:17 +01:00
|
|
|
}
|
2015-07-12 23:42:23 +02:00
|
|
|
|
|
|
|
String xLabel = "";
|
|
|
|
if (annotate) {
|
|
|
|
cal.setTimeInMillis(sample.getTimestamp() * 1000L);
|
|
|
|
date = cal.getTime();
|
|
|
|
String dateString = annotationDateFormat.format(date);
|
|
|
|
xLabel = dateString;
|
|
|
|
// if (last_type != type) {
|
|
|
|
// if (isSleep(last_type) && !isSleep(type)) {
|
|
|
|
// // woken up
|
|
|
|
// LimitLine line = new LimitLine(i, dateString);
|
|
|
|
// line.enableDashedLine(8, 8, 0);
|
|
|
|
// line.setTextColor(Color.WHITE);
|
|
|
|
// line.setTextSize(15);
|
|
|
|
// chart.getXAxis().addLimitLine(line);
|
|
|
|
// } else if (!isSleep(last_type) && isSleep(type)) {
|
|
|
|
// // fallen asleep
|
|
|
|
// LimitLine line = new LimitLine(i, dateString);
|
|
|
|
// line.enableDashedLine(8, 8, 0);
|
|
|
|
// line.setTextSize(15);
|
|
|
|
// line.setTextColor(Color.WHITE);
|
|
|
|
// chart.getXAxis().addLimitLine(line);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
last_type = type;
|
|
|
|
}
|
|
|
|
xLabels.add(xLabel);
|
|
|
|
}
|
|
|
|
|
2016-04-11 23:18:12 +02:00
|
|
|
// chart.getXAxis().setValues(xLabels);
|
2015-07-12 23:42:23 +02:00
|
|
|
|
|
|
|
BarDataSet activitySet = createActivitySet(activityEntries, colors, "Activity");
|
|
|
|
// create a data object with the datasets
|
2016-04-11 23:18:12 +02:00
|
|
|
combinedData = new CombinedData(xLabels);
|
2016-03-07 22:45:44 +01:00
|
|
|
List<IBarDataSet> list = new ArrayList<>();
|
2016-02-26 23:45:17 +01:00
|
|
|
list.add(activitySet);
|
|
|
|
BarData barData = new BarData(xLabels, list);
|
|
|
|
barData.setGroupSpace(0);
|
|
|
|
combinedData.setData(barData);
|
|
|
|
|
2016-04-04 23:05:00 +02:00
|
|
|
if (hr && heartrateEntries.size() > 0) {
|
2016-02-26 23:45:17 +01:00
|
|
|
LineDataSet heartrateSet = createHeartrateSet(heartrateEntries, "Heart Rate");
|
|
|
|
LineData lineData = new LineData(xLabels, heartrateSet);
|
|
|
|
combinedData.setData(lineData);
|
|
|
|
}
|
2015-07-12 23:42:23 +02:00
|
|
|
|
2015-09-05 23:05:57 +02:00
|
|
|
// chart.setDescription(getString(R.string.sleep_activity_date_range, dateStringFrom, dateStringTo));
|
2015-07-12 23:42:23 +02:00
|
|
|
// chart.setDescriptionPosition(?, ?);
|
2016-03-07 23:17:02 +01:00
|
|
|
} else {
|
2016-04-11 23:18:12 +02:00
|
|
|
combinedData = new CombinedData(Collections.<String>emptyList());
|
2015-07-12 23:42:23 +02:00
|
|
|
}
|
2016-04-11 23:18:12 +02:00
|
|
|
|
|
|
|
return new DefaultChartsData(combinedData);
|
2015-07-12 23:42:23 +02:00
|
|
|
}
|
|
|
|
|
2016-04-04 23:05:00 +02:00
|
|
|
protected boolean isValidHeartRateValue(int value) {
|
2016-04-12 23:12:15 +02:00
|
|
|
return value > HeartRateUtils.MIN_HEART_RATE_VALUE && value < HeartRateUtils.MAX_HEART_RATE_VALUE;
|
2016-04-04 23:05:00 +02:00
|
|
|
}
|
|
|
|
|
2015-08-25 22:45:07 +02:00
|
|
|
/**
|
|
|
|
* Implement this to supply the samples to be displayed.
|
2015-08-29 11:31:48 +02:00
|
|
|
*
|
2015-08-25 22:45:07 +02:00
|
|
|
* @param db
|
|
|
|
* @param device
|
|
|
|
* @param tsFrom
|
|
|
|
* @param tsTo
|
|
|
|
* @return
|
|
|
|
*/
|
2016-05-16 23:36:54 +02:00
|
|
|
protected abstract List<? extends ActivitySample> getSamples(DBHandler db, GBDevice device, int tsFrom, int tsTo);
|
2015-07-13 21:54:46 +02:00
|
|
|
|
2015-07-14 00:29:32 +02:00
|
|
|
protected abstract void setupLegend(Chart chart);
|
2015-07-12 23:42:23 +02:00
|
|
|
|
2015-07-25 21:52:52 +02:00
|
|
|
protected BarEntry createBarEntry(float value, int index) {
|
2015-07-11 00:03:41 +02:00
|
|
|
return new BarEntry(value, index);
|
|
|
|
}
|
|
|
|
|
2016-02-26 23:45:17 +01:00
|
|
|
protected Entry createLineEntry(float value, int index) {
|
|
|
|
return new Entry(value, index);
|
|
|
|
}
|
|
|
|
|
2015-07-11 00:03:41 +02:00
|
|
|
protected BarDataSet createActivitySet(List<BarEntry> values, List<Integer> colors, String label) {
|
|
|
|
BarDataSet set1 = new BarDataSet(values, label);
|
|
|
|
set1.setColors(colors);
|
|
|
|
// set1.setDrawCubic(true);
|
|
|
|
// set1.setCubicIntensity(0.2f);
|
|
|
|
// //set1.setDrawFilled(true);
|
|
|
|
// set1.setDrawCircles(false);
|
|
|
|
// set1.setLineWidth(2f);
|
|
|
|
// set1.setCircleSize(5f);
|
|
|
|
// set1.setFillColor(ColorTemplate.getHoloBlue());
|
|
|
|
set1.setDrawValues(false);
|
|
|
|
// set1.setHighLightColor(Color.rgb(128, 0, 255));
|
|
|
|
// set1.setColor(Color.rgb(89, 178, 44));
|
|
|
|
set1.setValueTextColor(CHART_TEXT_COLOR);
|
2016-02-27 11:18:16 +01:00
|
|
|
set1.setAxisDependency(YAxis.AxisDependency.LEFT);
|
2015-07-11 00:03:41 +02:00
|
|
|
return set1;
|
|
|
|
}
|
|
|
|
|
2016-02-26 23:45:17 +01:00
|
|
|
protected LineDataSet createHeartrateSet(List<Entry> values, String label) {
|
|
|
|
LineDataSet set1 = new LineDataSet(values, label);
|
2016-04-13 21:21:10 +02:00
|
|
|
set1.setLineWidth(0.8f);
|
2016-02-26 23:45:17 +01:00
|
|
|
set1.setColor(HEARTRATE_COLOR);
|
2016-04-04 23:05:00 +02:00
|
|
|
set1.setDrawCubic(true);
|
|
|
|
set1.setCubicIntensity(0.1f);
|
|
|
|
set1.setDrawCircles(false);
|
|
|
|
// set1.setCircleRadius(2f);
|
|
|
|
// set1.setDrawFilled(true);
|
2016-04-13 21:21:10 +02:00
|
|
|
// set1.setColor(getResources().getColor(android.R.color.background_light));
|
|
|
|
// set1.setCircleColor(HEARTRATE_COLOR);
|
2016-02-26 23:45:17 +01:00
|
|
|
// set1.setFillColor(ColorTemplate.getHoloBlue());
|
|
|
|
// set1.setHighLightColor(Color.rgb(128, 0, 255));
|
|
|
|
// set1.setColor(Color.rgb(89, 178, 44));
|
2016-04-13 21:21:10 +02:00
|
|
|
set1.setDrawValues(true);
|
2016-02-26 23:45:17 +01:00
|
|
|
set1.setValueTextColor(CHART_TEXT_COLOR);
|
2016-02-27 11:18:16 +01:00
|
|
|
set1.setAxisDependency(YAxis.AxisDependency.RIGHT);
|
2016-02-26 23:45:17 +01:00
|
|
|
return set1;
|
|
|
|
}
|
|
|
|
|
2015-07-11 00:03:41 +02:00
|
|
|
protected BarDataSet createDeepSleepSet(List<BarEntry> values, String label) {
|
|
|
|
BarDataSet set1 = new BarDataSet(values, label);
|
|
|
|
// set1.setDrawCubic(true);
|
|
|
|
// set1.setCubicIntensity(0.2f);
|
|
|
|
// //set1.setDrawFilled(true);
|
|
|
|
// set1.setDrawCircles(false);
|
|
|
|
// set1.setLineWidth(2f);
|
|
|
|
// set1.setCircleSize(5f);
|
|
|
|
// set1.setFillColor(ColorTemplate.getHoloBlue());
|
|
|
|
set1.setDrawValues(false);
|
|
|
|
// set1.setHighLightColor(Color.rgb(244, 117, 117));
|
|
|
|
// set1.setColor(Color.rgb(76, 90, 255));
|
|
|
|
set1.setValueTextColor(CHART_TEXT_COLOR);
|
|
|
|
return set1;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected BarDataSet createLightSleepSet(List<BarEntry> values, String label) {
|
|
|
|
BarDataSet set1 = new BarDataSet(values, label);
|
|
|
|
|
|
|
|
// set1.setDrawCubic(true);
|
|
|
|
// set1.setCubicIntensity(0.2f);
|
|
|
|
// //set1.setDrawFilled(true);
|
|
|
|
// set1.setDrawCircles(false);
|
|
|
|
// set1.setLineWidth(2f);
|
|
|
|
// set1.setCircleSize(5f);
|
|
|
|
// set1.setFillColor(ColorTemplate.getHoloBlue());
|
|
|
|
set1.setDrawValues(false);
|
|
|
|
// set1.setHighLightColor(Color.rgb(244, 117, 117));
|
|
|
|
// set1.setColor(Color.rgb(182, 191, 255));
|
|
|
|
set1.setValueTextColor(CHART_TEXT_COLOR);
|
|
|
|
// set1.setColor(Color.CYAN);
|
|
|
|
return set1;
|
|
|
|
}
|
2015-08-03 01:17:02 +02:00
|
|
|
|
|
|
|
protected RefreshTask createRefreshTask(String task, Context context) {
|
|
|
|
return new RefreshTask(task, context);
|
|
|
|
}
|
|
|
|
|
|
|
|
public class RefreshTask extends DBAccess {
|
2016-04-11 23:18:12 +02:00
|
|
|
private ChartsData chartsData;
|
|
|
|
|
2015-08-03 01:17:02 +02:00
|
|
|
public RefreshTask(String task, Context context) {
|
|
|
|
super(task, context);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void doInBackground(DBHandler db) {
|
2015-09-04 21:55:29 +02:00
|
|
|
ChartsHost chartsHost = getChartsHost();
|
|
|
|
if (chartsHost != null) {
|
2016-04-11 23:18:12 +02:00
|
|
|
chartsData = refreshInBackground(chartsHost, db, chartsHost.getDevice());
|
|
|
|
} else {
|
|
|
|
cancel(true);
|
2015-09-04 21:55:29 +02:00
|
|
|
}
|
2015-08-03 01:17:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPostExecute(Object o) {
|
|
|
|
super.onPostExecute(o);
|
2015-11-23 22:46:12 +01:00
|
|
|
FragmentActivity activity = getActivity();
|
2015-08-16 23:27:18 +02:00
|
|
|
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
|
2016-04-11 23:18:12 +02:00
|
|
|
updateChartsnUIThread(chartsData);
|
2015-08-16 23:27:18 +02:00
|
|
|
renderCharts();
|
|
|
|
} else {
|
|
|
|
LOG.info("Not rendering charts because activity is not available anymore");
|
|
|
|
}
|
2015-08-03 01:17:02 +02:00
|
|
|
}
|
|
|
|
}
|
2015-08-17 02:22:16 +02:00
|
|
|
|
2016-04-11 23:18:12 +02:00
|
|
|
protected abstract void updateChartsnUIThread(ChartsData chartsData);
|
|
|
|
|
2015-08-25 22:45:07 +02:00
|
|
|
/**
|
|
|
|
* Returns true if the date was successfully shifted, and false if the shift
|
|
|
|
* was ignored, e.g. when the to-value is in the future.
|
2015-08-29 11:31:48 +02:00
|
|
|
*
|
2015-08-25 22:45:07 +02:00
|
|
|
* @param from
|
|
|
|
* @param to
|
|
|
|
*/
|
|
|
|
public boolean setDateRange(Date from, Date to) {
|
2015-08-17 02:22:16 +02:00
|
|
|
if (from.compareTo(to) > 0) {
|
2015-08-29 11:31:48 +02:00
|
|
|
throw new IllegalArgumentException("Bad date range: " + from + ".." + to);
|
2015-08-17 02:22:16 +02:00
|
|
|
}
|
2015-08-25 22:45:07 +02:00
|
|
|
Date now = new Date();
|
|
|
|
if (to.after(now)) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-08-25 00:54:16 +02:00
|
|
|
setStartDate(from);
|
|
|
|
setEndDate(to);
|
2015-08-25 22:45:07 +02:00
|
|
|
return true;
|
2015-08-17 02:22:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void updateDateInfo(Date from, Date to) {
|
|
|
|
if (from.equals(to)) {
|
2015-09-04 21:55:29 +02:00
|
|
|
getChartsHost().setDateInfo(DateTimeUtils.formatDate(from));
|
2015-08-17 02:22:16 +02:00
|
|
|
} else {
|
2015-09-04 21:55:29 +02:00
|
|
|
getChartsHost().setDateInfo(DateTimeUtils.formatDateRange(from, to));
|
2015-08-17 02:22:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-16 23:36:54 +02:00
|
|
|
protected List<? extends ActivitySample> getSamples(DBHandler db, GBDevice device) {
|
2015-08-19 00:52:03 +02:00
|
|
|
return getSamples(db, device, getTSStart(), getTSEnd());
|
2015-08-17 02:22:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private int getTSEnd() {
|
2015-08-25 00:54:16 +02:00
|
|
|
return toTimestamp(getEndDate());
|
2015-08-17 02:22:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private int getTSStart() {
|
2015-08-25 00:54:16 +02:00
|
|
|
return toTimestamp(getStartDate());
|
2015-08-17 02:22:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private int toTimestamp(Date date) {
|
2015-09-01 22:30:02 +02:00
|
|
|
return (int) ((date.getTime() / 1000));
|
2015-08-17 02:22:16 +02:00
|
|
|
}
|
2016-04-11 23:18:12 +02:00
|
|
|
|
2016-04-14 17:41:04 +02:00
|
|
|
public static class DefaultChartsData extends ChartsData {
|
2016-04-11 23:18:12 +02:00
|
|
|
private final CombinedData combinedData;
|
|
|
|
|
|
|
|
public DefaultChartsData(CombinedData combinedData) {
|
|
|
|
this.combinedData = combinedData;
|
|
|
|
}
|
|
|
|
|
|
|
|
public CombinedData getCombinedData() {
|
|
|
|
return combinedData;
|
|
|
|
}
|
|
|
|
}
|
2015-07-11 00:03:41 +02:00
|
|
|
}
|