Merge pull request #2708 from Philoul/wear/new_custom_watchface

Wear CWF svg format included for images
This commit is contained in:
Milos Kozak 2023-08-26 23:59:11 +02:00 committed by GitHub
commit 10e14960a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 18 deletions

View file

@ -35,6 +35,7 @@ dependencies {
api "org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinx_serialization_version"
api "org.jetbrains.kotlinx:kotlinx-serialization-protobuf:$kotlinx_serialization_version"
api "com.caverock:androidsvg:$caverock_androidsvg_version"
api "org.apache.commons:commons-lang3:$commonslang3_version"
//RxBus

View file

@ -4,12 +4,15 @@ import android.content.res.Resources
import android.graphics.BitmapFactory
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.graphics.drawable.PictureDrawable
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import com.caverock.androidsvg.SVG
import info.nightscout.shared.R
import kotlinx.serialization.Serializable
import org.json.JSONObject
import java.io.BufferedOutputStream
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.FileOutputStream
@ -42,9 +45,7 @@ enum class CwfDrawableFileMap(val key: String, @DrawableRes val icon: Int?, val
enum class DrawableFormat(val extension: String) {
UNKNOWN(""),
//XML("xml"),
//SVG("svg"),
SVG("svg"),
JPG("jpg"),
PNG("png");
@ -66,19 +67,15 @@ data class DrawableData(val value: ByteArray, val format: DrawableFormat) {
val bitmap = BitmapFactory.decodeByteArray(value, 0, value.size)
BitmapDrawable(resources, bitmap)
}
/*
DrawableFormat.SVG -> {
//TODO: include svg to Drawable convertor here
null
}
DrawableFormat.XML -> {
// Always return a null Drawable, even if xml file is a valid xml vector file
val xmlInputStream = ByteArrayInputStream(value)
val xmlPullParser = Xml.newPullParser()
xmlPullParser.setInput(xmlInputStream, null)
Drawable.createFromXml(resources, xmlPullParser)
}
*/
DrawableFormat.SVG -> {
val svg = SVG.getFromInputStream(ByteArrayInputStream(value))
val picture = svg.renderToPicture()
PictureDrawable(picture).apply {
setBounds(0, 0, svg.documentWidth.toInt(), svg.documentHeight.toInt())
}
}
else -> null
}
} catch (e: Exception) {

View file

@ -46,7 +46,7 @@
<string name="metadata_wear_import_filename">File name: %1$s</string>
<string name="metadata_label_plugin_version">Plugin version: %1$s</string>
<string name="metadata_label_watchface_name_version">Name: %1$s (%2$s)</string>
<string name="metadata_label_watchface_comment" translatable="false">Comment: %1$s</string>
<string name="metadata_label_watchface_comment">Comment: %1$s</string>
<string name="metadata_label_watchface_authorization" translatable="false">%1$s</string>
<string name="pref_show_iob">Show IOB</string>
<string name="pref_show_detailed_iob">Show detailed IOB</string>

View file

@ -51,6 +51,8 @@ buildscript {
kotlinx_datetime_version = '0.4.0'
kotlinx_serialization_version = '1.6.0'
caverock_androidsvg_version = '1.4'
}
repositories {
google()

View file

@ -165,7 +165,7 @@ class CwfInfosActivity : TranslatedDaggerAppCompatActivity() {
val cwfView = viewList[position]
val key = cwfView.first.key
val value = cwfView.first.comment
val visible = cwfView.second // will be used if all keys included into RecyclerView
//val visible = cwfView.second // will be used if all keys included into RecyclerView
with(holder.cwfInfosActivityViewItemBinding) {
viewKey.text = "\"$key\":"
viewComment.text = rh.gs(value)