mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-08 19:27:04 +01:00
Garmin: Awake time (WIP)
This commit is contained in:
parent
cae6f5d73e
commit
b6e2ce1d9c
@ -78,6 +78,7 @@ public abstract class AbstractActivityChartFragment<D extends ChartsData> extend
|
||||
protected ActivityConfig akLightSleep;
|
||||
protected ActivityConfig akDeepSleep;
|
||||
protected ActivityConfig akRemSleep;
|
||||
protected ActivityConfig akAwakeSleep;
|
||||
protected ActivityConfig akNotWorn;
|
||||
|
||||
protected int BACKGROUND_COLOR;
|
||||
@ -89,6 +90,7 @@ public abstract class AbstractActivityChartFragment<D extends ChartsData> extend
|
||||
protected int AK_ACTIVITY_COLOR;
|
||||
protected int AK_DEEP_SLEEP_COLOR;
|
||||
protected int AK_REM_SLEEP_COLOR;
|
||||
protected int AK_AWAKE_SLEEP_COLOR;
|
||||
protected int AK_LIGHT_SLEEP_COLOR;
|
||||
protected int AK_NOT_WORN_COLOR;
|
||||
|
||||
@ -117,6 +119,8 @@ public abstract class AbstractActivityChartFragment<D extends ChartsData> extend
|
||||
AK_LIGHT_SLEEP_COLOR = runningColor.data;
|
||||
getContext().getTheme().resolveAttribute(R.attr.chart_rem_sleep, runningColor, true);
|
||||
AK_REM_SLEEP_COLOR = runningColor.data;
|
||||
getContext().getTheme().resolveAttribute(R.attr.chart_awake_sleep, runningColor, true);
|
||||
AK_AWAKE_SLEEP_COLOR = runningColor.data;
|
||||
getContext().getTheme().resolveAttribute(R.attr.chart_not_worn, runningColor, true);
|
||||
AK_NOT_WORN_COLOR = runningColor.data;
|
||||
|
||||
@ -127,6 +131,7 @@ public abstract class AbstractActivityChartFragment<D extends ChartsData> extend
|
||||
akLightSleep = new ActivityConfig(ActivityKind.LIGHT_SLEEP, getString(R.string.abstract_chart_fragment_kind_light_sleep), AK_LIGHT_SLEEP_COLOR);
|
||||
akDeepSleep = new ActivityConfig(ActivityKind.DEEP_SLEEP, getString(R.string.abstract_chart_fragment_kind_deep_sleep), AK_DEEP_SLEEP_COLOR);
|
||||
akRemSleep = new ActivityConfig(ActivityKind.REM_SLEEP, getString(R.string.abstract_chart_fragment_kind_rem_sleep), AK_REM_SLEEP_COLOR);
|
||||
akAwakeSleep = new ActivityConfig(ActivityKind.REM_SLEEP, getString(R.string.abstract_chart_fragment_kind_awake_sleep), AK_AWAKE_SLEEP_COLOR);
|
||||
akNotWorn = new ActivityConfig(ActivityKind.NOT_WORN, getString(R.string.abstract_chart_fragment_kind_not_worn), AK_NOT_WORN_COLOR);
|
||||
}
|
||||
|
||||
@ -138,6 +143,8 @@ public abstract class AbstractActivityChartFragment<D extends ChartsData> extend
|
||||
return akLightSleep.color;
|
||||
case REM_SLEEP:
|
||||
return akRemSleep.color;
|
||||
case AWAKE_SLEEP:
|
||||
return akAwakeSleep.color;
|
||||
case ACTIVITY:
|
||||
return akActivity.color;
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ public class ActivityAnalysis {
|
||||
ActivityAmount deepSleep = new ActivityAmount(ActivityKind.DEEP_SLEEP);
|
||||
ActivityAmount lightSleep = new ActivityAmount(ActivityKind.LIGHT_SLEEP);
|
||||
ActivityAmount remSleep = new ActivityAmount(ActivityKind.REM_SLEEP);
|
||||
ActivityAmount awakeSleep = new ActivityAmount(ActivityKind.AWAKE_SLEEP);
|
||||
ActivityAmount notWorn = new ActivityAmount(ActivityKind.NOT_WORN);
|
||||
ActivityAmount activity = new ActivityAmount(ActivityKind.ACTIVITY);
|
||||
|
||||
@ -57,6 +58,9 @@ public class ActivityAnalysis {
|
||||
case REM_SLEEP:
|
||||
amount = remSleep;
|
||||
break;
|
||||
case AWAKE_SLEEP:
|
||||
amount = awakeSleep;
|
||||
break;
|
||||
case NOT_WORN:
|
||||
amount = notWorn;
|
||||
break;
|
||||
@ -115,6 +119,9 @@ public class ActivityAnalysis {
|
||||
if (remSleep.getTotalSeconds() > 0) {
|
||||
result.addAmount(remSleep);
|
||||
}
|
||||
if (awakeSleep.getTotalSeconds() > 0) {
|
||||
result.addAmount(awakeSleep);
|
||||
}
|
||||
if (activity.getTotalSeconds() > 0) {
|
||||
result.addAmount(activity);
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ public class SleepAnalysis {
|
||||
long lightSleepDuration = 0;
|
||||
long deepSleepDuration = 0;
|
||||
long remSleepDuration = 0;
|
||||
long awakeSleepDuration = 0;
|
||||
long durationSinceLastSleep = 0;
|
||||
|
||||
for (ActivitySample sample : samples) {
|
||||
@ -48,13 +49,14 @@ public class SleepAnalysis {
|
||||
durationSinceLastSleep = 0;
|
||||
} else {
|
||||
//exclude "not worn" times from sleep sessions as this makes a discrepancy with the charts
|
||||
if (lightSleepDuration + deepSleepDuration + remSleepDuration > MIN_SESSION_LENGTH)
|
||||
result.add(new SleepSession(sleepStart, sleepEnd, lightSleepDuration, deepSleepDuration, remSleepDuration));
|
||||
if (lightSleepDuration + deepSleepDuration + remSleepDuration + awakeSleepDuration > MIN_SESSION_LENGTH)
|
||||
result.add(new SleepSession(sleepStart, sleepEnd, lightSleepDuration, deepSleepDuration, remSleepDuration, awakeSleepDuration));
|
||||
sleepStart = null;
|
||||
sleepEnd = null;
|
||||
lightSleepDuration = 0;
|
||||
deepSleepDuration = 0;
|
||||
remSleepDuration = 0;
|
||||
awakeSleepDuration = 0;
|
||||
}
|
||||
|
||||
if (previousSample != null) {
|
||||
@ -65,24 +67,27 @@ public class SleepAnalysis {
|
||||
deepSleepDuration += durationSinceLastSample;
|
||||
} else if (sample.getKind() == ActivityKind.REM_SLEEP) {
|
||||
remSleepDuration += durationSinceLastSample;
|
||||
} else if (sample.getKind() == ActivityKind.AWAKE_SLEEP) {
|
||||
awakeSleepDuration += durationSinceLastSample;
|
||||
} else {
|
||||
durationSinceLastSleep += durationSinceLastSample;
|
||||
if (sleepStart != null && durationSinceLastSleep > MAX_WAKE_PHASE_LENGTH) {
|
||||
if (lightSleepDuration + deepSleepDuration + remSleepDuration > MIN_SESSION_LENGTH)
|
||||
result.add(new SleepSession(sleepStart, sleepEnd, lightSleepDuration, deepSleepDuration, remSleepDuration));
|
||||
if (lightSleepDuration + deepSleepDuration + remSleepDuration + awakeSleepDuration > MIN_SESSION_LENGTH)
|
||||
result.add(new SleepSession(sleepStart, sleepEnd, lightSleepDuration, deepSleepDuration, remSleepDuration, awakeSleepDuration));
|
||||
sleepStart = null;
|
||||
sleepEnd = null;
|
||||
lightSleepDuration = 0;
|
||||
deepSleepDuration = 0;
|
||||
remSleepDuration = 0;
|
||||
awakeSleepDuration = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
previousSample = sample;
|
||||
}
|
||||
if (lightSleepDuration + deepSleepDuration + remSleepDuration > MIN_SESSION_LENGTH) {
|
||||
result.add(new SleepSession(sleepStart, sleepEnd, lightSleepDuration, deepSleepDuration, remSleepDuration));
|
||||
if (lightSleepDuration + deepSleepDuration + remSleepDuration + awakeSleepDuration > MIN_SESSION_LENGTH) {
|
||||
result.add(new SleepSession(sleepStart, sleepEnd, lightSleepDuration, deepSleepDuration, remSleepDuration, awakeSleepDuration));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -90,7 +95,8 @@ public class SleepAnalysis {
|
||||
private boolean isSleep(ActivitySample sample) {
|
||||
return sample.getKind() == ActivityKind.DEEP_SLEEP ||
|
||||
sample.getKind() == ActivityKind.LIGHT_SLEEP ||
|
||||
sample.getKind() == ActivityKind.REM_SLEEP;
|
||||
sample.getKind() == ActivityKind.REM_SLEEP ||
|
||||
sample.getKind() == ActivityKind.AWAKE_SLEEP;
|
||||
}
|
||||
|
||||
private Date getDateFromSample(ActivitySample sample) {
|
||||
@ -104,17 +110,20 @@ public class SleepAnalysis {
|
||||
private final long lightSleepDuration;
|
||||
private final long deepSleepDuration;
|
||||
private final long remSleepDuration;
|
||||
private final long awakeSleepDuration;
|
||||
|
||||
private SleepSession(Date sleepStart,
|
||||
Date sleepEnd,
|
||||
long lightSleepDuration,
|
||||
long deepSleepDuration,
|
||||
long remSleepDuration) {
|
||||
long remSleepDuration,
|
||||
long awakeSleepDuration) {
|
||||
this.sleepStart = sleepStart;
|
||||
this.sleepEnd = sleepEnd;
|
||||
this.lightSleepDuration = lightSleepDuration;
|
||||
this.deepSleepDuration = deepSleepDuration;
|
||||
this.remSleepDuration = remSleepDuration;
|
||||
this.awakeSleepDuration = awakeSleepDuration;
|
||||
}
|
||||
|
||||
public Date getSleepStart() {
|
||||
@ -136,5 +145,9 @@ public class SleepAnalysis {
|
||||
public long getRemSleepDuration() {
|
||||
return remSleepDuration;
|
||||
}
|
||||
|
||||
public long getAwakeSleepDuration() {
|
||||
return awakeSleepDuration;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -68,6 +68,8 @@ public class SleepChartFragment extends AbstractActivityChartFragment<SleepChart
|
||||
private TextView mSleepchartInfo;
|
||||
private TextView remSleepTimeText;
|
||||
private LinearLayout remSleepTimeTextWrapper;
|
||||
private TextView awakeSleepTimeText;
|
||||
private LinearLayout awakeSleepTimeTextWrapper;
|
||||
private TextView deepSleepTimeText;
|
||||
private TextView lightSleepTimeText;
|
||||
private TextView lowestHrText;
|
||||
@ -132,7 +134,8 @@ public class SleepChartFragment extends AbstractActivityChartFragment<SleepChart
|
||||
final long lightSleepDuration = calculateLightSleepDuration(sleepSessions);
|
||||
final long deepSleepDuration = calculateDeepSleepDuration(sleepSessions);
|
||||
final long remSleepDuration = calculateRemSleepDuration(sleepSessions);
|
||||
final long totalSeconds = lightSleepDuration + deepSleepDuration + remSleepDuration;
|
||||
final long awakeSleepDuration = calculateAwakeSleepDuration(sleepSessions);
|
||||
final long totalSeconds = lightSleepDuration + deepSleepDuration + remSleepDuration + awakeSleepDuration;
|
||||
|
||||
final List<PieEntry> entries = new ArrayList<>();
|
||||
final List<Integer> colors = new ArrayList<>();
|
||||
@ -148,6 +151,9 @@ public class SleepChartFragment extends AbstractActivityChartFragment<SleepChart
|
||||
colors.add(getColorFor(ActivityKind.REM_SLEEP));
|
||||
}
|
||||
|
||||
entries.add(new PieEntry(awakeSleepDuration, getActivity().getString(R.string.abstract_chart_fragment_kind_awake_sleep)));
|
||||
colors.add(getColorFor(ActivityKind.AWAKE_SLEEP));
|
||||
|
||||
} else {
|
||||
entries.add(new PieEntry(1));
|
||||
colors.add(getResources().getColor(R.color.gauge_line_color));
|
||||
@ -163,11 +169,12 @@ public class SleepChartFragment extends AbstractActivityChartFragment<SleepChart
|
||||
data.setDataSet(set);
|
||||
|
||||
String totalSleep = DateTimeUtils.formatDurationHoursMinutes(totalSeconds, TimeUnit.SECONDS);
|
||||
String totalAwake = DateTimeUtils.formatDurationHoursMinutes(awakeSleepDuration, TimeUnit.SECONDS);
|
||||
String totalRem = DateTimeUtils.formatDurationHoursMinutes(remSleepDuration, TimeUnit.SECONDS);
|
||||
String totalDeep = DateTimeUtils.formatDurationHoursMinutes(deepSleepDuration, TimeUnit.SECONDS);
|
||||
String totalLight = DateTimeUtils.formatDurationHoursMinutes(lightSleepDuration, TimeUnit.SECONDS);
|
||||
//setupLegend(pieChart);
|
||||
return new MySleepChartsData(data, sleepSessions, totalSleep, totalRem, totalDeep, totalLight);
|
||||
return new MySleepChartsData(data, sleepSessions, totalSleep, totalAwake, totalRem, totalDeep, totalLight);
|
||||
}
|
||||
|
||||
private long calculateLightSleepDuration(List<SleepSession> sleepSessions) {
|
||||
@ -194,6 +201,14 @@ public class SleepChartFragment extends AbstractActivityChartFragment<SleepChart
|
||||
return result;
|
||||
}
|
||||
|
||||
private long calculateAwakeSleepDuration(List<SleepSession> sleepSessions) {
|
||||
long result = 0;
|
||||
for (SleepSession sleepSession : sleepSessions) {
|
||||
result += sleepSession.getAwakeSleepDuration();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateChartsnUIThread(MyChartsData mcd) {
|
||||
MySleepChartsData pieData = mcd.getPieData();
|
||||
@ -207,10 +222,12 @@ public class SleepChartFragment extends AbstractActivityChartFragment<SleepChart
|
||||
mSleepAmountChart.setCenterTextColor(GBApplication.getTextColor(getContext()));
|
||||
mSleepAmountChart.setCenterText(pieData.getTotalSleep());
|
||||
if (!pieData.sleepSessions.isEmpty()) {
|
||||
awakeSleepTimeText.setText(pieData.getTotalAwake());
|
||||
remSleepTimeText.setText(pieData.getTotalRem());
|
||||
deepSleepTimeText.setText(pieData.getTotalDeep());
|
||||
lightSleepTimeText.setText(pieData.getTotalLight());
|
||||
} else {
|
||||
awakeSleepTimeText.setText("-");
|
||||
remSleepTimeText.setText("-");
|
||||
deepSleepTimeText.setText("-");
|
||||
lightSleepTimeText.setText("-");
|
||||
@ -357,6 +374,8 @@ public class SleepChartFragment extends AbstractActivityChartFragment<SleepChart
|
||||
mSleepchartInfo = rootView.findViewById(R.id.sleepchart_info);
|
||||
remSleepTimeText = rootView.findViewById(R.id.sleep_chart_legend_rem_time);
|
||||
remSleepTimeTextWrapper = rootView.findViewById(R.id.sleep_chart_legend_rem_time_wrapper);
|
||||
awakeSleepTimeText = rootView.findViewById(R.id.sleep_chart_legend_awake_time);
|
||||
awakeSleepTimeTextWrapper = rootView.findViewById(R.id.sleep_chart_legend_awake_time_wrapper);
|
||||
deepSleepTimeText = rootView.findViewById(R.id.sleep_chart_legend_deep_time);
|
||||
lightSleepTimeText = rootView.findViewById(R.id.sleep_chart_legend_light_time);
|
||||
lowestHrText = rootView.findViewById(R.id.sleep_hr_lowest);
|
||||
@ -484,15 +503,17 @@ public class SleepChartFragment extends AbstractActivityChartFragment<SleepChart
|
||||
|
||||
private static class MySleepChartsData extends ChartsData {
|
||||
private String totalSleep;
|
||||
private String totalAwake;
|
||||
private String totalRem;
|
||||
private String totalDeep;
|
||||
private String totalLight;
|
||||
private final PieData pieData;
|
||||
private final List<SleepSession> sleepSessions;
|
||||
|
||||
public MySleepChartsData(PieData pieData, List<SleepSession> sleepSessions, String totalSleep, String totalRem, String totalDeep, String totalLight) {
|
||||
public MySleepChartsData(PieData pieData, List<SleepSession> sleepSessions, String totalSleep, String totalAwake, String totalRem, String totalDeep, String totalLight) {
|
||||
this.pieData = pieData;
|
||||
this.sleepSessions = sleepSessions;
|
||||
this.totalAwake = totalAwake;
|
||||
this.totalSleep = totalSleep;
|
||||
this.totalRem = totalRem;
|
||||
this.totalDeep = totalDeep;
|
||||
@ -507,6 +528,10 @@ public class SleepChartFragment extends AbstractActivityChartFragment<SleepChart
|
||||
return totalSleep;
|
||||
}
|
||||
|
||||
public CharSequence getTotalAwake() {
|
||||
return totalAwake;
|
||||
}
|
||||
|
||||
public CharSequence getTotalRem() {
|
||||
return totalRem;
|
||||
}
|
||||
|
@ -52,6 +52,8 @@ import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
||||
|
||||
public class WeekSleepChartFragment extends AbstractWeekChartFragment {
|
||||
|
||||
private TextView awakeSleepTimeText;
|
||||
private LinearLayout awakeSleepTimeTextWrapper;
|
||||
private TextView remSleepTimeText;
|
||||
private LinearLayout remSleepTimeTextWrapper;
|
||||
private TextView deepSleepTimeText;
|
||||
@ -77,6 +79,7 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
|
||||
day = (Calendar) day.clone(); // do not modify the caller's argument
|
||||
day.add(Calendar.DATE, -TOTAL_DAYS + 1);
|
||||
TOTAL_DAYS_FOR_AVERAGE=0;
|
||||
long awakeWeeklyTotal = 0;
|
||||
long remWeeklyTotal = 0;
|
||||
long deepWeeklyTotal = 0;
|
||||
long lightWeeklyTotal = 0;
|
||||
@ -90,13 +93,12 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
|
||||
float[] totalAmounts = getTotalsForActivityAmounts(amounts);
|
||||
deepWeeklyTotal += (long) totalAmounts[0];
|
||||
lightWeeklyTotal += (long) totalAmounts[1];
|
||||
if (supportsRemSleep(device)) {
|
||||
remWeeklyTotal += (long) totalAmounts[2];
|
||||
}
|
||||
awakeWeeklyTotal += (long) totalAmounts[3];
|
||||
day.add(Calendar.DATE, 1);
|
||||
}
|
||||
|
||||
return new MySleepWeeklyData(remWeeklyTotal, deepWeeklyTotal, lightWeeklyTotal);
|
||||
return new MySleepWeeklyData(awakeWeeklyTotal, remWeeklyTotal, deepWeeklyTotal, lightWeeklyTotal);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -112,6 +114,8 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
|
||||
mWeekChart = rootView.findViewById(R.id.weekstepschart);
|
||||
remSleepTimeText = rootView.findViewById(R.id.sleep_chart_legend_rem_time);
|
||||
remSleepTimeTextWrapper = rootView.findViewById(R.id.sleep_chart_legend_rem_time_wrapper);
|
||||
awakeSleepTimeText = rootView.findViewById(R.id.sleep_chart_legend_awake_time);
|
||||
awakeSleepTimeTextWrapper = rootView.findViewById(R.id.sleep_chart_legend_awake_time_wrapper);
|
||||
deepSleepTimeText = rootView.findViewById(R.id.sleep_chart_legend_deep_time);
|
||||
lightSleepTimeText = rootView.findViewById(R.id.sleep_chart_legend_light_time);
|
||||
sleepDatesText = rootView.findViewById(R.id.sleep_dates);
|
||||
@ -147,10 +151,13 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
|
||||
lightSleepTimeText.setText(DateTimeUtils.formatDurationHoursMinutes((int) avgLight, TimeUnit.MINUTES));
|
||||
float avgRem = Math.abs(this.mySleepWeeklyData.getTotalRem() / TOTAL_DAYS_FOR_AVERAGE);
|
||||
remSleepTimeText.setText(DateTimeUtils.formatDurationHoursMinutes((int) avgRem, TimeUnit.MINUTES));
|
||||
float avgAwake = Math.abs(this.mySleepWeeklyData.getTotalAwake() / TOTAL_DAYS_FOR_AVERAGE);
|
||||
awakeSleepTimeText.setText(DateTimeUtils.formatDurationHoursMinutes((int) avgAwake, TimeUnit.MINUTES));
|
||||
} else {
|
||||
deepSleepTimeText.setText("-");
|
||||
lightSleepTimeText.setText("-");
|
||||
remSleepTimeText.setText("-");
|
||||
awakeSleepTimeText.setText("-");
|
||||
}
|
||||
|
||||
if (!supportsRemSleep(getChartsHost().getDevice())) {
|
||||
@ -237,6 +244,7 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
|
||||
long totalSecondsDeepSleep = 0;
|
||||
long totalSecondsLightSleep = 0;
|
||||
long totalSecondsRemSleep = 0;
|
||||
long totalSecondsAwakeSleep = 0;
|
||||
for (ActivityAmount amount : activityAmounts.getAmounts()) {
|
||||
if (amount.getActivityKind() == ActivityKind.DEEP_SLEEP) {
|
||||
totalSecondsDeepSleep += amount.getTotalSeconds();
|
||||
@ -244,16 +252,15 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
|
||||
totalSecondsLightSleep += amount.getTotalSeconds();
|
||||
} else if (amount.getActivityKind() == ActivityKind.REM_SLEEP) {
|
||||
totalSecondsRemSleep += amount.getTotalSeconds();
|
||||
} else if (amount.getActivityKind() == ActivityKind.AWAKE_SLEEP) {
|
||||
totalSecondsAwakeSleep += amount.getTotalSeconds();
|
||||
}
|
||||
}
|
||||
int totalMinutesDeepSleep = (int) (totalSecondsDeepSleep / 60);
|
||||
int totalMinutesLightSleep = (int) (totalSecondsLightSleep / 60);
|
||||
int totalMinutesRemSleep = (int) (totalSecondsRemSleep / 60);
|
||||
if (supportsRemSleep(getChartsHost().getDevice())) {
|
||||
return new float[]{totalMinutesDeepSleep, totalMinutesLightSleep, totalMinutesRemSleep};
|
||||
} else {
|
||||
return new float[]{totalMinutesDeepSleep, totalMinutesLightSleep};
|
||||
}
|
||||
int totalMinutesAwakeSleep = (int) (totalSecondsAwakeSleep / 60);
|
||||
return new float[]{totalMinutesDeepSleep, totalMinutesLightSleep, totalMinutesRemSleep, totalMinutesAwakeSleep};
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -349,18 +356,24 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
|
||||
}
|
||||
|
||||
private static class MySleepWeeklyData {
|
||||
private long totalAwake;
|
||||
private long totalRem;
|
||||
private long totalDeep;
|
||||
private long totalLight;
|
||||
private int totalDaysForAverage;
|
||||
|
||||
public MySleepWeeklyData(long totalRem, long totalDeep, long totalLight) {
|
||||
public MySleepWeeklyData(long totalAwake, long totalRem, long totalDeep, long totalLight) {
|
||||
this.totalDeep = totalDeep;
|
||||
this.totalRem = totalRem;
|
||||
this.totalAwake = totalAwake;
|
||||
this.totalLight = totalLight;
|
||||
this.totalDaysForAverage = 0;
|
||||
}
|
||||
|
||||
public long getTotalAwake() {
|
||||
return this.totalAwake;
|
||||
}
|
||||
|
||||
public long getTotalRem() {
|
||||
return this.totalRem;
|
||||
}
|
||||
|
@ -174,6 +174,9 @@ public class GarminActivitySampleProvider extends AbstractSampleProvider<GarminA
|
||||
sample.setRawKind(sleepType.getCode());
|
||||
|
||||
switch (sleepType) {
|
||||
case AWAKE_SLEEP:
|
||||
sample.setRawIntensity(50);
|
||||
break;
|
||||
case DEEP_SLEEP:
|
||||
sample.setRawIntensity(20);
|
||||
break;
|
||||
@ -197,6 +200,8 @@ public class GarminActivitySampleProvider extends AbstractSampleProvider<GarminA
|
||||
}
|
||||
|
||||
switch (sleepStage) {
|
||||
case AWAKE:
|
||||
return ActivityKind.AWAKE_SLEEP;
|
||||
case LIGHT:
|
||||
return ActivityKind.LIGHT_SLEEP;
|
||||
case DEEP:
|
||||
|
@ -85,6 +85,7 @@ public class DailyTotals {
|
||||
long[] sleep = getTotalsSleepForActivityAmounts(amountsSleep);
|
||||
long steps = getTotalsStepsForActivityAmounts(amountsSteps);
|
||||
|
||||
// Purposely not including awake sleep
|
||||
return new long[]{steps, sleep[0] + sleep[1] + sleep[2]};
|
||||
}
|
||||
|
||||
@ -92,6 +93,7 @@ public class DailyTotals {
|
||||
long totalSecondsDeepSleep = 0;
|
||||
long totalSecondsLightSleep = 0;
|
||||
long totalSecondsRemSleep = 0;
|
||||
long totalSecondsAwakeSleep = 0;
|
||||
for (ActivityAmount amount : activityAmounts.getAmounts()) {
|
||||
if (amount.getActivityKind() == ActivityKind.DEEP_SLEEP) {
|
||||
totalSecondsDeepSleep += amount.getTotalSeconds();
|
||||
@ -99,12 +101,15 @@ public class DailyTotals {
|
||||
totalSecondsLightSleep += amount.getTotalSeconds();
|
||||
} else if (amount.getActivityKind() == ActivityKind.REM_SLEEP) {
|
||||
totalSecondsRemSleep += amount.getTotalSeconds();
|
||||
} else if (amount.getActivityKind() == ActivityKind.AWAKE_SLEEP) {
|
||||
totalSecondsAwakeSleep += amount.getTotalSeconds();
|
||||
}
|
||||
}
|
||||
long totalMinutesDeepSleep = (totalSecondsDeepSleep / 60);
|
||||
long totalMinutesLightSleep = (totalSecondsLightSleep / 60);
|
||||
long totalMinutesRemSleep = (totalSecondsRemSleep / 60);
|
||||
return new long[]{totalMinutesDeepSleep, totalMinutesLightSleep, totalMinutesRemSleep};
|
||||
long totalMinutesAwakeSleep = (totalSecondsAwakeSleep / 60);
|
||||
return new long[]{totalMinutesDeepSleep, totalMinutesLightSleep, totalMinutesRemSleep, totalMinutesAwakeSleep};
|
||||
}
|
||||
|
||||
|
||||
|
@ -154,6 +154,42 @@
|
||||
android:text="@string/sleep_colored_stats_rem"
|
||||
android:textSize="12sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/sleep_chart_legend_awake_time_wrapper"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="20dip"
|
||||
android:paddingTop="20dip"
|
||||
android:paddingRight="20dip">
|
||||
|
||||
<View
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="5dp"
|
||||
android:background="@color/chart_awake_sleep_dark" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sleep_chart_legend_awake_time"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="start"
|
||||
android:layout_marginTop="20dip"
|
||||
android:gravity="center"
|
||||
android:text="@string/stats_empty_value"
|
||||
android:textSize="20sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sleep_chart_legend_awake_legend"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="start"
|
||||
android:gravity="center"
|
||||
android:text="@string/abstract_chart_fragment_kind_awake_sleep"
|
||||
android:textSize="12sp" />
|
||||
</LinearLayout>
|
||||
</TableRow>
|
||||
</TableLayout>
|
||||
|
||||
|
@ -140,6 +140,39 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"/>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:id="@+id/sleep_chart_legend_awake_time_wrapper"
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="20dip"
|
||||
android:paddingLeft="20dip"
|
||||
android:paddingRight="20dip"
|
||||
android:gravity="center"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="0dp"
|
||||
>
|
||||
<View
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="5dp"
|
||||
android:background="@color/chart_awake_sleep_dark"/>
|
||||
<TextView
|
||||
android:layout_marginTop="20dip"
|
||||
android:id="@+id/sleep_chart_legend_awake_time"
|
||||
android:text="@string/stats_empty_value"
|
||||
android:textSize="20sp"
|
||||
android:layout_gravity="start"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"/>
|
||||
<TextView
|
||||
android:id="@+id/sleep_chart_legend_awake_legend"
|
||||
android:text="@string/sleep_colored_stats_awake_avg"
|
||||
android:textSize="12sp"
|
||||
android:layout_gravity="start"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"/>
|
||||
</LinearLayout>
|
||||
</TableRow>
|
||||
</TableLayout>
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
<attr name="chart_deep_sleep" format="color" />
|
||||
<attr name="chart_light_sleep" format="color" />
|
||||
<attr name="chart_rem_sleep" format="color" />
|
||||
<attr name="chart_awake_sleep" format="color" />
|
||||
<attr name="chart_activity" format="color" />
|
||||
<attr name="chart_not_worn" format="color" />
|
||||
<attr name="alternate_row_background" format="color" />
|
||||
|
@ -31,6 +31,9 @@
|
||||
<color name="chart_rem_sleep_light" type="color">#e427c7</color>
|
||||
<color name="chart_rem_sleep_dark" type="color">#e427c7</color>
|
||||
|
||||
<color name="chart_awake_sleep_light" type="color">#ff866e</color>
|
||||
<color name="chart_awake_sleep_dark" type="color">#ff866e</color>
|
||||
|
||||
<color name="chart_activity_light" type="color">#60bd6d</color>
|
||||
<color name="chart_activity_dark" type="color">#59b22c</color>
|
||||
|
||||
|
@ -976,7 +976,7 @@
|
||||
<string name="abstract_chart_fragment_kind_light_sleep">Light sleep</string>
|
||||
<string name="abstract_chart_fragment_kind_deep_sleep">Deep sleep</string>
|
||||
<string name="abstract_chart_fragment_kind_rem_sleep">REM sleep</string>
|
||||
<string name="abstract_chart_fragment_kind_awake_sleep">Awake sleep</string>
|
||||
<string name="abstract_chart_fragment_kind_awake_sleep">Awake</string>
|
||||
<string name="abstract_chart_fragment_kind_not_worn">Not worn</string>
|
||||
<string name="sleep_colored_stats_deep">Deep</string>
|
||||
<string name="sleep_colored_stats_light">Light</string>
|
||||
@ -984,6 +984,7 @@
|
||||
<string name="sleep_colored_stats_deep_avg">Deep AVG</string>
|
||||
<string name="sleep_colored_stats_light_avg">Light AVG</string>
|
||||
<string name="sleep_colored_stats_rem_avg">REM AVG</string>
|
||||
<string name="sleep_colored_stats_awake_avg">Awake AVG</string>
|
||||
<string name="stats_empty_value">-</string>
|
||||
<string name="stats_lowest_hr">Lowest HR</string>
|
||||
<string name="stats_highest_hr">Highest HR</string>
|
||||
|
@ -27,6 +27,7 @@
|
||||
<item name="chart_deep_sleep">@color/chart_deep_sleep_light</item>
|
||||
<item name="chart_light_sleep">@color/chart_light_sleep_light</item>
|
||||
<item name="chart_rem_sleep">@color/chart_rem_sleep_light</item>
|
||||
<item name="chart_awake_sleep">@color/chart_awake_sleep_light</item>
|
||||
<item name="chart_activity">@color/chart_activity_light</item>
|
||||
<item name="chart_not_worn">@color/chart_not_worn_light</item>
|
||||
<item name="alternate_row_background">@color/alternate_row_background_light</item>
|
||||
@ -68,6 +69,7 @@
|
||||
<item name="chart_deep_sleep">@color/chart_deep_sleep_dark</item>
|
||||
<item name="chart_light_sleep">@color/chart_light_sleep_dark</item>
|
||||
<item name="chart_rem_sleep">@color/chart_rem_sleep_dark</item>
|
||||
<item name="chart_awake_sleep">@color/chart_awake_sleep_dark</item>
|
||||
<item name="chart_activity">@color/chart_activity_dark</item>
|
||||
<item name="chart_not_worn">@color/chart_not_worn_dark</item>
|
||||
<item name="alternate_row_background">@color/alternate_row_background_dark</item>
|
||||
|
Loading…
Reference in New Issue
Block a user