wear watch painting basals

This commit is contained in:
AdrianLxM 2016-11-18 02:31:29 +01:00
parent 2b17fc5155
commit 552fdaa9de
4 changed files with 73 additions and 22 deletions

View file

@ -41,7 +41,7 @@ import lecho.lib.hellocharts.util.ChartUtils;
import lecho.lib.hellocharts.view.LineChartView; 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 class BIGChart extends WatchFace implements SharedPreferences.OnSharedPreferenceChangeListener {
public final static IntentFilter INTENT_FILTER; public final static IntentFilter INTENT_FILTER;
@ -64,6 +64,7 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
public double datetime; public double datetime;
public ArrayList<BgWatchData> bgDataList = new ArrayList<>(); public ArrayList<BgWatchData> bgDataList = new ArrayList<>();
public ArrayList<TempWatchData> tempWatchDataList = new ArrayList<>(); public ArrayList<TempWatchData> tempWatchDataList = new ArrayList<>();
public ArrayList<BasalWatchData> basalWatchDataList = new ArrayList<>();
public PowerManager.WakeLock wakeLock; public PowerManager.WakeLock wakeLock;
// related endTime manual layout // related endTime manual layout
public View layoutView; public View layoutView;
@ -302,7 +303,18 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
tempWatchDataList.add(twd); tempWatchDataList.add(twd);
} }
} }
//TODO Adrian: also load temps ArrayList<DataMap> 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() { private void showAgeAndStatus() {
@ -498,11 +510,6 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre
public void missedReadingAlert() { public void missedReadingAlert() {
int minutes_since = (int) Math.floor(timeSince()/(1000*60)); int minutes_since = (int) Math.floor(timeSince()/(1000*60));
if(minutes_since >= 16 && ((minutes_since - 16) % 5) == 0) { 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 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 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")); int timeframe = Integer.parseInt(sharedPrefs.getString("chart_timeframe", "5"));
if (singleLine) { if (singleLine) {
bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList, tempWatchDataList, pointSize, midColor, timeframe); bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList, tempWatchDataList, basalWatchDataList, pointSize, midColor, timeframe);
} else { } 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()); chart.setLineChartData(bgGraphBuilder.lineData());

View file

@ -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;
}

View file

@ -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 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")); int timeframe = Integer.parseInt(sharedPrefs.getString("chart_timeframe", "5"));
if (singleLine) { if (singleLine) {
bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList, new ArrayList<TempWatchData>(), pointSize, midColor, timeframe); bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList, new ArrayList<TempWatchData>(), new ArrayList<BasalWatchData>(), pointSize, midColor, timeframe);
} else { } else {
bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList, new ArrayList<TempWatchData>(), pointSize, highColor, lowColor, midColor, timeframe); bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), bgDataList, new ArrayList<TempWatchData>(), new ArrayList<BasalWatchData>(), pointSize, highColor, lowColor, midColor, timeframe);
} }
chart.setLineChartData(bgGraphBuilder.lineData()); chart.setLineChartData(bgGraphBuilder.lineData());

View file

@ -24,6 +24,7 @@ import lecho.lib.hellocharts.model.Viewport;
* Created by stephenblack on 11/15/14. * Created by stephenblack on 11/15/14.
*/ */
public class BgGraphBuilder { public class BgGraphBuilder {
private ArrayList<BasalWatchData> basalWatchDataList;
public List<TempWatchData> tempWatchDataList; public List<TempWatchData> tempWatchDataList;
private int timespan; private int timespan;
public double end_time; public double end_time;
@ -46,7 +47,7 @@ public class BgGraphBuilder {
private List<PointValue> lowValues = new ArrayList<PointValue>(); private List<PointValue> lowValues = new ArrayList<PointValue>();
public Viewport viewport; public Viewport viewport;
public BgGraphBuilder(Context context, List<BgWatchData> aBgList, List<TempWatchData> tempWatchDataList, int aPointSize, int aMidColor, int timespan) { public BgGraphBuilder(Context context, List<BgWatchData> aBgList, List<TempWatchData> tempWatchDataList, ArrayList<BasalWatchData> 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.) 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 start_time = new Date().getTime() - (1000 * 60 * 60 * timespan); //timespan hours ago
this.bgDataList = aBgList; this.bgDataList = aBgList;
@ -60,9 +61,10 @@ public class BgGraphBuilder {
this.highColor = aMidColor; this.highColor = aMidColor;
this.timespan = timespan; this.timespan = timespan;
this.tempWatchDataList = tempWatchDataList; this.tempWatchDataList = tempWatchDataList;
this.basalWatchDataList = basalWatchDataList;
} }
public BgGraphBuilder(Context context, List<BgWatchData> aBgList, List<TempWatchData> tempWatchDataList, int aPointSize, int aHighColor, int aLowColor, int aMidColor, int timespan) { public BgGraphBuilder(Context context, List<BgWatchData> aBgList, List<TempWatchData> tempWatchDataList, ArrayList<BasalWatchData> 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.) 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 start_time = new Date().getTime() - (1000 * 60 * 60 * timespan); //timespan hours ago
this.bgDataList = aBgList; this.bgDataList = aBgList;
@ -75,6 +77,7 @@ public class BgGraphBuilder {
this.midColor = aMidColor; this.midColor = aMidColor;
this.timespan = timespan; this.timespan = timespan;
this.tempWatchDataList = tempWatchDataList; this.tempWatchDataList = tempWatchDataList;
this.basalWatchDataList = basalWatchDataList;
} }
public LineChartData lineData() { 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; double maxTemp = maxBasal;
for (TempWatchData twd: tempWatchDataList) { for (TempWatchData twd: tempWatchDataList) {
if(twd.amount > maxTemp){ if(twd.amount > maxTemp){
@ -122,9 +131,33 @@ public class BgGraphBuilder {
} }
} }
lines.add(basalLine((float) minChart, factor));
return lines; return lines;
} }
private Line basalLine(float offset, double factor) {
List<PointValue> pointValues = new ArrayList<PointValue>();
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() { public Line highValuesLine() {
Line highValuesLine = new Line(highValues); Line highValuesLine = new Line(highValues);
highValuesLine.setColor(highColor); highValuesLine.setColor(highColor);
@ -161,18 +194,17 @@ public class BgGraphBuilder {
public Line tempValuesLine(TempWatchData twd, float offset, double factor) { public Line tempValuesLine(TempWatchData twd, float offset, double factor) {
List<PointValue> lineValues = new ArrayList<PointValue>(); List<PointValue> lineValues = new ArrayList<PointValue>();
long begin = (long) Math.max(start_time, twd.startTime); 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.startBasal)));
lineValues.add(new PointValue(fuzz(begin), offset +(float)(factor*twd.amount))); 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.amount)));
lineValues.add(new PointValue(fuzz(twd.endTime), offset + (float)(factor*twd.endBasal))); 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); Line valueLine = new Line(lineValues);
valueLine.setHasPoints(false); valueLine.setHasPoints(false);
valueLine.setColor(Color.BLUE); valueLine.setColor(Color.BLUE);
valueLine.setStrokeWidth(1); valueLine.setStrokeWidth(1);
valueLine.setFilled(true);
return valueLine; return valueLine;
} }