From e33358d46c415374aea1d3630a1c0b5902a7c53a Mon Sep 17 00:00:00 2001 From: Philoul Date: Sat, 9 Sep 2023 23:15:28 +0200 Subject: [PATCH] Wear CWF Clean loaded font before loading --- .../java/info/nightscout/rx/weardata/CustomWatchfaceFormat.kt | 2 +- .../info/nightscout/androidaps/watchfaces/CustomWatchface.kt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) 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 e2779484e0..4be5b5e5a5 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 @@ -104,7 +104,7 @@ data class ResData(val value: ByteArray, val format: ResFormat) { return when (format) { ResFormat.TTF -> { // Workaround with temporary File, Typeface.createFromFileDescriptor(null, value, 0, value.size) more simple not available - File.createTempFile("temp", ".ttf").let { tempFile -> + File.createTempFile("temp", format.extension).let { tempFile -> FileOutputStream(tempFile).let { fileOutputStream -> fileOutputStream.write(value) fileOutputStream.close() 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 08103d262e..ca92b2c254 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CustomWatchface.kt +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/CustomWatchface.kt @@ -547,6 +547,7 @@ private enum class FontMap(val key: String, var font: Typeface, @FontRes val fon private val customFonts = mutableMapOf() fun init(context: Context, resDataMap: CwfResDataMap) { + customFonts.clear() values().forEach { fontMap -> customFonts[fontMap.key.lowercase()] = fontMap.fontRessources?.let { fontResource -> ResourcesCompat.getFont(context, fontResource)