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..024f72f676 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); + PowerManager.WakeLock wl = wearUtil.getWakeLock("readingPrefs", 50); sgvLevel = dataMap.getLong("sgvLevel"); datetime = dataMap.getLong("timestamp"); sSgv = dataMap.getString("sgvString"); @@ -143,6 +143,7 @@ public class RawDisplayData { sDelta = dataMap.getString("delta"); sAvgDelta = dataMap.getString("avgDelta"); sUnits = dataMap.getString("glucoseUnits"); + wearUtil.releaseWakeLock(wl); } public DataMap updateStatusFromMessage(Intent intent, PowerManager.WakeLock wakeLock) { @@ -156,7 +157,7 @@ public class RawDisplayData { } private void updateStatus(DataMap dataMap) { - wearUtil.getWakeLock("readingPrefs", 50); + PowerManager.WakeLock wl = wearUtil.getWakeLock("readingPrefs", 50); sBasalRate = dataMap.getString("currentBasal"); sUploaderBattery = dataMap.getString("battery"); sRigBattery = dataMap.getString("rigBattery"); @@ -170,6 +171,7 @@ public class RawDisplayData { externalStatusString = dataMap.getString("externalStatusString"); batteryLevel = dataMap.getInt("batteryLevel"); openApsStatus = dataMap.getLong("openApsStatus"); + wearUtil.releaseWakeLock(wl); } public DataMap updateBasalsFromMessage(Intent intent, PowerManager.WakeLock wakeLock) { @@ -183,8 +185,9 @@ public class RawDisplayData { } private void updateBasals(DataMap dataMap) { - wearUtil.getWakeLock("readingPrefs", 500); + PowerManager.WakeLock wl = wearUtil.getWakeLock("readingPrefs", 500); loadBasalsAndTemps(dataMap); + wearUtil.releaseWakeLock(wl); } private void loadBasalsAndTemps(DataMap dataMap) { @@ -194,7 +197,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 0500786802..b35aee5ade 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/BaseWatchFace.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/BaseWatchFace.java @@ -5,11 +5,13 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; +import android.content.res.Resources; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Point; import android.graphics.Rect; +import android.graphics.Typeface; import android.os.BatteryManager; import android.os.PowerManager; import android.os.Vibrator; @@ -37,6 +39,7 @@ import com.ustwo.clockwise.wearable.WatchFace; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.Locale; import javax.inject.Inject; @@ -70,13 +73,11 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc 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; public ImageView mGlucoseDial, mDeltaGauge, mHourHand, mMinuteHand; - public View mSimpleUi; public RelativeLayout mRelativeLayout; public LinearLayout mLinearLayout, mLinearLayout2, mDate, mChartTap, mMainMenuTap; public int ageLevel = 1; - public int loopLevel = 1; + public int loopLevel = -1; public int highColor = Color.YELLOW; public int lowColor = Color.RED; public int midColor = Color.WHITE; @@ -96,20 +97,32 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc // related endTime manual layout public View layoutView; public int specW, specH; - public boolean forceSquareCanvas = false; //set to true by the Steampunk watch face. + public boolean forceSquareCanvas = false; // Set to true by the Steampunk watch face. public String sMinute = "0"; public String sHour = "0"; protected SharedPreferences sharedPrefs; private LocalBroadcastManager localBroadcastManager; private MessageReceiver messageReceiver; private BroadcastReceiver batteryReceiver; - protected boolean isCharging = false; + private int colorDarkHigh, colorDarkMid, colorDarkLow; + private java.text.DateFormat timeFormat; + private SimpleDateFormat sdfDay, sdfMonth, sdfHour, sdfPeriod, sdfDayName, sdfMinute; + private Paint mBackgroundPaint, mTimePaint, mSvgPaint, mDirectionPaint; + private Date mDateTime; + private String mLastSvg = "", mLastDirection = ""; + private float mYOffset = 0; + private Intent mBatteryStatus; @Override public void 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); + rawData = new RawDisplayData(wearUtil); Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); display.getSize(displaySize); @@ -127,10 +140,15 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc persistence.turnOff(); setupBatteryReceiver(); + initFormats(); + setupSimpleUi(); } private void setupBatteryReceiver() { - if (sharedPrefs.getBoolean("simplify_ui_charging", false) && batteryReceiver == null) { + IntentFilter iFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); + mBatteryStatus = this.registerReceiver(null, iFilter); + String setting = sharedPrefs.getString("simplify_ui", "off"); + if (setting.equals("charging") || setting.equals("ambient_charging") && batteryReceiver == null) { IntentFilter intentBatteryFilter = new IntentFilter(); intentBatteryFilter.addAction(BatteryManager.ACTION_CHARGING); intentBatteryFilter.addAction(BatteryManager.ACTION_DISCHARGING); @@ -145,6 +163,48 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc } } + private void initFormats() { + Locale locale = Locale.getDefault(); + timeFormat = DateFormat.getTimeFormat(BaseWatchFace.this); + sdfMinute = new SimpleDateFormat("mm", locale); + sdfHour = DateFormat.is24HourFormat(this) ? new SimpleDateFormat("HH", locale) : new SimpleDateFormat("hh", locale); + sdfPeriod = new SimpleDateFormat("a", locale); + sdfDay = new SimpleDateFormat("dd", locale); + sdfDayName = new SimpleDateFormat("E", locale); + sdfMonth = new SimpleDateFormat("MMM", locale); + } + + private void setupSimpleUi() { + mDateTime = new Date(); + + int black = ContextCompat.getColor(getApplicationContext(), R.color.black); + mBackgroundPaint = new Paint(); + mBackgroundPaint.setColor(black); + + final Typeface NORMAL_TYPEFACE = Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL); + final Typeface BOLD_TYPEFACE = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD); + int white = ContextCompat.getColor(getApplicationContext(), R.color.white); + + Resources resources = this.getResources(); + float textSizeSvg = resources.getDimension(R.dimen.simple_ui_svg_text_size); + float textSizeDirection = resources.getDimension(R.dimen.simple_ui_direction_text_size); + float textSizeTime = resources.getDimension(R.dimen.simple_ui_time_text_size); + mYOffset = resources.getDimension(R.dimen.simple_ui_y_offset); + + mSvgPaint = createTextPaint(NORMAL_TYPEFACE, white, textSizeSvg); + mDirectionPaint = createTextPaint(BOLD_TYPEFACE, white, textSizeDirection); + mTimePaint = createTextPaint(NORMAL_TYPEFACE, white, textSizeTime); + } + + private Paint createTextPaint(Typeface typeface, int colour, float textSize) { + Paint paint = new Paint(); + paint.setColor(colour); + paint.setTypeface(typeface); + paint.setAntiAlias(true); + paint.setTextSize(textSize); + return paint; + } + @Override protected void onLayout(WatchShape shape, Rect screenBounds, WindowInsets screenInsets) { super.onLayout(shape, screenBounds, screenInsets); @@ -153,71 +213,63 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc } public void performViewSetup() { - final WatchViewStub stub = layoutView.findViewById(R.id.watch_view_stub); + final WatchViewStub layoutStub = layoutView.findViewById(R.id.watch_view_stub); IntentFilter messageFilter = new IntentFilter(Intent.ACTION_SEND); messageReceiver = new MessageReceiver(); localBroadcastManager = LocalBroadcastManager.getInstance(this); localBroadcastManager.registerReceiver(messageReceiver, messageFilter); - stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() { - @Override - public void onLayoutInflated(WatchViewStub stub) { - mTime = stub.findViewById(R.id.watch_time); - mHour = stub.findViewById(R.id.hour); - mMinute = stub.findViewById(R.id.minute); - mTimePeriod = stub.findViewById(R.id.timePeriod); - mDay = stub.findViewById(R.id.day); - mDayName = stub.findViewById(R.id.dayname); - mMonth = stub.findViewById(R.id.month); - mDate = stub.findViewById(R.id.date_time); - mLoop = stub.findViewById(R.id.loop); - mSgv = stub.findViewById(R.id.sgv); - mDirection = stub.findViewById(R.id.direction); - mTimestamp = stub.findViewById(R.id.timestamp); - mIOB1 = stub.findViewById(R.id.iob_text); - mIOB2 = stub.findViewById(R.id.iobView); - mCOB1 = stub.findViewById(R.id.cob_text); - mCOB2 = stub.findViewById(R.id.cobView); - mBgi = stub.findViewById(R.id.bgiView); - mStatus = stub.findViewById(R.id.externaltstatus); - mBasalRate = stub.findViewById(R.id.tmpBasal); - mUploaderBattery = stub.findViewById(R.id.uploader_battery); - mRigBattery = stub.findViewById(R.id.rig_battery); - mDelta = stub.findViewById(R.id.delta); - mAvgDelta = stub.findViewById(R.id.avgdelta); - isAAPSv2 = stub.findViewById(R.id.AAPSv2); - mHighLight = stub.findViewById(R.id.highLight); - mLowLight = stub.findViewById(R.id.lowLight); - mRelativeLayout = stub.findViewById(R.id.main_layout); - mLinearLayout = stub.findViewById(R.id.secondary_layout); - mLinearLayout2 = stub.findViewById(R.id.tertiary_layout); - mGlucoseDial = stub.findViewById(R.id.glucose_dial); - mDeltaGauge = stub.findViewById(R.id.delta_pointer); - mHourHand = stub.findViewById(R.id.hour_hand); - mMinuteHand = stub.findViewById(R.id.minute_hand); - mChartTap = stub.findViewById(R.id.chart_zoom_tap); - mMainMenuTap = stub.findViewById(R.id.main_menu_tap); - chart = stub.findViewById(R.id.chart); - mSimpleUi = stub.findViewById(R.id.simple_ui); - mSimpleSvg = stub.findViewById(R.id.simple_sgv); - mSimpleDirection = stub.findViewById(R.id.simple_direction); - mSimpleTime = stub.findViewById(R.id.simple_watch_time); - layoutSet = true; - setDataFields(); - setColor(); - } - } - ); + layoutStub.setOnLayoutInflatedListener((WatchViewStub stub) -> { + mTime = stub.findViewById(R.id.watch_time); + mHour = stub.findViewById(R.id.hour); + mMinute = stub.findViewById(R.id.minute); + mTimePeriod = stub.findViewById(R.id.timePeriod); + mDay = stub.findViewById(R.id.day); + mDayName = stub.findViewById(R.id.dayname); + mMonth = stub.findViewById(R.id.month); + mDate = stub.findViewById(R.id.date_time); + mLoop = stub.findViewById(R.id.loop); + mSgv = stub.findViewById(R.id.sgv); + mDirection = stub.findViewById(R.id.direction); + mTimestamp = stub.findViewById(R.id.timestamp); + mIOB1 = stub.findViewById(R.id.iob_text); + mIOB2 = stub.findViewById(R.id.iobView); + mCOB1 = stub.findViewById(R.id.cob_text); + mCOB2 = stub.findViewById(R.id.cobView); + mBgi = stub.findViewById(R.id.bgiView); + mStatus = stub.findViewById(R.id.externaltstatus); + mBasalRate = stub.findViewById(R.id.tmpBasal); + mUploaderBattery = stub.findViewById(R.id.uploader_battery); + mRigBattery = stub.findViewById(R.id.rig_battery); + mDelta = stub.findViewById(R.id.delta); + mAvgDelta = stub.findViewById(R.id.avgdelta); + isAAPSv2 = stub.findViewById(R.id.AAPSv2); + mHighLight = stub.findViewById(R.id.highLight); + mLowLight = stub.findViewById(R.id.lowLight); + mRelativeLayout = stub.findViewById(R.id.main_layout); + mLinearLayout = stub.findViewById(R.id.secondary_layout); + mLinearLayout2 = stub.findViewById(R.id.tertiary_layout); + mGlucoseDial = stub.findViewById(R.id.glucose_dial); + mDeltaGauge = stub.findViewById(R.id.delta_pointer); + mHourHand = stub.findViewById(R.id.hour_hand); + mMinuteHand = stub.findViewById(R.id.minute_hand); + mChartTap = stub.findViewById(R.id.chart_zoom_tap); + mMainMenuTap = stub.findViewById(R.id.main_menu_tap); + chart = stub.findViewById(R.id.chart); + layoutSet = true; + setupCharts(); + setDataFields(); + missedReadingAlert(); + }); wakeLock.acquire(50); } public int ageLevel() { if (timeSince() <= (1000 * 60 * 12)) { return 1; - } else { - return 0; } + return 0; } public double timeSince() { @@ -226,7 +278,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc public String readingAge(boolean shortString) { if (rawData.datetime == 0) { - return shortString ? "--'" : "-- Minute ago"; + return shortString ? "--" : "-- Minute ago"; } int minutesAgo = (int) Math.floor(timeSince() / (1000 * 60)); if (minutesAgo == 1) { @@ -250,45 +302,79 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc } @Override - protected void onDraw(Canvas canvas) { - if (layoutSet) { - setupCharts(); + protected long getInteractiveModeUpdateRate() { + return 60 * 1000L; // Only call onTimeChanged every 60 seconds + } - mRelativeLayout.measure(specW, specH); - if (forceSquareCanvas) { - mRelativeLayout.layout(0, 0, displaySize.x, displaySize.x); //force a square for Steampunk watch face. - } else { - mRelativeLayout.layout(0, 0, displaySize.x, displaySize.y); + @Override + protected void onDraw(Canvas canvas) { + if (isSimpleUi()) { + onDrawSimpleUi(canvas); + } else { + if (layoutSet) { + mRelativeLayout.measure(specW, specH); + int y = forceSquareCanvas ? displaySize.x : displaySize.y; // Square Steampunk + mRelativeLayout.layout(0, 0, displaySize.x, y); + mRelativeLayout.draw(canvas); } - mRelativeLayout.draw(canvas); - Log.d("onDraw", "draw"); } } + protected void onDrawSimpleUi(Canvas canvas) { + canvas.drawRect(0, 0, displaySize.x, displaySize.y, mBackgroundPaint); + float xHalf = displaySize.x / 2f; + float yThird = displaySize.y / 3f; + + boolean isOutdated = rawData.datetime > 0 && ageLevel() <= 0; + mSvgPaint.setStrikeThruText(isOutdated); + + mSvgPaint.setColor(getBgColour(rawData.sgvLevel)); + mDirectionPaint.setColor(getBgColour(rawData.sgvLevel)); + + String sSvg = rawData.sSgv; + float svgWidth = mSvgPaint.measureText(sSvg); + + String sDirection = " " + rawData.sDirection + "\uFE0E"; + float directionWidth = mDirectionPaint.measureText(sDirection); + + float xSvg = xHalf - (svgWidth + directionWidth) / 2; + canvas.drawText(sSvg, xSvg, yThird + mYOffset, mSvgPaint); + float xDirection = xSvg + svgWidth; + canvas.drawText(sDirection, xDirection, yThird + mYOffset, mDirectionPaint); + + String sTime = timeFormat.format(mDateTime); + float xTime = xHalf - mTimePaint.measureText(sTime) / 2f; + canvas.drawText(timeFormat.format(mDateTime), xTime, yThird * 2f + mYOffset, mTimePaint); + } + + int getBgColour(long level) { + if (level == 1) { + return colorDarkHigh; + } + if (level == 0) { + return colorDarkMid; + } + return colorDarkLow; + } + @Override protected void onTimeChanged(WatchFaceTime oldTime, WatchFaceTime newTime) { if (layoutSet && (newTime.hasHourChanged(oldTime) || newTime.hasMinuteChanged(oldTime))) { - wakeLock.acquire(50); + long now = System.currentTimeMillis(); + mDateTime.setTime(now); - setDataFields(); - setColor(); + PowerManager.WakeLock wl = wearUtil.getWakeLock("readingPrefs", 50); missedReadingAlert(); checkVibrateHourly(oldTime, newTime); - - mRelativeLayout.measure(specW, specH); - if (forceSquareCanvas) { - mRelativeLayout.layout(0, 0, displaySize.x, displaySize.x); //force a square for Steampunk watch face. - } else { - mRelativeLayout.layout(0, 0, displaySize.x, displaySize.y); + if (!isSimpleUi()) { + setDataFields(); } - invalidate(); + wearUtil.releaseWakeLock(wl); } } private boolean isCharging() { - IntentFilter iFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); - Intent batteryStatus = this.registerReceiver(null, iFilter); - int status = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1); + int status = mBatteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1); return status == BatteryManager.BATTERY_STATUS_CHARGING || status == BatteryManager.BATTERY_STATUS_FULL; } @@ -304,15 +390,13 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc } public void setDataFields() { - setDateAndTime(); - if (mSgv != null) { if (sharedPrefs.getBoolean("showBG", true)) { mSgv.setText(rawData.sSgv); mSgv.setVisibility(View.VISIBLE); } else { - //leave the textview there but invisible, as a height holder for the empty space above the white line + // Leave the textview there but invisible, as a height holder for the empty space above the white line mSgv.setVisibility(View.INVISIBLE); mSgv.setText(""); } @@ -322,7 +406,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc if (mDirection != null) { if (sharedPrefs.getBoolean("show_direction", true)) { - mDirection.setText(rawData.sDirection+"\uFE0E"); + mDirection.setText(rawData.sDirection + "\uFE0E"); mDirection.setVisibility(View.VISIBLE); } else { mDirection.setVisibility(View.GONE); @@ -356,7 +440,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc mCOB1.setVisibility(View.GONE); mCOB2.setVisibility(View.GONE); } - //deal with cases where there is only the value shown for COB, and not the label + // Deal with cases where there is only the value shown for COB, and not the label } else if (mCOB2 != null) { mCOB2.setText(rawData.sCOB2); if (sharedPrefs.getBoolean("show_cob", true)) { @@ -381,7 +465,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc mIOB1.setVisibility(View.GONE); mIOB2.setVisibility(View.GONE); } - //deal with cases where there is only the value shown for IOB, and not the label + // Deal with cases where there is only the value shown for IOB, and not the label } else if (mIOB2 != null) { if (sharedPrefs.getBoolean("show_iob", true)) { mIOB2.setVisibility(View.VISIBLE); @@ -400,11 +484,8 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc if (isAAPSv2 != null) { mTimestamp.setText(readingAge(true)); } else { - if (sharedPrefs.getBoolean("showExternalStatus", true)) { - mTimestamp.setText(readingAge(true)); - } else { - mTimestamp.setText(readingAge(false)); - } + boolean shortString = sharedPrefs.getBoolean("showExternalStatus", true); + mTimestamp.setText(readingAge(shortString)); } mTimestamp.setVisibility(View.VISIBLE); } else { @@ -479,78 +560,43 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc mLoop.setBackgroundResource(R.drawable.loop_green_25); } } else { - mLoop.setText("-'"); + loopLevel = -1; + mLoop.setText("-"); + mLoop.setBackgroundResource(R.drawable.loop_grey_25); } } else { mLoop.setVisibility(View.GONE); } } - setDataFieldsSimpleUi(); - } - void setDataFieldsSimpleUi() { - if (sharedPrefs.getBoolean("simplify_ui_charging", false) && isCharging()) { - mSimpleUi.setVisibility(View.VISIBLE); - - mSimpleSvg.setText(rawData.sSgv); - if (ageLevel() <= 0) { - mSimpleSvg.setPaintFlags(mSimpleSvg.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); - } 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)); - } else if (rawData.sgvLevel == 0) { - mSimpleSvg.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor)); - mSimpleDirection.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_midColor)); - } else if (rawData.sgvLevel == -1) { - mSimpleSvg.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_lowColor)); - mSimpleDirection.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.dark_lowColor)); - } - - mSimpleDirection.setText(rawData.sDirection+"\uFE0E"); - - final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(BaseWatchFace.this); - mSimpleTime.setText(timeFormat.format(System.currentTimeMillis())); - } else { - mSimpleUi.setVisibility(View.GONE); - } + setColor(); } @Override protected void on24HourFormatChanged(boolean is24HourFormat) { - setDateAndTime(); + initFormats(); + if (!isSimpleUi()) { + setDataFields(); + } + invalidate(); } public void setDateAndTime() { - - final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(BaseWatchFace.this); if (mTime != null) { - mTime.setText(timeFormat.format(System.currentTimeMillis())); + mTime.setText(timeFormat.format(mDateTime)); } - Date now = new Date(); - SimpleDateFormat sdfHour; - SimpleDateFormat sdfMinute = new SimpleDateFormat("mm"); - if (DateFormat.is24HourFormat(this)) { - sdfHour = new SimpleDateFormat("HH"); - } else { - sdfHour = new SimpleDateFormat("hh"); - } - sHour = sdfHour.format(now); - sMinute = sdfMinute.format(now); - + sMinute = sdfMinute.format(mDateTime); + sHour = sdfHour.format(mDateTime); if (mHour != null && mMinute != null) { mHour.setText(sHour); mMinute.setText(sMinute); } - if(mTimePeriod != null) { + if (mTimePeriod != null) { if (!DateFormat.is24HourFormat(this)) { mTimePeriod.setVisibility(View.VISIBLE); - SimpleDateFormat sdfPeriod = new SimpleDateFormat("a"); - mTimePeriod.setText(sdfPeriod.format(now).toUpperCase()); + mTimePeriod.setText(sdfPeriod.format(mDateTime).toUpperCase()); } else { mTimePeriod.setVisibility(View.GONE); } @@ -559,14 +605,11 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc if (mDate != null && mDay != null && mMonth != null) { if (sharedPrefs.getBoolean("show_date", false)) { if (mDayName != null) { - SimpleDateFormat sdfDayName = new SimpleDateFormat("E"); - mDayName.setText(sdfDayName.format(now)); + mDayName.setText(sdfDayName.format(mDateTime)); } - SimpleDateFormat sdfDay = new SimpleDateFormat("dd"); - SimpleDateFormat sdfMonth = new SimpleDateFormat("MMM"); - mDay.setText(sdfDay.format(now)); - mMonth.setText(sdfMonth.format(now)); + mDay.setText(sdfDay.format(mDateTime)); + mMonth.setText(sdfMonth.format(mDateTime)); mDate.setVisibility(View.VISIBLE); } else { mDate.setVisibility(View.GONE); @@ -588,7 +631,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc public void strikeThroughSgvIfNeeded() { if (mSgv != null) { if (sharedPrefs.getBoolean("showBG", true)) { - if (ageLevel() <= 0) { + if (ageLevel() <= 0 && rawData.datetime > 0) { mSgv.setPaintFlags(mSgv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); } else { mSgv.setPaintFlags(mSgv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG); @@ -598,30 +641,45 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc } protected void onWatchModeChanged(WatchMode watchMode) { - - if (lowResMode ^ isLowRes(watchMode)) { //if there was a change in lowResMode - lowResMode = isLowRes(watchMode); - setColor(); - } else if (!sharedPrefs.getBoolean("dark", true)) { - //in bright mode: different colours if active: - setColor(); + lowResMode = isLowRes(watchMode); + if (isSimpleUi()) { + setSimpleUiAntiAlias(); + } else { + setDataFields(); } + invalidate(); + } + + void setSimpleUiAntiAlias() { + boolean antiAlias = getCurrentWatchMode() == WatchMode.AMBIENT; + mSvgPaint.setAntiAlias(antiAlias); + mDirectionPaint.setAntiAlias(antiAlias); + mTimePaint.setAntiAlias(antiAlias); } private boolean isLowRes(WatchMode watchMode) { return (watchMode == WatchMode.LOW_BIT) || (watchMode == WatchMode.LOW_BIT_BURN_IN); // || (watchMode == WatchMode.LOW_BIT_BURN_IN); } + private boolean isSimpleUi() { + String simplify = sharedPrefs.getString("simplify_ui", "off"); + if (simplify.equals("off")) { + return false; + } + if ((simplify.equals("ambient") || simplify.equals("ambient_charging")) && getCurrentWatchMode() == WatchMode.AMBIENT) { + return true; + } + return (simplify.equals("charging") || simplify.equals("ambient_charging")) && isCharging(); + } + @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { setupBatteryReceiver(); if ("delta_granularity".equals(key)) { ListenerService.requestData(this); } - if (layoutSet) { setDataFields(); - setColor(); } invalidate(); } @@ -634,13 +692,16 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc public void missedReadingAlert() { int minutes_since = (int) Math.floor(timeSince() / (1000 * 60)); - if (minutes_since >= 16 && ((minutes_since - 16) % 5) == 0) { - ListenerService.requestData(this); // attempt endTime recover missing data + if (rawData.datetime == 0 || minutes_since >= 16 && ((minutes_since - 16) % 5) == 0) { + ListenerService.requestData(this); // Attempt endTime recover missing data } } public void setupCharts() { - if (rawData.bgDataList.size() > 0) { //Dont crash things just because we dont have values, people dont like crashy things + if (isSimpleUi()) { + return; + } + if (rawData.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", "3")); if (lowResMode) { bgGraphBuilder = new BgGraphBuilder(getApplicationContext(), rawData, pointSize, midColor, gridColor, basalBackgroundColor, basalCenterColor, bolusColor, Color.GREEN, timeframe); @@ -657,31 +718,36 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc public class MessageReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { + PowerManager.WakeLock wl = wearUtil.getWakeLock("readingPrefs", 50); - if (layoutSet) { - final DataMap dataMap = rawData.updateDataFromMessage(intent, wakeLock); - if (chart != null && dataMap != null) { - rawData.addToWatchSet(dataMap); - setupCharts(); + final DataMap dataMap = rawData.updateDataFromMessage(intent, wakeLock); + if (chart != null && dataMap != null) { + rawData.addToWatchSet(dataMap); + setupCharts(); + } + rawData.updateStatusFromMessage(intent, wakeLock); + rawData.updateBasalsFromMessage(intent, wakeLock); + + if (isSimpleUi()) { + if (needUpdate()) { + invalidate(); } - rawData.updateStatusFromMessage(intent, wakeLock); - } - - 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. } else { - mRelativeLayout.layout(0, 0, displaySize.x, displaySize.y); + setupCharts(); + setDataFields(); + invalidate(); } - invalidate(); + wearUtil.releaseWakeLock(wl); } } + private boolean needUpdate() { + if (mLastSvg.equals(rawData.sSgv) && mLastDirection.equals(rawData.sDirection)) { + return false; + } + mLastSvg = rawData.sSgv; + mLastDirection = rawData.sDirection; + return true; + } + } 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 31d293929a..3a68158109 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/Cockpit.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/Cockpit.java @@ -60,7 +60,9 @@ public class Cockpit extends BaseWatchFace { } } - if (loopLevel == 1) { + if (loopLevel == -1) { + mLoop.setBackgroundResource(R.drawable.loop_grey_25); + } else if (loopLevel == 1) { mLoop.setBackgroundResource(R.drawable.loop_green_25); } else { mLoop.setBackgroundResource(R.drawable.loop_red_25); 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 74a36f914b..9f1cb75ddd 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/Home2.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/Home2.java @@ -117,7 +117,9 @@ public class Home2 extends BaseWatchFace { mBasalRate.setTextColor(dividerTxtColor); mBgi.setTextColor(dividerTxtColor); - if (loopLevel == 1) { + if (loopLevel == -1) { + mLoop.setBackgroundResource(R.drawable.loop_grey_25); + } else if (loopLevel == 1) { mLoop.setBackgroundResource(R.drawable.loop_green_25); } else { mLoop.setBackgroundResource(R.drawable.loop_red_25); @@ -226,7 +228,9 @@ public class Home2 extends BaseWatchFace { mBasalRate.setTextColor(dividerTxtColor); mBgi.setTextColor(dividerTxtColor); - if (loopLevel == 1) { + if (loopLevel == -1) { + mLoop.setBackgroundResource(R.drawable.loop_grey_25); + } else if (loopLevel == 1) { mLoop.setBackgroundResource(R.drawable.loop_green_25); } else { mLoop.setBackgroundResource(R.drawable.loop_red_25); diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/Steampunk.java b/wear/src/main/java/info/nightscout/androidaps/watchfaces/Steampunk.java index 3451a3393f..644c17668d 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/Steampunk.java +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/Steampunk.java @@ -67,7 +67,7 @@ public class Steampunk extends BaseWatchFace { protected void setColorDark() { if (mLinearLayout2 != null) { - if (ageLevel() <= 0) { + if (ageLevel() <= 0 && rawData.datetime != 0) { mLinearLayout2.setBackgroundResource(R.drawable.redline); mTimestamp.setTextColor(getResources().getColor(R.color.red_600)); } else { @@ -108,6 +108,7 @@ public class Steampunk extends BaseWatchFace { if (rotationAngle > 330) rotationAngle = 330; //if the glucose value is higher than 330 then show "HIGH" on the dial. ("HIGH" is at 330 degrees on the dial) if (rotationAngle != 0 && rotationAngle < 30) rotationAngle = 30; //if the glucose value is lower than 30 show "LOW" on the dial. ("LOW" is at 30 degrees on the dial) + if (lastEndDegrees == 0) lastEndDegrees = rotationAngle; //rotate glucose dial RotateAnimation rotate = new RotateAnimation( @@ -267,4 +268,4 @@ public class Steampunk extends BaseWatchFace { setupCharts(); sharedPrefs.edit().putString("chart_timeframe", "" + timeframe).apply(); } -} \ No newline at end of file +} diff --git a/wear/src/main/res/layout/rect_activity_digitalstyle.xml b/wear/src/main/res/layout/rect_activity_digitalstyle.xml index 86c79196fc..ab31bb31ca 100644 --- a/wear/src/main/res/layout/rect_activity_digitalstyle.xml +++ b/wear/src/main/res/layout/rect_activity_digitalstyle.xml @@ -559,11 +559,6 @@ - - - - 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 f15bfa33bf..180ff9efdb 100644 --- a/wear/src/main/res/layout/rect_activity_home_2.xml +++ b/wear/src/main/res/layout/rect_activity_home_2.xml @@ -370,9 +370,4 @@ - - diff --git a/wear/src/main/res/layout/rect_activity_home_large.xml b/wear/src/main/res/layout/rect_activity_home_large.xml index e3fd3012e0..a6da174128 100644 --- a/wear/src/main/res/layout/rect_activity_home_large.xml +++ b/wear/src/main/res/layout/rect_activity_home_large.xml @@ -136,9 +136,4 @@ - - diff --git a/wear/src/main/res/layout/rect_cockpit.xml b/wear/src/main/res/layout/rect_cockpit.xml index 26b0e79d64..cf26712258 100644 --- a/wear/src/main/res/layout/rect_cockpit.xml +++ b/wear/src/main/res/layout/rect_cockpit.xml @@ -488,9 +488,4 @@ - - \ No newline at end of file diff --git a/wear/src/main/res/layout/rect_steampunk.xml b/wear/src/main/res/layout/rect_steampunk.xml index 91efff6d31..e88ab41c5c 100644 --- a/wear/src/main/res/layout/rect_steampunk.xml +++ b/wear/src/main/res/layout/rect_steampunk.xml @@ -378,9 +378,4 @@ android:layout_height="wrap_content" android:visibility="gone"/> - - diff --git a/wear/src/main/res/layout/round_activity_digitalstyle.xml b/wear/src/main/res/layout/round_activity_digitalstyle.xml index 193d727ca4..83a85b31fb 100644 --- a/wear/src/main/res/layout/round_activity_digitalstyle.xml +++ b/wear/src/main/res/layout/round_activity_digitalstyle.xml @@ -560,11 +560,6 @@ - - - - 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 35c07352a2..d1ef61abe5 100644 --- a/wear/src/main/res/layout/round_activity_home_2.xml +++ b/wear/src/main/res/layout/round_activity_home_2.xml @@ -383,9 +383,4 @@ - - diff --git a/wear/src/main/res/layout/round_activity_home_large.xml b/wear/src/main/res/layout/round_activity_home_large.xml index 054584b842..9569d5d1ab 100644 --- a/wear/src/main/res/layout/round_activity_home_large.xml +++ b/wear/src/main/res/layout/round_activity_home_large.xml @@ -135,9 +135,4 @@ - - diff --git a/wear/src/main/res/layout/round_cockpit.xml b/wear/src/main/res/layout/round_cockpit.xml index 856f2ee6a3..c4f2f7d5d2 100644 --- a/wear/src/main/res/layout/round_cockpit.xml +++ b/wear/src/main/res/layout/round_cockpit.xml @@ -488,9 +488,4 @@ - - - \ No newline at end of file + diff --git a/wear/src/main/res/layout/round_steampunk.xml b/wear/src/main/res/layout/round_steampunk.xml index 2d66ada9cb..6e586a4251 100644 --- a/wear/src/main/res/layout/round_steampunk.xml +++ b/wear/src/main/res/layout/round_steampunk.xml @@ -378,9 +378,4 @@ android:layout_height="wrap_content" android:visibility="gone"/> - - diff --git a/wear/src/main/res/layout/simple_ui.xml b/wear/src/main/res/layout/simple_ui.xml deleted file mode 100644 index 0780f3e83b..0000000000 --- a/wear/src/main/res/layout/simple_ui.xml +++ /dev/null @@ -1,81 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/wear/src/main/res/values/arrays.xml b/wear/src/main/res/values/arrays.xml index b3f80eb126..6a753edec5 100644 --- a/wear/src/main/res/values/arrays.xml +++ b/wear/src/main/res/values/arrays.xml @@ -65,4 +65,18 @@ none + + Off + During Charging + Always On Mode + Always On and Charging + + + + off + charging + ambient + ambient_charging + + diff --git a/wear/src/main/res/values/dimens.xml b/wear/src/main/res/values/dimens.xml new file mode 100644 index 0000000000..0eaedf5064 --- /dev/null +++ b/wear/src/main/res/values/dimens.xml @@ -0,0 +1,8 @@ + + + + 50sp + 35sp + 35sp + 5dp + diff --git a/wear/src/main/res/values/strings.xml b/wear/src/main/res/values/strings.xml index cf78cc7339..a83cb9bacd 100644 --- a/wear/src/main/res/values/strings.xml +++ b/wear/src/main/res/values/strings.xml @@ -136,8 +136,8 @@ white black multicolor - Simplify Charging UI - Only show time and BG when charging + Simplify UI + Only show time and BG Vibrate hourly diff --git a/wear/src/main/res/xml/preferences.xml b/wear/src/main/res/xml/preferences.xml index 528d8bf00a..919787dec7 100644 --- a/wear/src/main/res/xml/preferences.xml +++ b/wear/src/main/res/xml/preferences.xml @@ -5,16 +5,16 @@ @@ -24,7 +24,7 @@ android:summary="Show BG." android:title="@string/pref_show_bg" app:wear_iconOff="@drawable/settings_off" - app:wear_iconOn="@drawable/settings_on"/> + app:wear_iconOn="@drawable/settings_on" /> + app:wear_iconOn="@drawable/settings_on" /> + app:wear_iconOn="@drawable/settings_on" /> + app:wear_iconOn="@drawable/settings_on" /> + app:wear_iconOn="@drawable/settings_on" /> - - + app:wear_iconOn="@drawable/settings_on" /> - - @@ -128,7 +124,7 @@ android:summary="Wizard from watch possible" android:title="@string/pref_wizard_in_menu" app:wear_iconOff="@drawable/settings_off" - app:wear_iconOn="@drawable/settings_on"/> + app:wear_iconOn="@drawable/settings_on" /> + app:wear_iconOn="@drawable/settings_on" /> + app:wear_iconOn="@drawable/settings_on" /> - - + app:wear_iconOn="@drawable/settings_on" /> + app:wear_iconOn="@drawable/settings_on" /> - \ No newline at end of file + diff --git a/wear/src/main/res/xml/watch_face_configuration_bigchart.xml b/wear/src/main/res/xml/watch_face_configuration_bigchart.xml index 7953823134..a5f5010bdc 100644 --- a/wear/src/main/res/xml/watch_face_configuration_bigchart.xml +++ b/wear/src/main/res/xml/watch_face_configuration_bigchart.xml @@ -9,12 +9,13 @@ android:summary="Dark theme" android:title="@string/pref_dark" app:wear_iconOff="@drawable/settings_off" - app:wear_iconOn="@drawable/settings_on"/> + app:wear_iconOn="@drawable/settings_on" /> + diff --git a/wear/src/main/res/xml/watch_face_configuration_circle.xml b/wear/src/main/res/xml/watch_face_configuration_circle.xml index 440b527bfa..1943d72b0f 100644 --- a/wear/src/main/res/xml/watch_face_configuration_circle.xml +++ b/wear/src/main/res/xml/watch_face_configuration_circle.xml @@ -8,7 +8,7 @@ android:summary="Dark theme" android:title="@string/pref_dark" app:wear_iconOff="@drawable/settings_off" - app:wear_iconOn="@drawable/settings_on"/> + app:wear_iconOn="@drawable/settings_on" /> + app:wear_iconOn="@drawable/settings_on" /> + app:wear_iconOn="@drawable/settings_on" /> - + app:wear_iconOn="@drawable/settings_on" /> + diff --git a/wear/src/main/res/xml/watch_face_configuration_cockpit.xml b/wear/src/main/res/xml/watch_face_configuration_cockpit.xml index 2e8ef3c100..bd87348acb 100644 --- a/wear/src/main/res/xml/watch_face_configuration_cockpit.xml +++ b/wear/src/main/res/xml/watch_face_configuration_cockpit.xml @@ -3,18 +3,18 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> - + diff --git a/wear/src/main/res/xml/watch_face_configuration_digitalstyle.xml b/wear/src/main/res/xml/watch_face_configuration_digitalstyle.xml index d03498d32b..6e33c5d610 100644 --- a/wear/src/main/res/xml/watch_face_configuration_digitalstyle.xml +++ b/wear/src/main/res/xml/watch_face_configuration_digitalstyle.xml @@ -4,59 +4,59 @@ + android:entryValues="@array/digitalstyle_styles_values" + android:key="digitalstyle_frameStyle" + android:title="@string/digitalstyle_pref_your_style" /> + android:entryValues="@array/digitalstyle_color_values" + android:key="digitalstyle_frameColor" + android:title="@string/digitalstyle_pref_your_color" /> + android:entryValues="@array/digitalstyle_color_saturation" + android:key="digitalstyle_frameColorSaturation" + android:title="@string/digitalstyle_pref_your_color_saturation" /> + android:entryValues="@array/digitalstyle_color_opacity_value" + android:key="digitalstyle_frameColorOpacity" + android:title="@string/digitalstyle_pref_your_color_opacity" /> - + diff --git a/wear/src/main/res/xml/watch_face_configuration_home.xml b/wear/src/main/res/xml/watch_face_configuration_home.xml index fbe3015eab..a471c8a816 100644 --- a/wear/src/main/res/xml/watch_face_configuration_home.xml +++ b/wear/src/main/res/xml/watch_face_configuration_home.xml @@ -8,7 +8,7 @@ android:summary="Dark theme" android:title="@string/pref_dark" app:wear_iconOff="@drawable/settings_off" - app:wear_iconOn="@drawable/settings_on"/> + app:wear_iconOn="@drawable/settings_on" /> + app:wear_iconOn="@drawable/settings_on" /> - + diff --git a/wear/src/main/res/xml/watch_face_configuration_home2.xml b/wear/src/main/res/xml/watch_face_configuration_home2.xml index efc27df610..be883d2f76 100644 --- a/wear/src/main/res/xml/watch_face_configuration_home2.xml +++ b/wear/src/main/res/xml/watch_face_configuration_home2.xml @@ -32,12 +32,12 @@ app:wear_iconOff="@drawable/settings_off" app:wear_iconOn="@drawable/settings_on" /> - + diff --git a/wear/src/main/res/xml/watch_face_configuration_largehome.xml b/wear/src/main/res/xml/watch_face_configuration_largehome.xml index fbe3015eab..a471c8a816 100644 --- a/wear/src/main/res/xml/watch_face_configuration_largehome.xml +++ b/wear/src/main/res/xml/watch_face_configuration_largehome.xml @@ -8,7 +8,7 @@ android:summary="Dark theme" android:title="@string/pref_dark" app:wear_iconOff="@drawable/settings_off" - app:wear_iconOn="@drawable/settings_on"/> + app:wear_iconOn="@drawable/settings_on" /> + app:wear_iconOn="@drawable/settings_on" /> - + diff --git a/wear/src/main/res/xml/watch_face_configuration_nochart.xml b/wear/src/main/res/xml/watch_face_configuration_nochart.xml index dc5b99cf8c..a8d78f9d7c 100644 --- a/wear/src/main/res/xml/watch_face_configuration_nochart.xml +++ b/wear/src/main/res/xml/watch_face_configuration_nochart.xml @@ -8,13 +8,14 @@ android:summary="Dark theme" android:title="@string/pref_dark" app:wear_iconOff="@drawable/settings_off" - app:wear_iconOn="@drawable/settings_on"/> + app:wear_iconOn="@drawable/settings_on" /> + diff --git a/wear/src/main/res/xml/watch_face_configuration_steampunk.xml b/wear/src/main/res/xml/watch_face_configuration_steampunk.xml index 0b7358c1f6..e3933b6732 100644 --- a/wear/src/main/res/xml/watch_face_configuration_steampunk.xml +++ b/wear/src/main/res/xml/watch_face_configuration_steampunk.xml @@ -11,18 +11,18 @@ android:title="@string/pref_delta_granularity" /> - +