Change weekly sleep charts to display sleep from 12:00-12:00 instead of 0:00-0:00
parent
a0bb0c973c
commit
a90e0074fc
|
@ -47,6 +47,8 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
|
||||||
private PieChart mTodayPieChart;
|
private PieChart mTodayPieChart;
|
||||||
private BarChart mWeekChart;
|
private BarChart mWeekChart;
|
||||||
|
|
||||||
|
private int mOffsetHours = getOffsetHours();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ChartsData refreshInBackground(ChartsHost chartsHost, DBHandler db, GBDevice device) {
|
protected ChartsData refreshInBackground(ChartsHost chartsHost, DBHandler db, GBDevice device) {
|
||||||
Calendar day = Calendar.getInstance();
|
Calendar day = Calendar.getInstance();
|
||||||
|
@ -213,7 +215,7 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
|
||||||
// chart.getLegend().setTextColor(LEGEND_TEXT_COLOR);
|
// chart.getLegend().setTextColor(LEGEND_TEXT_COLOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<? extends ActivitySample> getSamplesOfDay(DBHandler db, Calendar day, GBDevice device) {
|
private List<? extends ActivitySample> getSamplesOfDay(DBHandler db, Calendar day, int offsetHours, GBDevice device) {
|
||||||
int startTs;
|
int startTs;
|
||||||
int endTs;
|
int endTs;
|
||||||
|
|
||||||
|
@ -221,12 +223,10 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
|
||||||
day.set(Calendar.HOUR_OF_DAY, 0);
|
day.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
day.set(Calendar.MINUTE, 0);
|
day.set(Calendar.MINUTE, 0);
|
||||||
day.set(Calendar.SECOND, 0);
|
day.set(Calendar.SECOND, 0);
|
||||||
startTs = (int) (day.getTimeInMillis() / 1000);
|
day.add(Calendar.HOUR, offsetHours);
|
||||||
|
|
||||||
day.set(Calendar.HOUR_OF_DAY, 23);
|
startTs = (int) (day.getTimeInMillis() / 1000);
|
||||||
day.set(Calendar.MINUTE, 59);
|
endTs = startTs + 24 * 60 * 60 - 1;
|
||||||
day.set(Calendar.SECOND, 59);
|
|
||||||
endTs = (int) (day.getTimeInMillis() / 1000);
|
|
||||||
|
|
||||||
return getSamples(db, device, startTs, endTs);
|
return getSamples(db, device, startTs, endTs);
|
||||||
}
|
}
|
||||||
|
@ -272,14 +272,14 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
activityAmountCache = ((ChartsActivity) activity).mActivityAmountCache;
|
activityAmountCache = ((ChartsActivity) activity).mActivityAmountCache;
|
||||||
amounts = (ActivityAmounts) (activityAmountCache.lookup(day.hashCode()));
|
amounts = (ActivityAmounts) (activityAmountCache.lookup(day.hashCode() ^ mOffsetHours));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (amounts == null) {
|
if (amounts == null) {
|
||||||
ActivityAnalysis analysis = new ActivityAnalysis();
|
ActivityAnalysis analysis = new ActivityAnalysis();
|
||||||
amounts = analysis.calculateActivityAmounts(getSamplesOfDay(db, day, device));
|
amounts = analysis.calculateActivityAmounts(getSamplesOfDay(db, day, mOffsetHours, device));
|
||||||
if (activityAmountCache != null) {
|
if (activityAmountCache != null) {
|
||||||
activityAmountCache.add(day.hashCode(), amounts);
|
activityAmountCache.add(day.hashCode() ^ mOffsetHours, amounts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,6 +288,8 @@ public abstract class AbstractWeekChartFragment extends AbstractChartFragment {
|
||||||
|
|
||||||
abstract int getGoal();
|
abstract int getGoal();
|
||||||
|
|
||||||
|
abstract int getOffsetHours();
|
||||||
|
|
||||||
abstract float[] getTotalsForActivityAmounts(ActivityAmounts activityAmounts);
|
abstract float[] getTotalsForActivityAmounts(ActivityAmounts activityAmounts);
|
||||||
|
|
||||||
abstract String formatPieValue(int value);
|
abstract String formatPieValue(int value);
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
|
||||||
private PagerTabStrip mPagerTabStrip;
|
private PagerTabStrip mPagerTabStrip;
|
||||||
private ViewPager viewPager;
|
private ViewPager viewPager;
|
||||||
|
|
||||||
LimitedQueue mActivityAmountCache = new LimitedQueue(32);
|
LimitedQueue mActivityAmountCache = new LimitedQueue(60);
|
||||||
|
|
||||||
private static class ShowDurationDialog extends Dialog {
|
private static class ShowDurationDialog extends Dialog {
|
||||||
private final String mDuration;
|
private final String mDuration;
|
||||||
|
|
|
@ -30,6 +30,11 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
|
||||||
return 8 * 60; // FIXME
|
return 8 * 60; // FIXME
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
int getOffsetHours() {
|
||||||
|
return -12;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
float[] getTotalsForActivityAmounts(ActivityAmounts activityAmounts) {
|
float[] getTotalsForActivityAmounts(ActivityAmounts activityAmounts) {
|
||||||
long totalSecondsDeepSleep = 0;
|
long totalSecondsDeepSleep = 0;
|
||||||
|
|
|
@ -29,6 +29,11 @@ public class WeekStepsChartFragment extends AbstractWeekChartFragment {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
int getOffsetHours() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
float[] getTotalsForActivityAmounts(ActivityAmounts activityAmounts) {
|
float[] getTotalsForActivityAmounts(ActivityAmounts activityAmounts) {
|
||||||
int totalSteps = 0;
|
int totalSteps = 0;
|
||||||
|
|
Loading…
Reference in New Issue