From ebfc4e307572c99dc133053cfa7e74fc01398884 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 21 Aug 2017 15:36:52 +0200 Subject: [PATCH] colored predictions --- .../nightscout/androidaps/db/BgReading.java | 30 ++++++++++++++++--- .../androidaps/db/CareportalEvent.java | 5 ++++ .../androidaps/db/ExtendedBolus.java | 5 ++++ .../androidaps/db/ProfileSwitch.java | 5 ++++ .../nightscout/androidaps/db/Treatment.java | 5 ++++ .../androidaps/plugins/Loop/APSResult.java | 8 ++--- .../DataPointWithLabelInterface.java | 1 + .../PointsWithLabelGraphSeries.java | 23 +++++++------- app/src/main/res/values/colors.xml | 1 + 9 files changed, 65 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/db/BgReading.java b/app/src/main/java/info/nightscout/androidaps/db/BgReading.java index cbe1850958..725094ae21 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/BgReading.java +++ b/app/src/main/java/info/nightscout/androidaps/db/BgReading.java @@ -17,7 +17,6 @@ import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv; import info.nightscout.androidaps.plugins.Overview.OverviewPlugin; import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface; import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries; -import info.nightscout.utils.DateUtil; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.SP; @@ -43,7 +42,10 @@ public class BgReading implements DataPointWithLabelInterface { @DatabaseField public String _id = null; // NS _id - public boolean isPrediction = false; // true when drawing predictions as bg points + public boolean isCOBPrediction = false; // true when drawing predictions as bg points (COB) + public boolean isaCOBPrediction = false; // true when drawing predictions as bg points (aCOB) + public boolean isIOBPrediction = false; // true when drawing predictions as bg points (IOB) + public boolean isUAMPrediction = false; // true when drawing predictions as bg points (UAM) public BgReading() { } @@ -181,7 +183,10 @@ public class BgReading implements DataPointWithLabelInterface { @Override public PointsWithLabelGraphSeries.Shape getShape() { - return PointsWithLabelGraphSeries.Shape.POINT; + if (isPrediction()) + return PointsWithLabelGraphSeries.Shape.PREDICTION; + else + return PointsWithLabelGraphSeries.Shape.BG; } @Override @@ -202,7 +207,7 @@ public class BgReading implements DataPointWithLabelInterface { highLine = Profile.fromMgdlToUnits(OverviewPlugin.bgTargetHigh, units); } int color = MainApp.sResources.getColor(R.color.inrange); - if (isPrediction) + if (isPrediction()) color = MainApp.sResources.getColor(R.color.prediction); else if (valueToUnits(units) < lowLine) color = MainApp.sResources.getColor(R.color.low); @@ -211,4 +216,21 @@ public class BgReading implements DataPointWithLabelInterface { return color; } + @Override + public int getSecondColor() { + if (isIOBPrediction) + return MainApp.sResources.getColor(R.color.iob); + if (isCOBPrediction) + return MainApp.sResources.getColor(R.color.cob); + if (isaCOBPrediction) + return 0x80FFFFFF & MainApp.sResources.getColor(R.color.cob); + if (isUAMPrediction) + return MainApp.sResources.getColor(R.color.uam); + return R.color.mdtp_white; + } + + private boolean isPrediction() { + return isaCOBPrediction || isCOBPrediction || isIOBPrediction || isUAMPrediction; + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java b/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java index f65da51176..b88b3e1009 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java +++ b/app/src/main/java/info/nightscout/androidaps/db/CareportalEvent.java @@ -242,4 +242,9 @@ public class CareportalEvent implements DataPointWithLabelInterface { return Color.GRAY; return Color.GRAY; } + + @Override + public int getSecondColor() { + return 0; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/db/ExtendedBolus.java b/app/src/main/java/info/nightscout/androidaps/db/ExtendedBolus.java index 32a9eca24c..1c3d7a6ce6 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/ExtendedBolus.java +++ b/app/src/main/java/info/nightscout/androidaps/db/ExtendedBolus.java @@ -280,4 +280,9 @@ public class ExtendedBolus implements Interval, DataPointWithLabelInterface { public int getColor() { return Color.CYAN; } + + @Override + public int getSecondColor() { + return 0; + } } diff --git a/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java b/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java index fb99934382..cbdf86b5ab 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java +++ b/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java @@ -202,6 +202,11 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface { return Color.CYAN; } + @Override + public int getSecondColor() { + return 0; + } + public String toString() { return "ProfileSwitch{" + "date=" + date + diff --git a/app/src/main/java/info/nightscout/androidaps/db/Treatment.java b/app/src/main/java/info/nightscout/androidaps/db/Treatment.java index 971e1d55f1..c89dc4e71c 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/Treatment.java +++ b/app/src/main/java/info/nightscout/androidaps/db/Treatment.java @@ -173,6 +173,11 @@ public class Treatment implements DataPointWithLabelInterface { return Color.CYAN; } + @Override + public int getSecondColor() { + return 0; + } + @Override public void setY(double y) { yValue = y; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java index 9b44bc40fd..8a6bf74aed 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java @@ -104,7 +104,7 @@ public class APSResult { BgReading bg = new BgReading(); bg.value = iob.getInt(i); bg.date = startTime + i * 5 * 60 * 1000L; - bg.isPrediction = true; + bg.isIOBPrediction = true; array.add(bg); } } @@ -114,7 +114,7 @@ public class APSResult { BgReading bg = new BgReading(); bg.value = iob.getInt(i); bg.date = startTime + i * 5 * 60 * 1000L; - bg.isPrediction = true; + bg.isaCOBPrediction = true; array.add(bg); } } @@ -124,7 +124,7 @@ public class APSResult { BgReading bg = new BgReading(); bg.value = iob.getInt(i); bg.date = startTime + i * 5 * 60 * 1000L; - bg.isPrediction = true; + bg.isCOBPrediction = true; array.add(bg); } } @@ -134,7 +134,7 @@ public class APSResult { BgReading bg = new BgReading(); bg.value = iob.getInt(i); bg.date = startTime + i * 5 * 60 * 1000L; - bg.isPrediction = true; + bg.isUAMPrediction = true; array.add(bg); } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/DataPointWithLabelInterface.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/DataPointWithLabelInterface.java index 20d478692a..3f6280431c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/DataPointWithLabelInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/DataPointWithLabelInterface.java @@ -55,4 +55,5 @@ public interface DataPointWithLabelInterface extends DataPointInterface{ PointsWithLabelGraphSeries.Shape getShape(); float getSize(); int getColor(); + int getSecondColor(); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/PointsWithLabelGraphSeries.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/PointsWithLabelGraphSeries.java index 970aaa8385..b8575a5f7c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/PointsWithLabelGraphSeries.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/PointsWithLabelGraphSeries.java @@ -50,14 +50,8 @@ public class PointsWithLabelGraphSeries e * You can also render a custom drawing via {@link com.jjoe64.graphview.series.PointsGraphSeries.CustomShape} */ public enum Shape { - /** - * draws a point / circle - */ - POINT, - - /** - * draws a triangle - */ + BG, + PREDICTION, TRIANGLE, RECTANGLE, BOLUS, @@ -191,9 +185,19 @@ public class PointsWithLabelGraphSeries e // draw data point if (!overdraw) { - if (value.getShape() == Shape.POINT) { + if (value.getShape() == Shape.BG) { + mPaint.setStyle(Paint.Style.FILL); mPaint.setStrokeWidth(0); canvas.drawCircle(endX, endY, value.getSize(), mPaint); + } else if (value.getShape() == Shape.PREDICTION) { + mPaint.setColor(value.getColor()); + mPaint.setStyle(Paint.Style.FILL); + mPaint.setStrokeWidth(0); + canvas.drawCircle(endX, endY, value.getSize(), mPaint); + mPaint.setColor(value.getSecondColor()); + mPaint.setStyle(Paint.Style.FILL); + mPaint.setStrokeWidth(0); + canvas.drawCircle(endX, endY, value.getSize() / 3, mPaint); } else if (value.getShape() == Shape.RECTANGLE) { canvas.drawRect(endX-value.getSize(), endY-value.getSize(), endX+value.getSize(), endY+value.getSize(), mPaint); } else if (value.getShape() == Shape.TRIANGLE) { @@ -244,7 +248,6 @@ public class PointsWithLabelGraphSeries e } else if (value.getShape() == Shape.MBG) { mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeWidth(5); - float w = mPaint.getStrokeWidth(); canvas.drawCircle(endX, endY, value.getSize(), mPaint); } else if (value.getShape() == Shape.BGCHECK) { mPaint.setStyle(Paint.Style.FILL_AND_STROKE); diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 5b1d364563..33943af398 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -4,6 +4,7 @@ #00ffff #FFFB8C00 #8BC34A + #ffea00 #FFFFFF #00FF00 #FF0000