Merge pull request #971 from jotomo/watch-pred-colors

Watch: colored preds.
This commit is contained in:
Milos Kozak 2018-05-02 16:38:01 +02:00 committed by GitHub
commit 6697c66435
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 52 additions and 32 deletions

View file

@ -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)

View file

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

View file

@ -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<BgWatchData>{
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<BgWatchData>{
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);
return Objects.hash(timestamp, color);
}
@Override

View file

@ -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++) {

View file

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

View file

@ -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,28 +276,29 @@ public class BgGraphBuilder {
}
private Line predictionLine() {
List<PointValue> pointValues = new ArrayList<PointValue>();
private void addPredictionLines(List<Line> lines) {
Map<Integer, List<PointValue>> values = new HashMap<>();
long endTime = getPredictionEndTime();
for (BgWatchData bwd : predictionsList) {
if (bwd.timestamp <= endTime) {
pointValues.add(new PointValue(fuzz(bwd.timestamp), (float) bwd.sgv));
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);
for (Map.Entry<Integer, List<PointValue>> 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);
return line;
lines.add(line);
}
}
public Line highValuesLine() {
Line highValuesLine = new Line(highValues);

View file

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