From 26792717d4b4fb1b7ede733f9b90463c8eb9c4a7 Mon Sep 17 00:00:00 2001 From: Daniele Gobbetti Date: Fri, 28 Aug 2015 14:54:49 +0200 Subject: [PATCH] Add showing when the device wasn't worn by the user --- .../charts/AbstractChartFragment.java | 28 ++++++++++++------- .../activities/charts/ActivityAnalysis.java | 4 +++ .../charts/ActivitySleepChartFragment.java | 6 ++-- .../devices/miband/MiBandSampleProvider.java | 10 +++++-- .../gadgetbridge/model/ActivityKind.java | 6 +++- app/src/main/res/values/colors.xml | 3 ++ 6 files changed, 42 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractChartFragment.java index 3ba71387..5a10e1ca 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractChartFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/AbstractChartFragment.java @@ -93,6 +93,8 @@ public abstract class AbstractChartFragment extends AbstractGBFragment { protected ActivityConfig akActivity = new ActivityConfig(ActivityKind.TYPE_ACTIVITY, "Activity", Color.rgb(89, 178, 44)); protected ActivityConfig akLightSleep = new ActivityConfig(ActivityKind.TYPE_LIGHT_SLEEP, "Light Sleep", Color.rgb(182, 191, 255)); protected ActivityConfig akDeepSleep = new ActivityConfig(ActivityKind.TYPE_DEEP_SLEEP, "Deep Sleep", Color.rgb(76, 90, 255)); + protected ActivityConfig akNotWorn = new ActivityConfig(ActivityKind.TYPE_NOT_WORN, "Not Worn", Color.rgb(84, 82, 84)); + protected int BACKGROUND_COLOR; protected int DESCRIPTION_COLOR; @@ -101,6 +103,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment { protected int AK_ACTIVITY_COLOR; protected int AK_DEEP_SLEEP_COLOR; protected int AK_LIGHT_SLEEP_COLOR; + protected int AK_NOT_WORN_COLOR; protected AbstractChartFragment(String... intentFilterActions) { mIntentFilterActions = new HashSet<>(); @@ -133,10 +136,12 @@ public abstract class AbstractChartFragment extends AbstractGBFragment { 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); + AK_NOT_WORN_COLOR = getResources().getColor(R.color.chart_not_worn_light); akActivity.color = AK_ACTIVITY_COLOR; akLightSleep.color = AK_LIGHT_SLEEP_COLOR; akDeepSleep.color = AK_DEEP_SLEEP_COLOR; + akNotWorn.color = AK_NOT_WORN_COLOR; } private void setStartDate(Date date) { @@ -396,25 +401,28 @@ public abstract class AbstractChartFragment extends AbstractGBFragment { float movement = sample.getIntensity(); float value = movement; - if (type == ActivityKind.TYPE_DEEP_SLEEP) { - value += SleepUtils.Y_VALUE_DEEP_SLEEP; - activityEntries.add(createBarEntry(value, i)); - colors.add(akDeepSleep.color); - } else { - if (type == ActivityKind.TYPE_LIGHT_SLEEP) { - activityEntries.add(createBarEntry(value, i)); + switch (type) { + case ActivityKind.TYPE_DEEP_SLEEP: + value += SleepUtils.Y_VALUE_DEEP_SLEEP; + colors.add(akDeepSleep.color); + break; + case ActivityKind.TYPE_LIGHT_SLEEP: colors.add(akLightSleep.color); - } else { + 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: // 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; - activityEntries.add(createBarEntry(value, i)); colors.add(akActivity.color); - } } + activityEntries.add(createBarEntry(value, i)); String xLabel = ""; if (annotate) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityAnalysis.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityAnalysis.java index 873053bf..f656b058 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityAnalysis.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityAnalysis.java @@ -11,6 +11,7 @@ public class ActivityAnalysis { public ActivityAmounts calculateActivityAmounts(List samples) { ActivityAmount deepSleep = new ActivityAmount(ActivityKind.TYPE_DEEP_SLEEP); ActivityAmount lightSleep = new ActivityAmount(ActivityKind.TYPE_LIGHT_SLEEP); + ActivityAmount notWorn = new ActivityAmount(ActivityKind.TYPE_NOT_WORN); ActivityAmount activity = new ActivityAmount(ActivityKind.TYPE_ACTIVITY); ActivityAmount previousAmount = null; @@ -24,6 +25,9 @@ public class ActivityAnalysis { case ActivityKind.TYPE_LIGHT_SLEEP: amount = lightSleep; break; + case ActivityKind.TYPE_NOT_WORN: + amount = notWorn; + break; case ActivityKind.TYPE_ACTIVITY: default: amount = activity; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivitySleepChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivitySleepChartFragment.java index 294af1f4..d3a380e4 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivitySleepChartFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivitySleepChartFragment.java @@ -115,14 +115,16 @@ public class ActivitySleepChartFragment extends AbstractChartFragment { } protected void setupLegend(Chart chart) { - List legendColors = new ArrayList<>(3); - List legendLabels = new ArrayList<>(3); + List legendColors = new ArrayList<>(4); + List legendLabels = new ArrayList<>(4); legendColors.add(akActivity.color); legendLabels.add(akActivity.label); legendColors.add(akLightSleep.color); legendLabels.add(akLightSleep.label); legendColors.add(akDeepSleep.color); legendLabels.add(akDeepSleep.label); + legendColors.add(akNotWorn.color); + legendLabels.add(akNotWorn.label); chart.getLegend().setColors(legendColors); chart.getLegend().setLabels(legendLabels); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandSampleProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandSampleProvider.java index fb378e03..80405991 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandSampleProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/miband/MiBandSampleProvider.java @@ -8,9 +8,9 @@ public class MiBandSampleProvider implements SampleProvider { public static final byte TYPE_LIGHT_SLEEP = 4; public static final byte TYPE_ACTIVITY = -1; public static final byte TYPE_UNKNOWN = -1; + public static final byte TYPE_NONWEAR = 3; + public static final byte TYPE_CHARGING = 6; -// public static final byte TYPE_CHARGING = 6; -// public static final byte TYPE_NONWEAR = 3; // public static final byte TYPE_NREM = 5; // DEEP SLEEP // public static final byte TYPE_ONBED = 7; // public static final byte TYPE_REM = 4; // LIGHT SLEEP @@ -31,6 +31,10 @@ public class MiBandSampleProvider implements SampleProvider { return ActivityKind.TYPE_LIGHT_SLEEP; case TYPE_ACTIVITY: return ActivityKind.TYPE_ACTIVITY; + case TYPE_NONWEAR: + return ActivityKind.TYPE_NOT_WORN; + case TYPE_CHARGING: + return ActivityKind.TYPE_NOT_WORN; //I believe it's a safe assumption default: // case TYPE_UNKNOWN: // fall through return ActivityKind.TYPE_UNKNOWN; @@ -46,6 +50,8 @@ public class MiBandSampleProvider implements SampleProvider { return TYPE_DEEP_SLEEP; case ActivityKind.TYPE_LIGHT_SLEEP: return TYPE_LIGHT_SLEEP; + case ActivityKind.TYPE_NOT_WORN: + return TYPE_NONWEAR; case ActivityKind.TYPE_UNKNOWN: // fall through default: return TYPE_UNKNOWN; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityKind.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityKind.java index 3314b4f7..a857c9d0 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityKind.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/model/ActivityKind.java @@ -9,9 +9,10 @@ public class ActivityKind { public static final int TYPE_ACTIVITY = 1; public static final int TYPE_LIGHT_SLEEP = 2; public static final int TYPE_DEEP_SLEEP = 4; + public static final int TYPE_NOT_WORN = 8; public static final int TYPE_SLEEP = TYPE_LIGHT_SLEEP | TYPE_DEEP_SLEEP; - public static final int TYPE_ALL = TYPE_ACTIVITY | TYPE_SLEEP; + public static final int TYPE_ALL = TYPE_ACTIVITY | TYPE_SLEEP | TYPE_NOT_WORN; public static byte[] mapToDBActivityTypes(int types, SampleProvider provider) { byte[] result = new byte[3]; @@ -25,6 +26,9 @@ public class ActivityKind { if ((types & ActivityKind.TYPE_LIGHT_SLEEP) != 0) { result[i++] = provider.toRawActivityKind(TYPE_LIGHT_SLEEP); } + if ((types & ActivityKind.TYPE_NOT_WORN) != 0) { + result[i++] = provider.toRawActivityKind(TYPE_NOT_WORN); + } return Arrays.copyOf(result, i); } diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 340861c2..56bd6251 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -20,4 +20,7 @@ #60bd6d #59b22c + #545254 + #d8d9d8 + \ No newline at end of file