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

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>