From 552fdaa9deb2ade33db34cca353a56d64cba7f6c Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Fri, 18 Nov 2016 02:31:29 +0100 Subject: [PATCH] wear watch painting basals --- .../info/nightscout/androidaps/BIGChart.java | 25 +++++---- .../nightscout/androidaps/BasalWatchData.java | 12 +++++ .../nightscout/androidaps/BaseWatchFace.java | 4 +- .../nightscout/androidaps/BgGraphBuilder.java | 54 +++++++++++++++---- 4 files changed, 73 insertions(+), 22 deletions(-) create mode 100644 wear/src/main/java/info/nightscout/androidaps/BasalWatchData.java diff --git a/wear/src/main/java/info/nightscout/androidaps/BIGChart.java b/wear/src/main/java/info/nightscout/androidaps/BIGChart.java index 55799bf897..bcf78f1af2 100644 --- a/wear/src/main/java/info/nightscout/androidaps/BIGChart.java +++ b/wear/src/main/java/info/nightscout/androidaps/BIGChart.java @@ -41,7 +41,7 @@ import lecho.lib.hellocharts.util.ChartUtils; import lecho.lib.hellocharts.view.LineChartView; /** - * Created by stephenblack on 12/29/14. + * Created by adrianLxM. */ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPreferenceChangeListener { public final static IntentFilter INTENT_FILTER; @@ -64,6 +64,7 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre public double datetime; public ArrayList bgDataList = new ArrayList<>(); public ArrayList tempWatchDataList = new ArrayList<>(); + public ArrayList basalWatchDataList = new ArrayList<>(); public PowerManager.WakeLock wakeLock; // related endTime manual layout public View layoutView; @@ -302,7 +303,18 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre tempWatchDataList.add(twd); } } - //TODO Adrian: also load temps + ArrayList basals = dataMap.getDataMapArrayList("basals"); + if (basals != null) { + basalWatchDataList = new ArrayList<>(); + for (DataMap basal : basals) { + BasalWatchData bwd = new BasalWatchData(); + bwd.startTime = basal.getLong("starttime"); + bwd.endTime = basal.getLong("endtime"); + bwd.amount = basal.getDouble("amount"); + //bwd.afterwards; + basalWatchDataList.add(bwd); + } + } } private void showAgeAndStatus() { @@ -498,11 +510,6 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre public void missedReadingAlert() { int minutes_since = (int) Math.floor(timeSince()/(1000*60)); if(minutes_since >= 16 && ((minutes_since - 16) % 5) == 0) { - /*NotificationCompat.Builder notification = new NotificationCompat.Builder(getApplicationContext()) - .setContentTitle("Missed BG Readings") - .setVibrate(vibratePattern); - NotificationManager mNotifyMgr = (hNotificationManager) getApplicationContext().getSystemService(getApplicationContext().NOTIFICATION_SERVICE); - mNotifyMgr.notify(missed_readings_alert_id, notification.build());*/ ListenerService.requestData(this); // attempt endTime recover missing data } } @@ -552,9 +559,9 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre if(bgDataList.size() > 0) { //Dont crash things just because we dont have values, people dont like crashy things int timeframe = Integer.parseInt(sharedPrefs.getString("chart_timeframe", "5")); if (singleLine) { - bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList, tempWatchDataList, pointSize, midColor, timeframe); + bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList, tempWatchDataList, basalWatchDataList, pointSize, midColor, timeframe); } else { - bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList, tempWatchDataList, pointSize, highColor, lowColor, midColor, timeframe); + bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList, tempWatchDataList, basalWatchDataList, pointSize, highColor, lowColor, midColor, timeframe); } chart.setLineChartData(bgGraphBuilder.lineData()); diff --git a/wear/src/main/java/info/nightscout/androidaps/BasalWatchData.java b/wear/src/main/java/info/nightscout/androidaps/BasalWatchData.java new file mode 100644 index 0000000000..1d85a73fd7 --- /dev/null +++ b/wear/src/main/java/info/nightscout/androidaps/BasalWatchData.java @@ -0,0 +1,12 @@ +package info.nightscout.androidaps; + +/** + * Created by adrian on 18/11/16. + */ + +public class BasalWatchData { + public long startTime; + public long endTime; + public double amount; + public double afterwards; +} diff --git a/wear/src/main/java/info/nightscout/androidaps/BaseWatchFace.java b/wear/src/main/java/info/nightscout/androidaps/BaseWatchFace.java index 0541a6c248..1663d25b37 100644 --- a/wear/src/main/java/info/nightscout/androidaps/BaseWatchFace.java +++ b/wear/src/main/java/info/nightscout/androidaps/BaseWatchFace.java @@ -376,9 +376,9 @@ protected abstract void setColorDark(); if(bgDataList.size() > 0) { //Dont crash things just because we dont have values, people dont like crashy things int timeframe = Integer.parseInt(sharedPrefs.getString("chart_timeframe", "5")); if (singleLine) { - bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList, new ArrayList(), pointSize, midColor, timeframe); + bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList, new ArrayList(), new ArrayList(), pointSize, midColor, timeframe); } else { - bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList, new ArrayList(), pointSize, highColor, lowColor, midColor, timeframe); + bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList, new ArrayList(), new ArrayList(), pointSize, highColor, lowColor, midColor, timeframe); } chart.setLineChartData(bgGraphBuilder.lineData()); diff --git a/wear/src/main/java/info/nightscout/androidaps/BgGraphBuilder.java b/wear/src/main/java/info/nightscout/androidaps/BgGraphBuilder.java index 411a3d2475..22773b2af6 100644 --- a/wear/src/main/java/info/nightscout/androidaps/BgGraphBuilder.java +++ b/wear/src/main/java/info/nightscout/androidaps/BgGraphBuilder.java @@ -24,6 +24,7 @@ import lecho.lib.hellocharts.model.Viewport; * Created by stephenblack on 11/15/14. */ public class BgGraphBuilder { + private ArrayList basalWatchDataList; public List tempWatchDataList; private int timespan; public double end_time; @@ -46,7 +47,7 @@ public class BgGraphBuilder { private List lowValues = new ArrayList(); public Viewport viewport; - public BgGraphBuilder(Context context, List aBgList, List tempWatchDataList, int aPointSize, int aMidColor, int timespan) { + public BgGraphBuilder(Context context, List aBgList, List tempWatchDataList, ArrayList basalWatchDataList, int aPointSize, int aMidColor, int timespan) { end_time = new Date().getTime() + (1000 * 60 * 6 * timespan); //Now plus 30 minutes padding (for 5 hours. Less if less.) start_time = new Date().getTime() - (1000 * 60 * 60 * timespan); //timespan hours ago this.bgDataList = aBgList; @@ -60,9 +61,10 @@ public class BgGraphBuilder { this.highColor = aMidColor; this.timespan = timespan; this.tempWatchDataList = tempWatchDataList; + this.basalWatchDataList = basalWatchDataList; } - public BgGraphBuilder(Context context, List aBgList, List tempWatchDataList, int aPointSize, int aHighColor, int aLowColor, int aMidColor, int timespan) { + public BgGraphBuilder(Context context, List aBgList, List tempWatchDataList, ArrayList basalWatchDataList, int aPointSize, int aHighColor, int aLowColor, int aMidColor, int timespan) { end_time = new Date().getTime() + (1000 * 60 * 6 * timespan); //Now plus 30 minutes padding (for 5 hours. Less if less.) start_time = new Date().getTime() - (1000 * 60 * 60 * timespan); //timespan hours ago this.bgDataList = aBgList; @@ -75,6 +77,7 @@ public class BgGraphBuilder { this.midColor = aMidColor; this.timespan = timespan; this.tempWatchDataList = tempWatchDataList; + this.basalWatchDataList = basalWatchDataList; } public LineChartData lineData() { @@ -105,7 +108,13 @@ public class BgGraphBuilder { } } - double maxBasal = 0.8; //TODO Adrian keine Konstante! + double maxBasal = 0.1; + for (BasalWatchData bwd: basalWatchDataList) { + if(bwd.amount > maxBasal){ + maxBasal = bwd.amount; + } + } + double maxTemp = maxBasal; for (TempWatchData twd: tempWatchDataList) { if(twd.amount > maxTemp){ @@ -122,9 +131,33 @@ public class BgGraphBuilder { } } + lines.add(basalLine((float) minChart, factor)); + return lines; } + private Line basalLine(float offset, double factor) { + + List pointValues = new ArrayList(); + + for (BasalWatchData bwd: basalWatchDataList) { + if(bwd.endTime > start_time) { + long begin = (long) Math.max(start_time, bwd.startTime); + pointValues.add(new PointValue(fuzz(begin), offset + (float) (factor * bwd.amount))); + pointValues.add(new PointValue(fuzz(bwd.endTime), offset + (float) (factor * bwd.amount))); + } + } + + Line basalLine = new Line(pointValues); + basalLine.setHasPoints(false); + basalLine.setColor(Color.parseColor("#00BFFF")); + basalLine.setPathEffect(new DashPathEffect(new float[]{4f, 3f}, 4f)); + basalLine.setStrokeWidth(1); + return basalLine; + + + } + public Line highValuesLine() { Line highValuesLine = new Line(highValues); highValuesLine.setColor(highColor); @@ -161,18 +194,17 @@ public class BgGraphBuilder { public Line tempValuesLine(TempWatchData twd, float offset, double factor) { List lineValues = new ArrayList(); - long begin = (long) Math.max(start_time, twd.startTime); - lineValues.add(new PointValue(fuzz(begin), offset + (float)(factor*twd.startBasal))); - lineValues.add(new PointValue(fuzz(begin), offset +(float)(factor*twd.amount))); - lineValues.add(new PointValue(fuzz(twd.endTime), offset + (float)(factor*twd.amount))); - lineValues.add(new PointValue(fuzz(twd.endTime), offset + (float)(factor*twd.endBasal))); - - - + long begin = (long) Math.max(start_time, twd.startTime); + lineValues.add(new PointValue(fuzz(begin), offset + (float) (factor * twd.startBasal))); + lineValues.add(new PointValue(fuzz(begin), offset + (float) (factor * twd.amount))); + lineValues.add(new PointValue(fuzz(twd.endTime), offset + (float) (factor * twd.amount))); + lineValues.add(new PointValue(fuzz(twd.endTime), offset + (float) (factor * twd.endBasal))); + lineValues.add(new PointValue(fuzz(begin), offset + (float) (factor * twd.startBasal))); Line valueLine = new Line(lineValues); valueLine.setHasPoints(false); valueLine.setColor(Color.BLUE); valueLine.setStrokeWidth(1); + valueLine.setFilled(true); return valueLine; }