Wear: simple ui use dimens

This commit is contained in:
Andries Smit 2022-01-08 17:32:29 +01:00
parent c01ff80bf6
commit 5760bbe708
3 changed files with 71 additions and 44 deletions

View file

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
@ -17,7 +18,7 @@ import android.os.Vibrator;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.wearable.view.WatchViewStub; import android.support.wearable.view.WatchViewStub;
import android.text.format.DateFormat; import android.text.format.DateFormat;
//import android.util.Log; import android.util.Log;
import android.view.Display; import android.view.Display;
import android.view.View; import android.view.View;
import android.view.WindowInsets; import android.view.WindowInsets;
@ -108,15 +109,16 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
private int colorDarkLow; private int colorDarkLow;
private java.text.DateFormat timeFormat; private java.text.DateFormat timeFormat;
private SimpleDateFormat sdfDay, sdfMonth, sdfHour, sdfPeriod, sdfDayName, sdfMinute; private SimpleDateFormat sdfDay, sdfMonth, sdfHour, sdfPeriod, sdfDayName, sdfMinute;
// private final String TAG = "ASTAG"; private final String TAG = "ASTAG";
private Paint mBackgroundPaint, mTimePaint, mSvgPaint, mDirectionPaint; private Paint mBackgroundPaint, mTimePaint, mSvgPaint, mDirectionPaint;
private Date mDateTime; private Date mDateTime;
private String mLastSvg = ""; private String mLastSvg = "";
private String mLastDirection = ""; private String mLastDirection = "";
private float mYOffset = 0;
@Override @Override
public void onCreate() { public void onCreate() {
// Log.i(TAG, "onCreate: "); Log.i(TAG, "onCreate: ");
// Not derived from DaggerService, do injection here // Not derived from DaggerService, do injection here
AndroidInjection.inject(this); AndroidInjection.inject(this);
super.onCreate(); super.onCreate();
@ -148,16 +150,16 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
private void setupBatteryReceiver() { private void setupBatteryReceiver() {
String setting = sharedPrefs.getString("simplify_ui", "off"); String setting = sharedPrefs.getString("simplify_ui", "off");
// Log.i(TAG, "setupBatteryReceiver: " + setting); Log.i(TAG, "setupBatteryReceiver: " + setting);
if (setting.equals("charging") || setting.equals("ambient_charging") && batteryReceiver == null) { if (setting.equals("charging") || setting.equals("ambient_charging") && batteryReceiver == null) {
// Log.i(TAG, "setupBatteryReceiver: DONE"); Log.i(TAG, "setupBatteryReceiver: DONE");
IntentFilter intentBatteryFilter = new IntentFilter(); IntentFilter intentBatteryFilter = new IntentFilter();
intentBatteryFilter.addAction(BatteryManager.ACTION_CHARGING); intentBatteryFilter.addAction(BatteryManager.ACTION_CHARGING);
intentBatteryFilter.addAction(BatteryManager.ACTION_DISCHARGING); intentBatteryFilter.addAction(BatteryManager.ACTION_DISCHARGING);
batteryReceiver = new BroadcastReceiver() { batteryReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
// Log.i(TAG, "Battery BroadcastReceiver.onReceive: "); Log.i(TAG, "Battery BroadcastReceiver.onReceive: ");
setDataFields(); setDataFields();
invalidate(); invalidate();
} }
@ -188,9 +190,11 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
final Typeface BOLD_TYPEFACE = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD); final Typeface BOLD_TYPEFACE = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD);
int white = ContextCompat.getColor(getApplicationContext(), R.color.white); int white = ContextCompat.getColor(getApplicationContext(), R.color.white);
float textSizeSvg = 75; Resources resources = this.getResources();
float textSizeDirection = 57; float textSizeSvg = resources.getDimension(R.dimen.simple_ui_svg_text_size);
float textSizeTime = 60; 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); mSvgPaint = createTextPaint(NORMAL_TYPEFACE, white, textSizeSvg);
mDirectionPaint = createTextPaint(BOLD_TYPEFACE, white, textSizeDirection); mDirectionPaint = createTextPaint(BOLD_TYPEFACE, white, textSizeDirection);
@ -208,7 +212,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
@Override @Override
protected void onLayout(WatchShape shape, Rect screenBounds, WindowInsets screenInsets) { protected void onLayout(WatchShape shape, Rect screenBounds, WindowInsets screenInsets) {
// Log.i(TAG, "onLayout: "); Log.i(TAG, "onLayout: ");
super.onLayout(shape, screenBounds, screenInsets); super.onLayout(shape, screenBounds, screenInsets);
layoutView.onApplyWindowInsets(screenInsets); layoutView.onApplyWindowInsets(screenInsets);
bIsRound = screenInsets.isRound(); bIsRound = screenInsets.isRound();
@ -311,9 +315,8 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
@Override @Override
protected void onDraw(Canvas canvas) { protected void onDraw(Canvas canvas) {
// Log.i(TAG, "onDraw: start "); Log.i(TAG, "onDraw: start ");
// Draw the background. long sTime = System.nanoTime();
// long sTime = System.nanoTime();
if (isSimpleUi()) { if (isSimpleUi()) {
onDrawSimpleUi(canvas); onDrawSimpleUi(canvas);
} else { } else {
@ -326,20 +329,19 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
mRelativeLayout.layout(0, 0, displaySize.x, displaySize.y); mRelativeLayout.layout(0, 0, displaySize.x, displaySize.y);
} }
mRelativeLayout.draw(canvas); mRelativeLayout.draw(canvas);
//Log.d("onDraw", "draw");
} }
} }
// long fTime = System.nanoTime(); long fTime = System.nanoTime();
// float elapsedTime = (float) (fTime - sTime) / (1000 * 1000); float elapsedTime = (float) (fTime - sTime) / (1000 * 1000);
// Log.i(TAG, "onDraw: end " + String.format("%.3f", elapsedTime) + "ms"); Log.i(TAG, "onDraw: end " + String.format("%.3f", elapsedTime) + "ms");
} }
protected void onDrawSimpleUi(Canvas canvas) { protected void onDrawSimpleUi(Canvas canvas) {
Log.i(TAG, "onDrawSimpleUi: ");
canvas.drawRect(0, 0, displaySize.x, displaySize.y, mBackgroundPaint); canvas.drawRect(0, 0, displaySize.x, displaySize.y, mBackgroundPaint);
float xHalf = displaySize.x / 2f; float xHalf = displaySize.x / 2f;
float yThird = displaySize.y / 3f; float yThird = displaySize.y / 3f;
float yOffset = 25f;
boolean isOutdated = rawData.datetime > 0 && ageLevel() <= 0; boolean isOutdated = rawData.datetime > 0 && ageLevel() <= 0;
mSvgPaint.setStrikeThruText(isOutdated); mSvgPaint.setStrikeThruText(isOutdated);
@ -354,21 +356,20 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
float directionWidth = mDirectionPaint.measureText(sDirection); float directionWidth = mDirectionPaint.measureText(sDirection);
float xSvg = xHalf - (svgWidth + directionWidth) / 2; float xSvg = xHalf - (svgWidth + directionWidth) / 2;
canvas.drawText(sSvg, xSvg, yThird + 50, mSvgPaint); canvas.drawText(sSvg, xSvg, yThird + mYOffset, mSvgPaint);
float xDirection = xSvg + svgWidth; float xDirection = xSvg + svgWidth;
canvas.drawText(sDirection, xDirection, yThird + yOffset, mDirectionPaint); canvas.drawText(sDirection, xDirection, yThird + mYOffset, mDirectionPaint);
String sTime = timeFormat.format(mDateTime); String sTime = timeFormat.format(mDateTime);
float xTime = xHalf - mTimePaint.measureText(sTime) / 2; float xTime = xHalf - mTimePaint.measureText(sTime) / 2f;
canvas.drawText(timeFormat.format(mDateTime), xTime, yThird * 2 + yOffset, mTimePaint); canvas.drawText(timeFormat.format(mDateTime), xTime, yThird * 2f + mYOffset, mTimePaint);
} }
int getBgColour(long level) { int getBgColour(long level) {
if (rawData.sgvLevel == level) { if (level == 1) {
return colorDarkHigh; return colorDarkHigh;
} if (rawData.sgvLevel == level) { } if (level == 0) {
return colorDarkMid; return colorDarkMid;
} }
return colorDarkLow; return colorDarkLow;
@ -376,9 +377,9 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
@Override @Override
protected void onTimeChanged(WatchFaceTime oldTime, WatchFaceTime newTime) { protected void onTimeChanged(WatchFaceTime oldTime, WatchFaceTime newTime) {
// Log.i(TAG, "onTimeChanged: called "); Log.i(TAG, "onTimeChanged: called ");
if (layoutSet && (newTime.hasHourChanged(oldTime) || newTime.hasMinuteChanged(oldTime))) { if (layoutSet && (newTime.hasHourChanged(oldTime) || newTime.hasMinuteChanged(oldTime))) {
// Log.i(TAG, "onTimeChanged: minute/hour changed"); Log.i(TAG, "onTimeChanged: minute/hour changed");
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
mDateTime.setTime(now); mDateTime.setTime(now);
@ -403,7 +404,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
private void checkVibrateHourly(WatchFaceTime oldTime, WatchFaceTime newTime) { private void checkVibrateHourly(WatchFaceTime oldTime, WatchFaceTime newTime) {
boolean hourlyVibratePref = sharedPrefs.getBoolean("vibrate_Hourly", false); boolean hourlyVibratePref = sharedPrefs.getBoolean("vibrate_Hourly", false);
if (hourlyVibratePref && layoutSet && newTime.hasHourChanged(oldTime)) { if (hourlyVibratePref && layoutSet && newTime.hasHourChanged(oldTime)) {
// Log.i("hourlyVibratePref", "true --> " + newTime.toString()); Log.i("hourlyVibratePref", "true --> " + newTime.toString());
Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);
long[] vibrationPattern = {0, 150, 125, 100}; long[] vibrationPattern = {0, 150, 125, 100};
vibrator.vibrate(vibrationPattern, -1); vibrator.vibrate(vibrationPattern, -1);
@ -411,7 +412,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
} }
public void setDataFields() { public void setDataFields() {
Log.i(TAG, "setDataFields: ");
setDateAndTime(); setDateAndTime();
if (mSgv != null) { if (mSgv != null) {
if (sharedPrefs.getBoolean("showBG", true)) { if (sharedPrefs.getBoolean("showBG", true)) {
@ -569,8 +570,8 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
mStatus.setVisibility(View.GONE); mStatus.setVisibility(View.GONE);
} }
} }
// Log.i(TAG, Log.i(TAG,
// "setDataFields: loop " + rawData.openApsStatus + " " + (System.currentTimeMillis() - rawData.openApsStatus)); "setDataFields: loop " + rawData.openApsStatus + " " + (System.currentTimeMillis() - rawData.openApsStatus));
if (mLoop != null) { if (mLoop != null) {
if (sharedPrefs.getBoolean("showExternalStatus", true)) { if (sharedPrefs.getBoolean("showExternalStatus", true)) {
mLoop.setVisibility(View.VISIBLE); mLoop.setVisibility(View.VISIBLE);
@ -599,7 +600,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
@Override @Override
protected void on24HourFormatChanged(boolean is24HourFormat) { protected void on24HourFormatChanged(boolean is24HourFormat) {
// Log.i(TAG, "on24HourFormatChanged: "); Log.i(TAG, "on24HourFormatChanged: ");
initFormats(); initFormats();
if (!isSimpleUi()) { if (!isSimpleUi()) {
setDataFields(); setDataFields();
@ -608,7 +609,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
} }
public void setDateAndTime() { public void setDateAndTime() {
Log.i(TAG, "setDateAndTime: ");
if (mTime != null) { if (mTime != null) {
mTime.setText(timeFormat.format(mDateTime)); mTime.setText(timeFormat.format(mDateTime));
} }
@ -645,6 +646,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
} }
public void setColor() { public void setColor() {
Log.i(TAG, "setColor: ");
dividerMatchesBg = sharedPrefs.getBoolean("match_divider", false); dividerMatchesBg = sharedPrefs.getBoolean("match_divider", false);
if (lowResMode) { if (lowResMode) {
setColorLowRes(); setColorLowRes();
@ -658,7 +660,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
public void strikeThroughSgvIfNeeded() { public void strikeThroughSgvIfNeeded() {
if (mSgv != null) { if (mSgv != null) {
if (sharedPrefs.getBoolean("showBG", true)) { if (sharedPrefs.getBoolean("showBG", true)) {
if (ageLevel() <= 0) { if (ageLevel() <= 0 && rawData.datetime > 0) {
mSgv.setPaintFlags(mSgv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); mSgv.setPaintFlags(mSgv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
} else { } else {
mSgv.setPaintFlags(mSgv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG); mSgv.setPaintFlags(mSgv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
@ -668,7 +670,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
} }
protected void onWatchModeChanged(WatchMode watchMode) { protected void onWatchModeChanged(WatchMode watchMode) {
// Log.i(TAG, "onWatchModeChanged: " + watchMode); Log.i(TAG, "onWatchModeChanged: " + watchMode);
lowResMode = isLowRes(watchMode); lowResMode = isLowRes(watchMode);
if (isSimpleUi()) { if (isSimpleUi()) {
setSimpleUiAntiAlias(); setSimpleUiAntiAlias();
@ -691,18 +693,25 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
private boolean isSimpleUi() { private boolean isSimpleUi() {
String simplify = sharedPrefs.getString("simplify_ui", "off"); String simplify = sharedPrefs.getString("simplify_ui", "off");
Log.i(TAG, "isSimpleUi: " + simplify);
if (simplify.equals("off")) { if (simplify.equals("off")) {
Log.i(TAG, "isSimpleUi: off");
return false; return false;
} }
if ((simplify.equals("ambient") || simplify.equals("ambient_charging")) && getCurrentWatchMode() == WatchMode.AMBIENT) { if ((simplify.equals("ambient") || simplify.equals("ambient_charging")) && getCurrentWatchMode() == WatchMode.AMBIENT) {
Log.i(TAG, "isSimpleUi: abient");
return true; return true;
} }
return (simplify.equals("charging") || simplify.equals("ambient_charging")) && isCharging(); if((simplify.equals("charging") || simplify.equals("ambient_charging")) && isCharging()){
Log.i(TAG, "isSimpleUi: charging");
return true;
}
return false;
} }
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
// Log.i(TAG, "onSharedPreferenceChanged: "); Log.i(TAG, "onSharedPreferenceChanged: ");
setupBatteryReceiver(); setupBatteryReceiver();
if ("delta_granularity".equals(key)) { if ("delta_granularity".equals(key)) {
ListenerService.requestData(this); ListenerService.requestData(this);
@ -721,10 +730,10 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
protected abstract void setColorLowRes(); protected abstract void setColorLowRes();
public void missedReadingAlert() { public void missedReadingAlert() {
// Log.i(TAG, "missedReadingAlert: check"); Log.i(TAG, "missedReadingAlert: check");
int minutes_since = (int) Math.floor(timeSince() / (1000 * 60)); int minutes_since = (int) Math.floor(timeSince() / (1000 * 60));
if (rawData.datetime == 0 || minutes_since >= 16 && ((minutes_since - 16) % 5) == 0) { if (rawData.datetime == 0 || minutes_since >= 16 && ((minutes_since - 16) % 5) == 0) {
// Log.i(TAG, "missedReadingAlert: do"); Log.i(TAG, "missedReadingAlert: do");
ListenerService.requestData(this); // attempt endTime recover missing data ListenerService.requestData(this); // attempt endTime recover missing data
} }
} }
@ -733,6 +742,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
if (isSimpleUi()) { if (isSimpleUi()) {
return; return;
} }
Log.i(TAG, "setupCharts: ");
if (rawData.bgDataList.size() > 0) { // Dont crash things just because we dont have values, people dont like crashy things 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")); int timeframe = Integer.parseInt(sharedPrefs.getString("chart_timeframe", "3"));
if (lowResMode) { if (lowResMode) {
@ -750,17 +760,21 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
public class MessageReceiver extends BroadcastReceiver { public class MessageReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
// Log.i(TAG, "Data MessageReceiver.onReceive: "); Log.i(TAG, "Data MessageReceiver.onReceive: ");
long sTime = System.nanoTime();
PowerManager.WakeLock wl = wearUtil.getWakeLock("readingPrefs", 50); PowerManager.WakeLock wl = wearUtil.getWakeLock("readingPrefs", 50);
final DataMap dataMap = rawData.updateDataFromMessage(intent, wakeLock); final DataMap dataMap = rawData.updateDataFromMessage(intent, wakeLock);
Log.i(TAG, "onReceive: data " + intent.getBundleExtra("data"));
if (chart != null && dataMap != null) { if (chart != null && dataMap != null) {
rawData.addToWatchSet(dataMap); rawData.addToWatchSet(dataMap);
setupCharts(); setupCharts();
} }
rawData.updateStatusFromMessage(intent, wakeLock); rawData.updateStatusFromMessage(intent, wakeLock);
rawData.updateBasalsFromMessage(intent, wakeLock); rawData.updateBasalsFromMessage(intent, wakeLock);
Log.i(TAG, "onReceive: status " + intent.getBundleExtra("status"));
Log.i(TAG, "onReceive: " + rawData.sSgv + " " + rawData.sDirection);
if (isSimpleUi()) { if (isSimpleUi()) {
if (needUpdate()) { if (needUpdate()) {
invalidate(); invalidate();
@ -771,6 +785,9 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
invalidate(); invalidate();
} }
wearUtil.releaseWakeLock(wl); wearUtil.releaseWakeLock(wl);
long fTime = System.nanoTime();
float elapsedTime = (float) (fTime - sTime) / (1000 * 1000);
Log.i(TAG, "onReceive: end " + String.format("%.3f", elapsedTime) + "ms");
} }
} }
@ -780,6 +797,7 @@ public abstract class BaseWatchFace extends WatchFace implements SharedPreferenc
} }
mLastSvg = rawData.sSgv; mLastSvg = rawData.sSgv;
mLastDirection = rawData.sDirection; mLastDirection = rawData.sDirection;
Log.i(TAG, "needUpdate: ");
return true; return true;
} }

View file

@ -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 > 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 (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 //rotate glucose dial
RotateAnimation rotate = new RotateAnimation( RotateAnimation rotate = new RotateAnimation(

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="simple_ui_svg_text_size">50sp</dimen>
<dimen name="simple_ui_direction_text_size">35sp</dimen>
<dimen name="simple_ui_time_text_size">35sp</dimen>
<dimen name="simple_ui_y_offset">5dp</dimen>
</resources>