From dcf79c710c3919df64c7c720de5e57f190b51a8b Mon Sep 17 00:00:00 2001 From: Andrew Warrington Date: Tue, 28 Nov 2017 09:24:52 +0100 Subject: [PATCH] Update following testing! Bug fixes: - Detailed IOB always shown in older watch faces (fixed) - Cockpit: Loop graphic stays red once set (fixed) Design changes: - AAPSv2: Changed spacing of status and cob/time/iob lines to use layout_weight instead of padding (more dynamic) - Removed decimal point in delta strings when BG is in mg/dL to gain space so everything fits with all options switched on. This will affect older watch faces. - Changed to 1 decimal point in BGI to gain space. This will affect older watches as well. - Changed order of preferences to match screen layout more closely New features: - Exposed BGI as an individual item in dataMap & added to BaseWatchFace + AAPSv2 --- .../wearintegration/WatchUpdaterService.java | 40 ++-- .../androidaps/watchfaces/BaseWatchFace.java | 43 +++- .../androidaps/watchfaces/Cockpit.java | 6 + .../androidaps/watchfaces/Home2.java | 6 + .../main/res/layout/rect_activity_home_2.xml | 182 ++++++++++----- .../main/res/layout/round_activity_home_2.xml | 218 ++++++++++++------ wear/src/main/res/xml/preferences.xml | 50 ++-- 7 files changed, 375 insertions(+), 170 deletions(-) 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 9176ecf9cf..85bce9658e 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 @@ -251,8 +251,8 @@ public class WatchUpdaterService extends WearableListenerService implements dataMap.putDouble("timestamp", lastBG.date); if (glucoseStatus == null) { dataMap.putString("slopeArrow", ""); - dataMap.putString("delta", ""); - dataMap.putString("avgDelta", ""); + dataMap.putString("delta", "--"); + dataMap.putString("avgDelta", "--"); } else { dataMap.putString("slopeArrow", slopeArrow(glucoseStatus.delta)); dataMap.putString("delta", deltastring(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units)); @@ -274,11 +274,13 @@ public class WatchUpdaterService extends WearableListenerService implements deltastring += "-"; } + if (units.equals(Constants.MGDL)) { - deltastring += DecimalFormatter.to1Decimal(Math.abs(deltaMGDL)); + deltastring += DecimalFormatter.to0Decimal(Math.abs(deltaMGDL)); } else { deltastring += DecimalFormatter.to1Decimal(Math.abs(deltaMMOL)); } + return deltastring; } @@ -525,12 +527,18 @@ public class WatchUpdaterService extends WearableListenerService implements treatmentsInterface.updateTotalIOBTempBasals(); IobTotal basalIob = treatmentsInterface.getLastCalculationTempBasals().round(); - String iobTotal = DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob); + String iobSum = DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob); String iobDetail = "(" + DecimalFormatter.to2Decimal(bolusIob.iob) + "|" + DecimalFormatter.to2Decimal(basalIob.basaliob) + ")"; - String iobString = iobTotal + " " + iobDetail; //for generateStatusString() String cobString = generateCOBString(); String tempBasal = generateBasalString(treatmentsInterface); - String status = generateStatusString(iobString,tempBasal,bolusIob,basalIob); + + //bgi + String bgiString = ""; + Profile profile = MainApp.getConfigBuilder().getProfile(); + double bgi = -(bolusIob.activity + basalIob.activity) * 5 * profile.getIsf(); + bgiString = "" + ((bgi >= 0) ? "+" : "") + DecimalFormatter.to1Decimal(bgi); + + String status = generateStatusString(profile, tempBasal,iobSum, iobDetail, bgiString); //batteries int phoneBattery = getBatteryLevel(getApplicationContext()); @@ -543,7 +551,7 @@ public class WatchUpdaterService extends WearableListenerService implements PutDataMapRequest dataMapRequest = PutDataMapRequest.create(NEW_STATUS_PATH); //unique content dataMapRequest.getDataMap().putString("externalStatusString", status); - dataMapRequest.getDataMap().putString("iobTotal", iobTotal); + dataMapRequest.getDataMap().putString("iobSum", iobSum); dataMapRequest.getDataMap().putString("iobDetail", iobDetail); dataMapRequest.getDataMap().putBoolean("detailedIob", mPrefs.getBoolean("wear_detailediob", false)); dataMapRequest.getDataMap().putString("cob", cobString); @@ -551,6 +559,8 @@ public class WatchUpdaterService extends WearableListenerService implements dataMapRequest.getDataMap().putString("battery", "" + phoneBattery); dataMapRequest.getDataMap().putString("rigBattery", rigBattery); dataMapRequest.getDataMap().putString("openApsStatus", openApsStatus); + dataMapRequest.getDataMap().putString("bgi", bgiString); + dataMapRequest.getDataMap().putBoolean("showBgi", mPrefs.getBoolean("wear_showbgi", false)); dataMapRequest.getDataMap().putInt("batteryLevel", (phoneBattery >= 30) ? 1 : 0); PutDataRequest putDataRequest = dataMapRequest.asPutDataRequest(); Wearable.DataApi.putDataItem(googleApiClient, putDataRequest); @@ -576,11 +586,10 @@ public class WatchUpdaterService extends WearableListenerService implements } @NonNull - private String generateStatusString(String iobString, String tempBasal, IobTotal bolusIob, IobTotal basalIob) { + private String generateStatusString(Profile profile, String tempBasal, String iobSum, String iobDetail, String bgiString) { String status = ""; - Profile profile = MainApp.getConfigBuilder().getProfile(); if (profile == null) { status = MainApp.sResources.getString(R.string.noprofile); return status; @@ -595,14 +604,19 @@ public class WatchUpdaterService extends WearableListenerService implements lastLoopStatus = true; } + String iobString = ""; + if (mPrefs.getBoolean("wear_detailediob", false)) { + iobString = iobSum + " " + iobDetail; + } else { + iobString = iobSum + "U"; + } + status += tempBasal + " " + iobString; //add BGI if shown, otherwise return - if (!mPrefs.getBoolean("wear_showbgi", false)) { - return status; + if (mPrefs.getBoolean("wear_showbgi", false)) { + status += " " + bgiString; } - double bgi = -(bolusIob.activity + basalIob.activity) * 5 * profile.getIsf(); - status += " " + ((bgi >= 0) ? "+" : "") + DecimalFormatter.to2Decimal(bgi); return status; } 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 b7677a2783..17df5197d5 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BaseWatchFace.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/BaseWatchFace.java @@ -49,7 +49,7 @@ import lecho.lib.hellocharts.view.LineChartView; public abstract class BaseWatchFace extends WatchFace implements SharedPreferences.OnSharedPreferenceChangeListener { 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, mStatus, mBasalRate, mIOB1, mIOB2, mCOB1, mCOB2, mLoop, mDay, mMonth, isAAPSv2, mHighLight, mLowLight; + 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 RelativeLayout mRelativeLayout; public LinearLayout mLinearLayout, mLinearLayout2, mDate; @@ -84,19 +84,21 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen protected SharedPreferences sharedPrefs; public boolean detailedIOB = false; + public boolean showBGI = false; public String openApsStatus = "0"; public String externalStatusString = "no status"; public String sSgv = "---"; public String sDirection = "--"; public String sUploaderBattery = "--"; public String sRigBattery = "--"; - public String sDelta = "-"; - public String sAvgDelta = "-"; + public String sDelta = "--"; + public String sAvgDelta = "--"; public String sBasalRate = "-.--U/h"; public String sIOB1 = "IOB"; public String sIOB2 = "-.--"; public String sCOB1 = "Carb"; public String sCOB2 = "--g"; + public String sBgi = "--"; @Override public void onCreate() { @@ -145,11 +147,13 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen mIOB2 = (TextView) stub.findViewById(R.id.iobView); mCOB1 = (TextView) stub.findViewById(R.id.cob_text); mCOB2 = (TextView) stub.findViewById(R.id.cobView); + mBgi = (TextView) stub.findViewById(R.id.bgiView); mStatus = (TextView) stub.findViewById(R.id.externaltstatus); mBasalRate = (TextView) stub.findViewById(R.id.tmpBasal); mUploaderBattery = (TextView) stub.findViewById(R.id.uploader_battery); mRigBattery = (TextView) stub.findViewById(R.id.rig_battery); mDelta = (TextView) stub.findViewById(R.id.delta); + mAvgDelta = (TextView) stub.findViewById(R.id.avgdelta); isAAPSv2 = (TextView) stub.findViewById(R.id.AAPSv2); mHighLight = (TextView) stub.findViewById(R.id.highLight); mLowLight = (TextView) stub.findViewById(R.id.lowLight); @@ -220,8 +224,8 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen wakeLock.acquire(50); setDataFields(); - missedReadingAlert(); + mRelativeLayout.measure(specW, specH); mRelativeLayout.layout(0, 0, mRelativeLayout.getMeasuredWidth(), mRelativeLayout.getMeasuredHeight()); @@ -256,10 +260,12 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen sUploaderBattery = dataMap.getString("battery"); sRigBattery = dataMap.getString("rigBattery"); detailedIOB = dataMap.getBoolean("detailedIob"); - sIOB1 = dataMap.getString("iobTotal") + "U"; + sIOB1 = dataMap.getString("iobSum") + "U"; sIOB2 = dataMap.getString("iobDetail"); sCOB1 = "Carb"; sCOB2 = dataMap.getString("cob"); + sBgi = dataMap.getString("bgi"); + showBGI = dataMap.getBoolean("showBgi"); externalStatusString = dataMap.getString("externalStatusString"); openApsStatus = dataMap.getString("openApsStatus"); batteryLevel = dataMap.getInt("batteryLevel"); @@ -315,8 +321,14 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen } else { mDelta.setVisibility(View.GONE); } + } + + if (mAvgDelta != null) { if (sharedPrefs.getBoolean("showAvgDelta", true)) { - mDelta.append(" " + sAvgDelta); + mAvgDelta.setText(sAvgDelta); + mAvgDelta.setVisibility(View.VISIBLE); + } else { + mAvgDelta.setVisibility(View.GONE); } } @@ -420,6 +432,15 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen } } + if (mBgi != null) { + if (showBGI) { + mBgi.setText(sBgi); + mBgi.setVisibility(View.VISIBLE); + } else { + mBgi.setVisibility(View.GONE); + } + } + if (mStatus != null) { if (sharedPrefs.getBoolean("showExternalStatus", true)) { mStatus.setText(externalStatusString); @@ -436,14 +457,14 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen mLoop.setText(openApsStatus + "'"); if (Integer.valueOf(openApsStatus) > 14) { loopLevel = 0; - if (getCurrentWatchMode() == WatchMode.INTERACTIVE) { + //if (getCurrentWatchMode() == WatchMode.INTERACTIVE) { mLoop.setBackgroundResource(R.drawable.loop_red_25); - } + //} } else { loopLevel = 1; - if (getCurrentWatchMode() == WatchMode.INTERACTIVE) { + //if (getCurrentWatchMode() == WatchMode.INTERACTIVE) { mLoop.setBackgroundResource(R.drawable.loop_green_25); - } + //} } } else { mLoop.setText("-'"); @@ -516,7 +537,9 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferen if(layoutSet){ setDataFields(); } + invalidate(); } + protected abstract void setColorDark(); protected abstract void setColorBright(); protected abstract void setColorLowRes(); diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/Cockpit.java b/wear/src/main/java/info/nightscout/androidaps/watchfaces/Cockpit.java index 673fde8dfd..a275752cf9 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/Cockpit.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/Cockpit.java @@ -68,6 +68,12 @@ public class Cockpit extends BaseWatchFace { } } + if (loopLevel == 1) { + mLoop.setBackgroundResource(R.drawable.loop_green_25); + } else { + mLoop.setBackgroundResource(R.drawable.loop_red_25); + } + invalidate(); } diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/Home2.java b/wear/src/main/java/info/nightscout/androidaps/watchfaces/Home2.java index fd01675816..367b93a729 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/Home2.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/Home2.java @@ -102,7 +102,9 @@ public class Home2 extends BaseWatchFace { } mRigBattery.setTextColor(Color.BLACK); mDelta.setTextColor(Color.BLACK); + mAvgDelta.setTextColor(Color.BLACK); mBasalRate.setTextColor(Color.BLACK); + mBgi.setTextColor(Color.BLACK); if (loopLevel == 1) { mLoop.setBackgroundResource(R.drawable.loop_green_25); @@ -132,9 +134,11 @@ public class Home2 extends BaseWatchFace { mDirection.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor)); mTimestamp.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_Timestamp)); mDelta.setTextColor(Color.BLACK); + mAvgDelta.setTextColor(Color.BLACK); mRigBattery.setTextColor(Color.BLACK); mUploaderBattery.setTextColor(Color.BLACK); mBasalRate.setTextColor(Color.BLACK); + mBgi.setTextColor(Color.BLACK); mIOB1.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor)); mIOB2.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor)); mCOB1.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor)); @@ -196,7 +200,9 @@ public class Home2 extends BaseWatchFace { } mRigBattery.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor)); mDelta.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor)); + mAvgDelta.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor)); mBasalRate.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor)); + mBgi.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor)); if (loopLevel == 1) { mLoop.setBackgroundResource(R.drawable.loop_green_25); diff --git a/wear/src/main/res/layout/rect_activity_home_2.xml b/wear/src/main/res/layout/rect_activity_home_2.xml index eff7ee4e7e..88f55404bc 100644 --- a/wear/src/main/res/layout/rect_activity_home_2.xml +++ b/wear/src/main/res/layout/rect_activity_home_2.xml @@ -6,33 +6,28 @@ android:id="@+id/main_layout"> + android:textAlignment="center"> + android:textAlignment="center"> + android:layout_gravity="center" + android:gravity="center" + android:orientation="horizontal" + android:paddingEnd="2dp" + android:paddingStart="2dp" + android:textAlignment="center"> + + + + @@ -166,24 +200,34 @@ + android:weightSum="7"> + + @@ -191,6 +235,8 @@ android:id="@+id/cob_text" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_gravity="center" + android:gravity="center" android:text="Carb" android:textColor="#FFFFFF" android:textSize="10sp" @@ -200,6 +246,8 @@ android:id="@+id/cobView" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_gravity="center" + android:gravity="center" android:text="--g" android:textAlignment="center" android:textColor="#FFFFFF" @@ -208,13 +256,18 @@ + + @@ -235,7 +287,8 @@ android:id="@+id/day" android:layout_width="23dp" android:layout_height="wrap_content" - android:gravity="center_horizontal" + android:layout_gravity="center" + android:gravity="center" android:text="day" android:textAlignment="center" android:textColor="#FFFFFF" @@ -245,26 +298,35 @@ android:id="@+id/month" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:gravity="center_horizontal" + android:layout_gravity="center" + android:gravity="center" android:text="mth" android:textColor="#FFFFFF" android:textSize="10sp" /> + + + + + @@ -289,9 +359,9 @@ diff --git a/wear/src/main/res/layout/round_activity_home_2.xml b/wear/src/main/res/layout/round_activity_home_2.xml index 154812e645..837dc979e3 100644 --- a/wear/src/main/res/layout/round_activity_home_2.xml +++ b/wear/src/main/res/layout/round_activity_home_2.xml @@ -6,33 +6,35 @@ android:id="@+id/main_layout"> + android:weightSum="1.1"> + + + + android:orientation="horizontal" + android:textAlignment="center"> + android:paddingTop="-2dp" + android:text="---" + android:textColor="#FFFFFF" + android:textSize="38sp" /> + android:paddingEnd="4dp" + android:textAlignment="center"> + android:layout_gravity="center" + android:gravity="center" + android:orientation="horizontal" + android:paddingEnd="5dp" + android:paddingStart="5dp" + android:textAlignment="center"> + + + + @@ -166,24 +208,34 @@ + android:weightSum="7"> + + @@ -191,6 +243,8 @@ android:id="@+id/cob_text" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_gravity="center" + android:gravity="center" android:text="Carb" android:textColor="#FFFFFF" android:textSize="10sp" @@ -200,6 +254,8 @@ android:id="@+id/cobView" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_gravity="center" + android:gravity="center" android:text="--g" android:textAlignment="center" android:textColor="#FFFFFF" @@ -208,13 +264,18 @@ + + @@ -235,7 +295,8 @@ android:id="@+id/day" android:layout_width="23dp" android:layout_height="wrap_content" - android:gravity="center_horizontal" + android:layout_gravity="center" + android:gravity="center" android:text="day" android:textAlignment="center" android:textColor="#FFFFFF" @@ -245,26 +306,35 @@ android:id="@+id/month" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:gravity="center_horizontal" + android:layout_gravity="center" + android:gravity="center" android:text="mth" android:textColor="#FFFFFF" android:textSize="12sp" /> + + + + + @@ -289,10 +367,18 @@ + + + \ No newline at end of file diff --git a/wear/src/main/res/xml/preferences.xml b/wear/src/main/res/xml/preferences.xml index d02354c6dd..1846ce4939 100644 --- a/wear/src/main/res/xml/preferences.xml +++ b/wear/src/main/res/xml/preferences.xml @@ -43,10 +43,19 @@ + app:wear_iconOn="@drawable/settings_on"/> + + - - - - + app:wear_iconOn="@drawable/settings_on" /> + +