From c83f966d922e75e4e0fd73ce4d295fc33ea144e1 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Mon, 4 Dec 2017 18:40:13 +0100 Subject: [PATCH 1/3] wear timestamps long --- .../NSClientInternal/data/NSDeviceStatus.java | 2 +- .../wearintegration/WatchUpdaterService.java | 28 +++++++++++-------- .../androidaps/data/BgWatchData.java | 4 +-- .../androidaps/watchfaces/BIGChart.java | 8 +++--- .../androidaps/watchfaces/BaseWatchFace.java | 14 +++++----- .../androidaps/watchfaces/BgGraphBuilder.java | 16 +++++------ .../watchfaces/CircleWatchface.java | 12 ++++---- .../androidaps/watchfaces/NOChart.java | 4 +-- 8 files changed, 46 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java index 6ce5ab0440..315e9724ce 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSDeviceStatus.java @@ -308,7 +308,7 @@ public class NSDeviceStatus { return Html.fromHtml(string.toString()); } - public static double getOpenApsTimestamp() { + public static long getOpenApsTimestamp() { if (deviceStatusOpenAPSData.clockSuggested != 0) { return deviceStatusOpenAPSData.clockSuggested; 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 c6caca20a2..cbf2fc9ae2 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 @@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; +import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; @@ -122,11 +123,6 @@ public class WatchUpdaterService extends WearableListenerService implements @Override public int onStartCommand(Intent intent, int flags, int startId) { - double timestamp = 0; - if (intent != null) { - timestamp = intent.getDoubleExtra("timestamp", 0); - } - String action = null; if (intent != null) { action = intent.getAction(); @@ -247,7 +243,7 @@ public class WatchUpdaterService extends WearableListenerService implements DataMap dataMap = new DataMap(); dataMap.putString("sgvString", lastBG.valueToUnitsToString(units)); - dataMap.putDouble("timestamp", lastBG.date); + dataMap.putLong("timestamp", lastBG.date); if (glucoseStatus == null) { dataMap.putString("slopeArrow", ""); dataMap.putString("delta", "--"); @@ -481,7 +477,7 @@ public class WatchUpdaterService extends WearableListenerService implements if (googleApiClient.isConnected()) { PutDataMapRequest dataMapRequest = PutDataMapRequest.create(OPEN_SETTINGS_PATH); //unique content - dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis()); + dataMapRequest.getDataMap().putLong("timestamp", System.currentTimeMillis()); dataMapRequest.getDataMap().putString("openSettings", "openSettings"); PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); @@ -494,7 +490,7 @@ public class WatchUpdaterService extends WearableListenerService implements if (googleApiClient.isConnected()) { PutDataMapRequest dataMapRequest = PutDataMapRequest.create(BOLUS_PROGRESS_PATH); //unique content - dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis()); + dataMapRequest.getDataMap().putLong("timestamp", System.currentTimeMillis()); dataMapRequest.getDataMap().putString("bolusProgress", "bolusProgress"); dataMapRequest.getDataMap().putString("progressstatus", status); dataMapRequest.getDataMap().putInt("progresspercent", progresspercent); @@ -509,7 +505,7 @@ public class WatchUpdaterService extends WearableListenerService implements if (googleApiClient.isConnected()) { PutDataMapRequest dataMapRequest = PutDataMapRequest.create(ACTION_CONFIRMATION_REQUEST_PATH); //unique content - dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis()); + dataMapRequest.getDataMap().putLong("timestamp", System.currentTimeMillis()); dataMapRequest.getDataMap().putString("actionConfirmationRequest", "actionConfirmationRequest"); dataMapRequest.getDataMap().putString("title", title); dataMapRequest.getDataMap().putString("message", message); @@ -551,8 +547,16 @@ public class WatchUpdaterService extends WearableListenerService implements int phoneBattery = getBatteryLevel(getApplicationContext()); String rigBattery = NSDeviceStatus.getInstance().getUploaderStatus().trim(); + + long openApsStatus = -1; //OpenAPS status - Double openApsStatus = NSDeviceStatus.getOpenApsTimestamp(); + if(Config.APS){ + //we are AndroidAPS + openApsStatus = LoopPlugin.lastRun.lastEnact != null && LoopPlugin.lastRun.lastEnact.getTime() != 0 ? LoopPlugin.lastRun.lastEnact.getTime(): -1; + } else { + //NSClient or remote + openApsStatus = NSDeviceStatus.getOpenApsTimestamp(); + } PutDataMapRequest dataMapRequest = PutDataMapRequest.create(NEW_STATUS_PATH); //unique content @@ -564,7 +568,7 @@ public class WatchUpdaterService extends WearableListenerService implements dataMapRequest.getDataMap().putString("tempBasal", tempBasal); dataMapRequest.getDataMap().putString("battery", "" + phoneBattery); dataMapRequest.getDataMap().putString("rigBattery", rigBattery); - dataMapRequest.getDataMap().putDouble("openApsStatus", openApsStatus); + dataMapRequest.getDataMap().putLong("openApsStatus", openApsStatus); dataMapRequest.getDataMap().putString("bgi", bgiString); dataMapRequest.getDataMap().putBoolean("showBgi", mPrefs.getBoolean("wear_showbgi", false)); dataMapRequest.getDataMap().putInt("batteryLevel", (phoneBattery >= 30) ? 1 : 0); @@ -582,7 +586,7 @@ public class WatchUpdaterService extends WearableListenerService implements PutDataMapRequest dataMapRequest = PutDataMapRequest.create(NEW_PREFERENCES_PATH); //unique content - dataMapRequest.getDataMap().putDouble("timestamp", System.currentTimeMillis()); + dataMapRequest.getDataMap().putLong("timestamp", System.currentTimeMillis()); dataMapRequest.getDataMap().putBoolean("wearcontrol", wearcontrol); PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); 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 48d106a116..54eb597f1a 100644 --- a/wear/src/main/java/info/nightscout/androidaps/data/BgWatchData.java +++ b/wear/src/main/java/info/nightscout/androidaps/data/BgWatchData.java @@ -7,9 +7,9 @@ public class BgWatchData implements Comparable{ public double sgv; public double high; public double low; - public double timestamp; + public long timestamp; - public BgWatchData(double aSgv, double aHigh, double aLow, double aTimestamp) { + public BgWatchData(double aSgv, double aHigh, double aLow, long aTimestamp) { this.sgv = aSgv; this.high = aHigh; this.low = aLow; 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 25fe619b2a..a9700c6092 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BIGChart.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/BIGChart.java @@ -69,7 +69,7 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre public boolean layoutSet = false; public BgGraphBuilder bgGraphBuilder; public LineChartView chart; - public double datetime; + public long datetime; public ArrayList bgDataList = new ArrayList<>(); public ArrayList tempWatchDataList = new ArrayList<>(); public ArrayList basalWatchDataList = new ArrayList<>(); @@ -281,7 +281,7 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre wakeLock.acquire(50); sgvLevel = dataMap.getLong("sgvLevel"); batteryLevel = dataMap.getInt("batteryLevel"); - datetime = dataMap.getDouble("timestamp"); + datetime = dataMap.getLong("timestamp"); rawString = dataMap.getString("rawString"); sgvString = dataMap.getString("sgvString"); batteryString = dataMap.getString("battery"); @@ -604,14 +604,14 @@ public class BIGChart extends WatchFace implements SharedPreferences.OnSharedPre double sgv = entry.getDouble("sgvDouble"); double high = entry.getDouble("high"); double low = entry.getDouble("low"); - double timestamp = entry.getDouble("timestamp"); + long timestamp = entry.getLong("timestamp"); bgDataList.add(new BgWatchData(sgv, high, low, timestamp)); } } else { double sgv = dataMap.getDouble("sgvDouble"); double high = dataMap.getDouble("high"); double low = dataMap.getDouble("low"); - double timestamp = dataMap.getDouble("timestamp"); + long timestamp = dataMap.getLong("timestamp"); final int size = bgDataList.size(); if (size > 0) { 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 a442ed1c12..0f978c4ff4 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BaseWatchFace.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/BaseWatchFace.java @@ -50,7 +50,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen public final static IntentFilter INTENT_FILTER; public static final long[] vibratePattern = {0,400,300,400,300,400}; public TextView mTime, mSgv, mDirection, mTimestamp, mUploaderBattery, mRigBattery, mDelta, mAvgDelta, mStatus, mBasalRate, mIOB1, mIOB2, mCOB1, mCOB2, mBgi, mLoop, mDay, mMonth, isAAPSv2, mHighLight, mLowLight; - public double datetime; + public long datetime; public RelativeLayout mRelativeLayout; public LinearLayout mLinearLayout, mLinearLayout2, mDate; public long sgvLevel = 0; @@ -85,7 +85,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen public boolean detailedIOB = false; public boolean showBGI = false; - public Double openApsStatus; + public long openApsStatus; public String externalStatusString = "no status"; public String sSgv = "---"; public String sDirection = "--"; @@ -241,7 +241,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen DataMap dataMap = DataMap.fromBundle(bundle); wakeLock.acquire(50); sgvLevel = dataMap.getLong("sgvLevel"); - datetime = dataMap.getDouble("timestamp"); + datetime = dataMap.getLong("timestamp"); sSgv = dataMap.getString("sgvString"); sDirection = dataMap.getString("slopeArrow"); sDelta = dataMap.getString("delta"); @@ -268,7 +268,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen showBGI = dataMap.getBoolean("showBgi"); externalStatusString = dataMap.getString("externalStatusString"); batteryLevel = dataMap.getInt("batteryLevel"); - openApsStatus = dataMap.getDouble("openApsStatus"); + openApsStatus = dataMap.getLong("openApsStatus"); } setDataFields(); @@ -453,7 +453,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen if (mLoop != null) { if (sharedPrefs.getBoolean("showExternalStatus", true)) { mLoop.setVisibility(View.VISIBLE); - if (openApsStatus != null) { + if (openApsStatus != -1) { int mins = (int) ((System.currentTimeMillis() - openApsStatus) / 1000 / 60); mLoop.setText(mins + "'"); if (mins > 14) { @@ -557,14 +557,14 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen double sgv = entry.getDouble("sgvDouble"); double high = entry.getDouble("high"); double low = entry.getDouble("low"); - double timestamp = entry.getDouble("timestamp"); + long timestamp = entry.getLong("timestamp"); bgDataList.add(new BgWatchData(sgv, high, low, timestamp)); } } else { double sgv = dataMap.getDouble("sgvDouble"); double high = dataMap.getDouble("high"); double low = dataMap.getDouble("low"); - double timestamp = dataMap.getDouble("timestamp"); + long timestamp = dataMap.getLong("timestamp"); final int size = bgDataList.size(); if (size > 0) { 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 28e470adab..2adf432fa3 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BgGraphBuilder.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/BgGraphBuilder.java @@ -30,8 +30,8 @@ public class BgGraphBuilder { private ArrayList basalWatchDataList; public List tempWatchDataList; private int timespan; - public double end_time; - public double start_time; + public long end_time; + public long start_time; public double fuzzyTimeDenom = (1000 * 60 * 1); public Context context; public double highMark; @@ -47,7 +47,7 @@ public class BgGraphBuilder { public int basalBackgroundColor; public boolean singleLine = false; - private double endHour; + private long endHour; private List inRangeValues = new ArrayList(); private List highValues = new ArrayList(); private List lowValues = new ArrayList(); @@ -316,8 +316,8 @@ public class BgGraphBuilder { GregorianCalendar today = new GregorianCalendar(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)); SimpleDateFormat timeFormat = new SimpleDateFormat(is24? "HH" : "h a"); timeFormat.setTimeZone(TimeZone.getDefault()); - double start_hour = today.getTime().getTime(); - double timeNow = System.currentTimeMillis(); + long start_hour = today.getTime().getTime(); + long timeNow = System.currentTimeMillis(); for (int l = 0; l <= 24; l++) { if ((start_hour + (60000 * 60 * (l))) < timeNow) { if ((start_hour + (60000 * 60 * (l + 1))) >= timeNow) { @@ -332,7 +332,7 @@ public class BgGraphBuilder { //Add whole hours endTime the axis (as long as they are more than 15 mins away from the current time) for (int l = 0; l <= 24; l++) { - double timestamp = endHour - (60000 * 60 * l); + long timestamp = endHour - (60000 * 60 * l); if((timestamp - timeNow < 0) && (timestamp > start_time)) { if(Math.abs(timestamp - timeNow) > (1000 * 60 * 8 * timespan)){ xAxisValues.add(new AxisValue(fuzz(timestamp), (timeFormat.format(timestamp)).toCharArray())); @@ -350,7 +350,7 @@ public class BgGraphBuilder { return xAxis; } - public float fuzz(double value) { - return (float) Math.round(value / fuzzyTimeDenom); + public float fuzz(long value) { + return (float) Math.round(value / fuzzyTimeDenom); } } 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 73930d8365..7c62ba6b0f 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/CircleWatchface.java @@ -73,7 +73,7 @@ public class CircleWatchface extends WatchFace implements SharedPreferences.OnSh private int batteryLevel = 0; - private double datetime = 0; + private long datetime = 0; private String direction = ""; private String delta = ""; private String avgDelta = ""; @@ -433,11 +433,11 @@ public class CircleWatchface extends WatchFace implements SharedPreferences.OnSh } - private synchronized double getDatetime() { + private synchronized long getDatetime() { return datetime; } - private synchronized void setDatetime(double datetime) { + private synchronized void setDatetime(long datetime) { this.datetime = datetime; } @@ -534,7 +534,7 @@ public class CircleWatchface extends WatchFace implements SharedPreferences.OnSh Log.d("CircleWatchface", "sgv string : " + getSgvString()); setDelta(dataMap.getString("delta")); setAvgDelta(dataMap.getString("avgDelta")); - setDatetime(dataMap.getDouble("timestamp")); + setDatetime(dataMap.getLong("timestamp")); addToWatchSet(dataMap); @@ -576,7 +576,7 @@ public class CircleWatchface extends WatchFace implements SharedPreferences.OnSh double sgv = dataMap.getDouble("sgvDouble"); double high = dataMap.getDouble("high"); double low = dataMap.getDouble("low"); - double timestamp = dataMap.getDouble("timestamp"); + long timestamp = dataMap.getLong("timestamp"); bgDataList.add(new BgWatchData(sgv, high, low, timestamp)); } else if (!sharedPrefs.getBoolean("animation", false)) { // don't load history at once if animations are set (less resource consumption) @@ -586,7 +586,7 @@ public class CircleWatchface extends WatchFace implements SharedPreferences.OnSh double sgv = entry.getDouble("sgvDouble"); double high = entry.getDouble("high"); double low = entry.getDouble("low"); - double timestamp = entry.getDouble("timestamp"); + long timestamp = entry.getLong("timestamp"); bgDataList.add(new BgWatchData(sgv, high, low, timestamp)); } } else diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/NOChart.java b/wear/src/main/java/info/nightscout/androidaps/watchfaces/NOChart.java index 9bb452c480..328f101497 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/NOChart.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/NOChart.java @@ -59,7 +59,7 @@ public class NOChart extends WatchFace implements SharedPreferences.OnSharedPref public int ageLevel = 1; public boolean lowResMode = false; public boolean layoutSet = false; - public double datetime; + public long datetime; public ArrayList bgDataList = new ArrayList<>(); public ArrayList tempWatchDataList = new ArrayList<>(); public ArrayList basalWatchDataList = new ArrayList<>(); @@ -252,7 +252,7 @@ public class NOChart extends WatchFace implements SharedPreferences.OnSharedPref wakeLock.acquire(50); sgvLevel = dataMap.getLong("sgvLevel"); batteryLevel = dataMap.getInt("batteryLevel"); - datetime = dataMap.getDouble("timestamp"); + datetime = dataMap.getLong("timestamp"); sgvString = dataMap.getString("sgvString"); mSgv.setText(dataMap.getString("sgvString")); From 2f235385e0cae1becbfe307bf3dc0fb28c8b99fd Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Mon, 4 Dec 2017 20:04:58 +0100 Subject: [PATCH 2/3] fix NPE --- .../plugins/Wear/wearintegration/WatchUpdaterService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 cbf2fc9ae2..7acdd15d72 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 @@ -552,7 +552,7 @@ public class WatchUpdaterService extends WearableListenerService implements //OpenAPS status if(Config.APS){ //we are AndroidAPS - openApsStatus = LoopPlugin.lastRun.lastEnact != null && LoopPlugin.lastRun.lastEnact.getTime() != 0 ? LoopPlugin.lastRun.lastEnact.getTime(): -1; + openApsStatus = LoopPlugin.lastRun != null && LoopPlugin.lastRun.lastEnact != null && LoopPlugin.lastRun.lastEnact.getTime() != 0 ? LoopPlugin.lastRun.lastEnact.getTime(): -1; } else { //NSClient or remote openApsStatus = NSDeviceStatus.getOpenApsTimestamp(); From 0701dc4a52211f457d7855dbb6ed5bc500181db4 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Mon, 4 Dec 2017 20:08:57 +0100 Subject: [PATCH 3/3] make chart zoomable again --- .../info/nightscout/androidaps/watchfaces/BaseWatchFace.java | 1 + 1 file changed, 1 insertion(+) 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 0f978c4ff4..cb82daf3eb 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BaseWatchFace.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/BaseWatchFace.java @@ -213,6 +213,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen @Override protected void onDraw(Canvas canvas) { if (layoutSet) { + setupCharts(); this.mRelativeLayout.draw(canvas); Log.d("onDraw", "draw"); }