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 17a6d7d8e2..ef0277d170 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/BgReading.java +++ b/app/src/main/java/info/nightscout/androidaps/db/BgReading.java @@ -1,5 +1,7 @@ package info.nightscout.androidaps.db; +import android.content.res.Resources; + import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.table.DatabaseTable; @@ -219,7 +221,7 @@ public class BgReading implements DataPointWithLabelInterface { return color; } - private int getPredectionColor() { + public int getPredectionColor() { if (isIOBPrediction) return MainApp.sResources.getColor(R.color.iob); if (isCOBPrediction) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java index db26cdec65..696b8b0b57 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java @@ -477,7 +477,8 @@ public class WatchUpdaterService extends WearableListenerService implements if (!predArray.isEmpty()) { for (BgReading bg : predArray) { - predictions.add(predictionMap(bg.date, bg.value)); + if (bg.value < 40) continue; + predictions.add(predictionMap(bg.date, bg.value, bg.getPredectionColor())); } } } @@ -520,10 +521,11 @@ public class WatchUpdaterService extends WearableListenerService implements return dm; } - private DataMap predictionMap(long timestamp, double sgv) { + private DataMap predictionMap(long timestamp, double sgv, int color) { DataMap dm = new DataMap(); dm.putLong("timestamp", timestamp); dm.putDouble("sgv", sgv); + dm.putInt("color", color); return dm; } diff --git a/wear/src/main/java/info/nightscout/androidaps/data/BgWatchData.java b/wear/src/main/java/info/nightscout/androidaps/data/BgWatchData.java index 8f20d77282..4f258ee074 100644 --- a/wear/src/main/java/info/nightscout/androidaps/data/BgWatchData.java +++ b/wear/src/main/java/info/nightscout/androidaps/data/BgWatchData.java @@ -1,5 +1,7 @@ package info.nightscout.androidaps.data; +import java.util.Objects; + /** * Created by emmablack on 1/7/15. */ @@ -8,12 +10,14 @@ public class BgWatchData implements Comparable{ public double high; public double low; public long timestamp; + public int color; - public BgWatchData(double aSgv, double aHigh, double aLow, long aTimestamp) { + public BgWatchData(double aSgv, double aHigh, double aLow, long aTimestamp, int aColor) { this.sgv = aSgv; this.high = aHigh; this.low = aLow; this.timestamp = aTimestamp; + this.color = aColor; } public BgWatchData(){ @@ -25,12 +29,14 @@ public class BgWatchData implements Comparable{ if(! (that instanceof BgWatchData)){ return false; } + if (this.color != ((BgWatchData) that).color) + return false; return this.timestamp == ((BgWatchData) that).timestamp; } @Override - public int hashCode(){ - return (int) (timestamp%Integer.MAX_VALUE); + public int hashCode() { + return Objects.hash(timestamp, color); } @Override diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BIGChart.java b/wear/src/main/java/info/nightscout/androidaps/watchfaces/BIGChart.java index ce8c931078..b61bdc866b 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BIGChart.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/BIGChart.java @@ -428,6 +428,7 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre BgWatchData bwd = new BgWatchData(); bwd.timestamp = prediction.getLong("timestamp"); bwd.sgv = prediction.getDouble("sgv"); + bwd.color = prediction.getInt("color"); predictionList.add(bwd); } } @@ -649,13 +650,15 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre double high = entry.getDouble("high"); double low = entry.getDouble("low"); long timestamp = entry.getLong("timestamp"); - bgDataList.add(new BgWatchData(sgv, high, low, timestamp)); + int color = entry.getInt("color", 0); + bgDataList.add(new BgWatchData(sgv, high, low, timestamp, color)); } } else { double sgv = dataMap.getDouble("sgvDouble"); double high = dataMap.getDouble("high"); double low = dataMap.getDouble("low"); long timestamp = dataMap.getLong("timestamp"); + int color = dataMap.getInt("color", 0); final int size = bgDataList.size(); if (size > 0) { @@ -663,7 +666,7 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre return; // Ignore duplicates. } - bgDataList.add(new BgWatchData(sgv, high, low, timestamp)); + bgDataList.add(new BgWatchData(sgv, high, low, timestamp, color)); } for (int i = 0; i < bgDataList.size(); i++) { diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BaseWatchFace.java b/wear/src/main/java/info/nightscout/androidaps/watchfaces/BaseWatchFace.java index 3c980a713f..47ea3dbf08 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BaseWatchFace.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/BaseWatchFace.java @@ -604,13 +604,15 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen double high = entry.getDouble("high"); double low = entry.getDouble("low"); long timestamp = entry.getLong("timestamp"); - bgDataList.add(new BgWatchData(sgv, high, low, timestamp)); + int color = entry.getInt("color", 0); + bgDataList.add(new BgWatchData(sgv, high, low, timestamp, color)); } } else { double sgv = dataMap.getDouble("sgvDouble"); double high = dataMap.getDouble("high"); double low = dataMap.getDouble("low"); long timestamp = dataMap.getLong("timestamp"); + int color = dataMap.getInt("color", 0); final int size = bgDataList.size(); if (size > 0) { @@ -618,7 +620,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen return; // Ignore duplicates. } - bgDataList.add(new BgWatchData(sgv, high, low, timestamp)); + bgDataList.add(new BgWatchData(sgv, high, low, timestamp, color)); } for (int i = 0; i < bgDataList.size(); i++) { @@ -689,6 +691,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen BgWatchData bwd = new BgWatchData(); bwd.timestamp = prediction.getLong("timestamp"); bwd.sgv = prediction.getDouble("sgv"); + bwd.color = prediction.getInt("color"); predictionList.add(bwd); } } diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BgGraphBuilder.java b/wear/src/main/java/info/nightscout/androidaps/watchfaces/BgGraphBuilder.java index 7d50d7ff4c..4a401489d9 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BgGraphBuilder.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/BgGraphBuilder.java @@ -10,7 +10,9 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.GregorianCalendar; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.TimeZone; import info.nightscout.androidaps.data.BasalWatchData; @@ -173,13 +175,12 @@ public class BgGraphBuilder { } } + addPredictionLines(lines); lines.add(basalLine((float) minChart, factor, highlight)); lines.add(bolusLine((float) minChart)); lines.add(bolusInvalidLine((float) minChart)); lines.add(carbsLine((float) minChart)); lines.add(smbLine((float) minChart)); - lines.add(predictionLine()); - return lines; } @@ -275,29 +276,30 @@ public class BgGraphBuilder { } - private Line predictionLine() { - - List pointValues = new ArrayList(); - + private void addPredictionLines(List lines) { + Map> values = new HashMap<>(); long endTime = getPredictionEndTime(); - for (BgWatchData bwd: predictionsList) { - if(bwd.timestamp <= endTime) { - pointValues.add(new PointValue(fuzz(bwd.timestamp), (float) bwd.sgv)); + for (BgWatchData bwd : predictionsList) { + if (bwd.timestamp <= endTime) { + double value = bwd.sgv < 300 ? bwd.sgv : 300; + if (!values.containsKey(bwd.color)) { + values.put(bwd.color, new ArrayList<>()); + } + values.get(bwd.color).add(new PointValue(fuzz(bwd.timestamp), (float) value)); } } - Line line = new Line(pointValues); - line.setColor(Color.MAGENTA); - line.setHasLines(false); - int size = pointSize/2; - size = (size>0)?size:1; - line.setPointRadius(size); - line.setHasPoints(true); - return line; + for (Map.Entry> entry : values.entrySet()) { + Line line = new Line(entry.getValue()); + line.setColor(entry.getKey()); + line.setHasLines(false); + int size = pointSize / 2; + size = (size > 0) ? size : 1; + line.setPointRadius(size); + line.setHasPoints(true); + lines.add(line); + } } - - - public Line highValuesLine() { Line highValuesLine = new Line(highValues); highValuesLine.setColor(highColor); diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.java b/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.java index 3c479f3f86..4b6922fb90 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.java @@ -573,7 +573,8 @@ public class CircleWatchface extends WatchFace implements SharedPreferences.OnSh double high = dataMap.getDouble("high"); double low = dataMap.getDouble("low"); long timestamp = dataMap.getLong("timestamp"); - bgDataList.add(new BgWatchData(sgv, high, low, timestamp)); + int color = dataMap.getInt("color", 0); + bgDataList.add(new BgWatchData(sgv, high, low, timestamp, color)); } else if (!sharedPrefs.getBoolean("animation", false)) { // don't load history at once if animations are set (less resource consumption) Log.d("addToWatchSet", "entries.size(): " + entries.size()); @@ -583,7 +584,8 @@ public class CircleWatchface extends WatchFace implements SharedPreferences.OnSh double high = entry.getDouble("high"); double low = entry.getDouble("low"); long timestamp = entry.getLong("timestamp"); - bgDataList.add(new BgWatchData(sgv, high, low, timestamp)); + int color = entry.getInt("color", 0); + bgDataList.add(new BgWatchData(sgv, high, low, timestamp, color)); } } else