Wear cwf Include svg format for vector images (background, cover_plate, ...)

This commit is contained in:
Philoul 2023-08-26 23:01:08 +02:00
parent c08e43f412
commit 2466e297be
3 changed files with 15 additions and 6 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
@ -44,7 +47,7 @@ enum class DrawableFormat(val extension: String) {
UNKNOWN(""),
//XML("xml"),
//SVG("svg"),
SVG("svg"),
JPG("jpg"),
PNG("png");
@ -66,11 +69,14 @@ 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.SVG -> {
val svg = SVG.getFromInputStream(ByteArrayInputStream(value))
val picture = svg.renderToPicture()
PictureDrawable(picture).apply {
setBounds(0, 0, svg.documentWidth.toInt(), svg.documentHeight.toInt())
}
}
/*
DrawableFormat.XML -> {
// Always return a null Drawable, even if xml file is a valid xml vector file
val xmlInputStream = ByteArrayInputStream(value)

View file

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