From e658ba45bc705b01e902c03818b30a7ff7db1c74 Mon Sep 17 00:00:00 2001 From: Philoul Date: Mon, 14 Aug 2023 21:58:26 +0200 Subject: [PATCH] Remove direction from layout and add missing colors --- .../rx/weardata/CustomWatchfaceFormat.kt | 54 ++---------------- .../androidaps/watchfaces/CustomWatchface.kt | 56 ++++++------------- .../watchfaces/utils/WatchfaceViewAdapter.kt | 2 +- wear/src/main/res/layout/activity_custom.xml | 17 +----- 4 files changed, 27 insertions(+), 102 deletions(-) diff --git a/app-wear-shared/shared/src/main/java/info/nightscout/rx/weardata/CustomWatchfaceFormat.kt b/app-wear-shared/shared/src/main/java/info/nightscout/rx/weardata/CustomWatchfaceFormat.kt index 7c855468bb..4b8fe7b6bc 100644 --- a/app-wear-shared/shared/src/main/java/info/nightscout/rx/weardata/CustomWatchfaceFormat.kt +++ b/app-wear-shared/shared/src/main/java/info/nightscout/rx/weardata/CustomWatchfaceFormat.kt @@ -17,7 +17,7 @@ import java.util.zip.ZipEntry import java.util.zip.ZipInputStream import java.util.zip.ZipOutputStream -val CUSTOM_VERSION = "0.3" +val CUSTOM_VERSION = "0.4" enum class CustomWatchfaceDrawableDataKey(val key: String, @DrawableRes val icon: Int?, val fileName: String) { UNKNOWN("unknown", null, "Unknown"), CUSTOM_WATCHFACE("customWatchface", R.drawable.watchface_custom, "CustomWatchface"), @@ -29,30 +29,10 @@ enum class CustomWatchfaceDrawableDataKey(val key: String, @DrawableRes val icon SECONDHAND("second_hand", R.drawable.second_hand, "SecondHand"); companion object { - - private val keyToEnumMap = HashMap() - private val fileNameToEnumMap = HashMap() - - init { - for (value in values()) keyToEnumMap[value.key] = value - for (value in values()) fileNameToEnumMap[value.fileName] = value - } - fun fromKey(key: String): CustomWatchfaceDrawableDataKey = - if (keyToEnumMap.containsKey(key)) { - keyToEnumMap[key] ?: UNKNOWN - } else { - UNKNOWN - } - - fun fromFileName(file: String): CustomWatchfaceDrawableDataKey = - if (fileNameToEnumMap.containsKey(file.substringBeforeLast("."))) { - fileNameToEnumMap[file.substringBeforeLast(".")] ?: UNKNOWN - } else { - UNKNOWN - } + values().firstOrNull { it.key == key } ?: UNKNOWN + fun fromFileName(file: String): CustomWatchfaceDrawableDataKey = values().firstOrNull { it.fileName == file } ?: UNKNOWN } - } enum class DrawableFormat(val extension: String) { @@ -64,19 +44,9 @@ enum class DrawableFormat(val extension: String) { PNG("png"); companion object { - - private val extensionToEnumMap = HashMap() - - init { - for (value in values()) extensionToEnumMap[value.extension] = value - } - fun fromFileName(fileName: String): DrawableFormat = - if (extensionToEnumMap.containsKey(fileName.substringAfterLast("."))) { - extensionToEnumMap[fileName.substringAfterLast(".")] ?: UNKNOWN - } else { - UNKNOWN - } + values().firstOrNull { it.extension == fileName.substringAfterLast(".") } ?: UNKNOWN + } } @@ -126,20 +96,8 @@ enum class CustomWatchfaceMetadataKey(val key: String, @StringRes val label: Int CWF_VERSION("cwf_version", R.string.metadata_label_watchface_version); companion object { - - private val keyToEnumMap = HashMap() - - init { - for (value in values()) keyToEnumMap[value.key] = value - } - fun fromKey(key: String): CustomWatchfaceMetadataKey? = - if (keyToEnumMap.containsKey(key)) { - keyToEnumMap[key] - } else { - null - } - + values().firstOrNull { it.key == key } } } diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CustomWatchface.kt b/wear/src/main/java/info/nightscout/androidaps/watchfaces/CustomWatchface.kt index a5c8be2026..5a61a3be77 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CustomWatchface.kt +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/CustomWatchface.kt @@ -78,12 +78,16 @@ class CustomWatchface : BaseWatchFace() { override fun setDataFields() { super.setDataFields() binding.direction2.setImageDrawable(resources.getDrawable(TrendArrow.fromSymbol(singleBg.slopeArrow).icon)) + // rotate the second hand. + binding.secondHand.rotation = TimeOfDay().secondOfMinute * 6f + // rotate the minute hand. + binding.minuteHand.rotation = TimeOfDay().minuteOfHour * 6f + // rotate the hour hand. + binding.hourHand.rotation = TimeOfDay().hourOfDay * 30f + TimeOfDay().minuteOfHour * 0.5f } override fun setColorDark() { setWatchfaceStyle() - binding.mainLayout.setBackgroundColor(ContextCompat.getColor(this, R.color.dark_background)) binding.sgv.setTextColor(bgColor) - binding.direction.setTextColor(bgColor) binding.direction2.colorFilter = changeDrawableColor(bgColor) if (ageLevel != 1) @@ -96,16 +100,6 @@ class CustomWatchface : BaseWatchFace() { else -> binding.loop.setBackgroundResource(R.drawable.loop_red_25) } - basalBackgroundColor = ContextCompat.getColor(this, R.color.basal_dark) - basalCenterColor = ContextCompat.getColor(this, R.color.basal_light) - - // rotate the second hand. - binding.secondHand.rotation = TimeOfDay().secondOfMinute * 6f - // rotate the minute hand. - binding.minuteHand.rotation = TimeOfDay().minuteOfHour * 6f - // rotate the hour hand. - binding.hourHand.rotation = TimeOfDay().hourOfDay * 30f + TimeOfDay().minuteOfHour * 0.5f - setupCharts() } @@ -143,7 +137,9 @@ class CustomWatchface : BaseWatchFace() { lowColor = if (json.has("lowColor")) Color.parseColor(json.getString("lowColor")) else ContextCompat.getColor(this, R.color.low) lowBatColor = if (json.has("lowBatColor")) Color.parseColor(json.getString("lowBatColor")) else ContextCompat.getColor(this, R.color.dark_uploaderBatteryEmpty) carbColor = if (json.has("carbColor")) Color.parseColor(json.getString("carbColor")) else ContextCompat.getColor(this, R.color.carbs) - gridColor = if (json.has("gridColor")) Color.parseColor(json.getString("gridColor")) else ContextCompat.getColor(this, R.color.carbs) + basalBackgroundColor = if (json.has("basalBackgroundColor")) Color.parseColor(json.getString("basalBackgroundColor")) else ContextCompat.getColor(this, R.color.basal_dark) + basalCenterColor = if (json.has("basalCenterColor")) Color.parseColor(json.getString("basalCenterColor")) else ContextCompat.getColor(this, R.color.basal_light) + gridColor = if (json.has("gridColor")) Color.parseColor(json.getString("gridColor")) else Color.WHITE pointSize = if (json.has("pointSize")) json.getInt("pointSize") else 2 bgColor = when (singleBg.sgvLevel) { 1L -> highColor @@ -224,6 +220,8 @@ class CustomWatchface : BaseWatchFace() { .put("lowColor", String.format("#%06X", 0xFFFFFF and lowColor)) .put("lowBatColor", String.format("#%06X", 0xFFFFFF and lowBatColor)) .put("carbColor", String.format("#%06X", 0xFFFFFF and carbColor)) + .put("basalBackgroundColor", String.format("#%06X", 0xFFFFFF and basalBackgroundColor)) + .put("basalCenterColor", String.format("#%06X", 0xFFFFFF and basalCenterColor)) .put("gridColor", String.format("#%06X", 0xFFFFFF and Color.WHITE)) .put("pointSize",2) .put("enableSecond", true) @@ -287,6 +285,8 @@ class CustomWatchface : BaseWatchFace() { midColor = Color.parseColor("#00FF00") lowColor = Color.parseColor("#FF0000") carbColor = ContextCompat.getColor(this, R.color.carbs) + basalBackgroundColor = ContextCompat.getColor(this, R.color.basal_dark) + basalCenterColor = ContextCompat.getColor(this, R.color.basal_light) lowBatColor = ContextCompat.getColor(this, R.color.dark_uploaderBatteryEmpty) gridColor = Color.WHITE } @@ -434,8 +434,7 @@ class CustomWatchface : BaseWatchFace() { DAY("day", R.id.day, null), MONTH("month", R.id.month, null), LOOP("loop", R.id.loop, R.string.key_show_external_status), - DIRECTION("direction", R.id.direction, R.string.key_show_direction), - DIRECTION2("direction2", R.id.direction2, R.string.key_show_direction), + DIRECTION("direction", R.id.direction2, R.string.key_show_direction), TIMESTAMP("timestamp", R.id.timestamp, R.string.key_show_ago), SGV("sgv", R.id.sgv, R.string.key_show_bg), COVER_PLATE(CustomWatchfaceDrawableDataKey.COVERPLATE.key, R.id.cover_plate, null), @@ -444,27 +443,8 @@ class CustomWatchface : BaseWatchFace() { SECOND_HAND(CustomWatchfaceDrawableDataKey.SECONDHAND.key, R.id.second_hand, R.string.key_show_seconds); companion object { - - private val keyToEnumMap = HashMap() - private val idToEnumMap = HashMap() - - init { - for (value in values()) keyToEnumMap[value.key] = value - for (value in values()) idToEnumMap[value.id] = value - } - - fun fromKey(key: String): CustomViews? = - if (keyToEnumMap.containsKey(key)) { - keyToEnumMap[key] - } else { - null - } - fun fromId(id: Int): CustomViews? = - if (idToEnumMap.containsKey(id)) { - idToEnumMap[id] - } else { - null - } + fun fromKey(key: String): CustomViews? = values().firstOrNull { it.key == key } + fun fromId(id: Int): CustomViews? = values().firstOrNull { it.id == id } } @@ -475,7 +455,7 @@ class CustomWatchface : BaseWatchFace() { enum class TrendArrow(val text: String, val symbol: String,@DrawableRes val icon: Int) { NONE("NONE", "??", R.drawable.ic_invalid), - TRIPLE_UP("TripleUp", "X", R.drawable.ic_invalid), + TRIPLE_UP("TripleUp", "X", R.drawable.ic_doubleup), DOUBLE_UP("DoubleUp", "\u21c8", R.drawable.ic_doubleup), SINGLE_UP("SingleUp", "\u2191", R.drawable.ic_singleup), FORTY_FIVE_UP("FortyFiveUp", "\u2197", R.drawable.ic_fortyfiveup), @@ -483,7 +463,7 @@ class CustomWatchface : BaseWatchFace() { FORTY_FIVE_DOWN("FortyFiveDown", "\u2198",R.drawable.ic_fortyfivedown), SINGLE_DOWN("SingleDown", "\u2193", R.drawable.ic_singledown), DOUBLE_DOWN("DoubleDown", "\u21ca", R.drawable.ic_doubledown), - TRIPLE_DOWN("TripleDown", "X",R.drawable.ic_invalid) + TRIPLE_DOWN("TripleDown", "X",R.drawable.ic_doubledown) ; companion object { diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/WatchfaceViewAdapter.kt b/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/WatchfaceViewAdapter.kt index 61333ad1e1..0498c48637 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/WatchfaceViewAdapter.kt +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/WatchfaceViewAdapter.kt @@ -47,7 +47,7 @@ class WatchfaceViewAdapter( // Optional attributes val sgv = aL?.sgv ?: a2?.sgv ?: aa?.sgv ?: bC?.sgv ?: bC?.sgv ?: cp?.sgv ?: ds?.sgv ?: nC?.sgv ?: cU?.sgv - val direction = aL?.direction ?: a2?.direction ?: aa?.direction ?: cp?.direction ?: ds?.direction ?: cU?.direction + val direction = aL?.direction ?: a2?.direction ?: aa?.direction ?: cp?.direction ?: ds?.direction val loop = a2?.loop ?: cp?.loop ?: sP?.loop ?: cU?.loop val delta = aL?.delta ?: a2?.delta ?: aa?.delta ?: bC?.delta ?: bC?.delta ?: cp?.delta ?: ds?.delta ?: nC?.delta ?: cU?.delta val avgDelta = a2?.avgDelta ?: bC?.avgDelta ?: bC?.avgDelta ?: cp?.avgDelta ?: ds?.avgDelta ?: nC?.avgDelta ?: cU?.avgDelta diff --git a/wear/src/main/res/layout/activity_custom.xml b/wear/src/main/res/layout/activity_custom.xml index a746ba2a8a..b4dabff038 100644 --- a/wear/src/main/res/layout/activity_custom.xml +++ b/wear/src/main/res/layout/activity_custom.xml @@ -300,27 +300,14 @@ android:textColor="@color/light_grey" tools:text="--'" /> - -