diff --git a/wear/src/main/java/info/nightscout/androidaps/data/RawDisplayData.java b/wear/src/main/java/info/nightscout/androidaps/data/RawDisplayData.java
index 0eeead26bb..6560598227 100644
--- a/wear/src/main/java/info/nightscout/androidaps/data/RawDisplayData.java
+++ b/wear/src/main/java/info/nightscout/androidaps/data/RawDisplayData.java
@@ -135,7 +135,7 @@ public class RawDisplayData {
}
private void updateData(DataMap dataMap) {
- wearUtil.getWakeLock("readingPrefs", 50);
+ // wearUtil.getWakeLock("readingPrefs", 50);
sgvLevel = dataMap.getLong("sgvLevel");
datetime = dataMap.getLong("timestamp");
sSgv = dataMap.getString("sgvString");
@@ -156,7 +156,7 @@ public class RawDisplayData {
}
private void updateStatus(DataMap dataMap) {
- wearUtil.getWakeLock("readingPrefs", 50);
+ // wearUtil.getWakeLock("readingPrefs", 50);
sBasalRate = dataMap.getString("currentBasal");
sUploaderBattery = dataMap.getString("battery");
sRigBattery = dataMap.getString("rigBattery");
@@ -183,7 +183,7 @@ public class RawDisplayData {
}
private void updateBasals(DataMap dataMap) {
- wearUtil.getWakeLock("readingPrefs", 500);
+ // wearUtil.getWakeLock("readingPrefs", 500);
loadBasalsAndTemps(dataMap);
}
@@ -194,7 +194,7 @@ public class RawDisplayData {
for (DataMap temp : temps) {
TempWatchData twd = new TempWatchData();
twd.startTime = temp.getLong("starttime");
- twd.startBasal = temp.getDouble("startBasal");
+ twd.startBasal = temp.getDouble("startBasal");
twd.endTime = temp.getLong("endtime");
twd.endBasal = temp.getDouble("endbasal");
twd.amount = temp.getDouble("amount");
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 a1b195e29f..e79ef2c332 100644
--- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BaseWatchFace.java
+++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/BaseWatchFace.java
@@ -54,12 +54,15 @@ import lecho.lib.hellocharts.view.LineChartView;
* Refactored by dlvoy on 2019-11-2019
*/
+
+
public abstract class BaseWatchFace extends WatchFace implements SharedPreferences.OnSharedPreferenceChangeListener {
@Inject WearUtil wearUtil;
@Inject Persistence persistence;
public final static IntentFilter INTENT_FILTER;
+ public final static String TAG = "ASTAG-perf";
static {
INTENT_FILTER = new IntentFilter();
@@ -68,6 +71,9 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
INTENT_FILTER.addAction(Intent.ACTION_TIME_CHANGED);
}
+ String mLastSvg = "";
+ String mLastDirection = "";
+
public final Point displaySize = new Point();
public TextView mTime, mHour, mMinute, mTimePeriod, mSgv, mDirection, mTimestamp, mUploaderBattery, mRigBattery, mDelta, mAvgDelta, mStatus, mBasalRate, mIOB1, mIOB2, mCOB1, mCOB2, mBgi, mLoop, mDay, mDayName, mMonth, isAAPSv2, mHighLight, mLowLight;
public TextView mSimpleSvg, mSimpleDirection, mSimpleTime;
@@ -104,12 +110,23 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
private MessageReceiver messageReceiver;
private BroadcastReceiver batteryReceiver;
protected boolean isCharging = false;
+ int colorDarkHigh;
+ int colorDarkMid;
+ int colorDarkLow;
+ java.text.DateFormat timeFormat;
@Override
public void onCreate() {
+ Log.i(TAG, "onCreate: ");
// Not derived from DaggerService, do injection here
AndroidInjection.inject(this);
super.onCreate();
+
+ colorDarkHigh = ContextCompat.getColor(getApplicationContext(), R.color.dark_highColor);
+ colorDarkMid = ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor);
+ colorDarkLow = ContextCompat.getColor(getApplicationContext(), R.color.dark_lowColor);
+ timeFormat = DateFormat.getTimeFormat(BaseWatchFace.this);
+
rawData = new RawDisplayData(wearUtil);
Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
display.getSize(displaySize);
@@ -130,13 +147,17 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
}
private void setupBatteryReceiver() {
- if (sharedPrefs.getString("simplify_ui", "off") == "charching" && batteryReceiver == null) {
+ String setting = sharedPrefs.getString("simplify_ui", "off");
+ Log.i(TAG, "setupBatteryReceiver: " + setting);
+ if (setting.equals("charging") || setting.equals("ambient_charging") && batteryReceiver == null) {
+ Log.i(TAG, "setupBatteryReceiver: DONE");
IntentFilter intentBatteryFilter = new IntentFilter();
intentBatteryFilter.addAction(BatteryManager.ACTION_CHARGING);
intentBatteryFilter.addAction(BatteryManager.ACTION_DISCHARGING);
batteryReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
+ Log.i(TAG, "Battery BroadcastReceiver.onReceive: ");
setDataFields();
invalidate();
}
@@ -147,6 +168,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
@Override
protected void onLayout(WatchShape shape, Rect screenBounds, WindowInsets screenInsets) {
+ Log.i(TAG, "onLayout: ");
super.onLayout(shape, screenBounds, screenInsets);
layoutView.onApplyWindowInsets(screenInsets);
bIsRound = screenInsets.isRound();
@@ -160,6 +182,10 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
localBroadcastManager = LocalBroadcastManager.getInstance(this);
localBroadcastManager.registerReceiver(messageReceiver, messageFilter);
+ final int colorDarkHigh = ContextCompat.getColor(getApplicationContext(), R.color.dark_highColor);
+ final int colorDarkMid = ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor);
+ final int colorDarkDark = ContextCompat.getColor(getApplicationContext(), R.color.dark_lowColor);
+
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
@Override
public void onLayoutInflated(WatchViewStub stub) {
@@ -249,8 +275,15 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
super.onDestroy();
}
+ @Override
+ protected long getInteractiveModeUpdateRate() {
+ // Only call onTimeChanged every 1
+ return 60 * 1000L;
+ }
+
@Override
protected void onDraw(Canvas canvas) {
+ Log.i(TAG, "onDraw: ");
if (layoutSet) {
setupCharts();
@@ -267,8 +300,10 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
@Override
protected void onTimeChanged(WatchFaceTime oldTime, WatchFaceTime newTime) {
+ Log.i(TAG, "onTimeChanged: ");
if (layoutSet && (newTime.hasHourChanged(oldTime) || newTime.hasMinuteChanged(oldTime))) {
- wakeLock.acquire(50);
+ Log.i(TAG, "onTimeChanged: time changed");
+ // wakeLock.acquire(50);
setDataFields();
setColor();
@@ -281,7 +316,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
} else {
mRelativeLayout.layout(0, 0, displaySize.x, displaySize.y);
}
- invalidate();
+ // invalidate();
}
}
@@ -305,10 +340,10 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
public void setDataFields() {
- setDateAndTime();
if (setDataFieldsSimpleUi()) {
return;
}
+ setDateAndTime();
if (mSgv != null) {
if (sharedPrefs.getBoolean("showBG", true)) {
mSgv.setText(rawData.sSgv);
@@ -500,20 +535,21 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
} else {
mSimpleSvg.setPaintFlags(mSimpleSvg.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
}
+
if (rawData.sgvLevel == 1) {
- mSimpleSvg.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_highColor));
- mSimpleDirection.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_highColor));
+ mSimpleSvg.setTextColor(colorDarkHigh);
+ mSimpleDirection.setTextColor(colorDarkHigh);
} else if (rawData.sgvLevel == 0) {
- mSimpleSvg.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
- mSimpleDirection.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor));
+ mSimpleSvg.setTextColor(colorDarkMid);
+ mSimpleDirection.setTextColor(colorDarkMid);
} else if (rawData.sgvLevel == -1) {
- mSimpleSvg.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_lowColor));
- mSimpleDirection.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_lowColor));
+ mSimpleSvg.setTextColor(colorDarkLow);
+ mSimpleDirection.setTextColor(colorDarkLow);
}
mSimpleDirection.setText(rawData.sDirection+"\uFE0E");
- final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(BaseWatchFace.this);
+
mSimpleTime.setText(timeFormat.format(System.currentTimeMillis()));
return true;
}
@@ -601,6 +637,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
}
protected void onWatchModeChanged(WatchMode watchMode) {
+ Log.i(TAG, "onWatchModeChanged: " + watchMode);
setDataFields();
if (lowResMode ^ isLowRes(watchMode)) { //if there was a change in lowResMode
lowResMode = isLowRes(watchMode);
@@ -620,10 +657,10 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
if (simplify.equals("off")) {
return false;
}
- if (simplify.equals("ambient") && getCurrentWatchMode() == WatchMode.AMBIENT) {
+ if ((simplify.equals("ambient") || simplify.equals("ambient_charging")) && getCurrentWatchMode() == WatchMode.AMBIENT) {
return true;
}
- if (simplify.equals("charging") && isCharging()) {
+ if ((simplify.equals("charging") || simplify.equals("ambient_charging")) && isCharging()) {
return true;
}
return false;
@@ -631,6 +668,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+ Log.i(TAG, "onSharedPreferenceChanged: ");
setupBatteryReceiver();
if ("delta_granularity".equals(key)) {
ListenerService.requestData(this);
@@ -677,6 +715,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
public class MessageReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
+ Log.i(TAG, "Data MessageReceiver.onReceive: ");
if (layoutSet) {
final DataMap dataMap = rawData.updateDataFromMessage(intent, wakeLock);
@@ -685,15 +724,15 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
setupCharts();
}
rawData.updateStatusFromMessage(intent, wakeLock);
+ rawData.updateBasalsFromMessage(intent, wakeLock);
+ }
+ if (!needUpdate()) {
+ return;
}
setDataFields();
setColor();
- if (layoutSet) {
- rawData.updateBasalsFromMessage(intent, wakeLock);
- }
-
mRelativeLayout.measure(specW, specH);
if (forceSquareCanvas) {
mRelativeLayout.layout(0, 0, displaySize.x, displaySize.x); //force a square for Steampunk watch face.
@@ -704,4 +743,13 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
}
}
+ private boolean needUpdate() {
+ if (isSimpleUi() && mLastSvg.equals(rawData.sSgv) && mLastDirection.equals(rawData.sDirection)) {
+ return false;
+ }
+ mLastSvg = rawData.sSgv;
+ mLastDirection = rawData.sDirection;
+ return true;
+ }
+
}
diff --git a/wear/src/main/res/values/arrays.xml b/wear/src/main/res/values/arrays.xml
index 75f5479ef3..6a753edec5 100644
--- a/wear/src/main/res/values/arrays.xml
+++ b/wear/src/main/res/values/arrays.xml
@@ -69,12 +69,14 @@
- Off
- During Charging
- Always On Mode
+ - Always On and Charging
- off
- charging
- ambient
+ - ambient_charging