Wear CWF Remove variable and SonarLint bug
This commit is contained in:
parent
170b2ecec0
commit
fd74a1e121
1 changed files with 13 additions and 8 deletions
|
@ -72,7 +72,7 @@ enum class ResFormat(val extension: String) {
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun fromFileName(fileName: String): ResFormat =
|
fun fromFileName(fileName: String): ResFormat =
|
||||||
values().firstOrNull { it.extension == fileName.substringAfterLast(".") } ?: UNKNOWN
|
values().firstOrNull { it.extension == fileName.substringAfterLast(".").lowercase() } ?: UNKNOWN
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,14 +108,19 @@ data class ResData(val value: ByteArray, val format: ResFormat) {
|
||||||
return when (format) {
|
return when (format) {
|
||||||
ResFormat.TTF -> {
|
ResFormat.TTF -> {
|
||||||
// Workaround with temporary File, Typeface.createFromFileDescriptor(null, value, 0, value.size) more simple not available
|
// Workaround with temporary File, Typeface.createFromFileDescriptor(null, value, 0, value.size) more simple not available
|
||||||
val tempFile = File.createTempFile("temp", ".ttf")
|
File.createTempFile("temp", ".ttf").let { tempFile ->
|
||||||
val fileOutputStream = FileOutputStream(tempFile)
|
FileOutputStream(tempFile).let { fileOutputStream ->
|
||||||
fileOutputStream.write(value)
|
fileOutputStream.write(value)
|
||||||
fileOutputStream.close()
|
fileOutputStream.close()
|
||||||
|
}
|
||||||
|
|
||||||
val typeface = Typeface.createFromFile(tempFile)
|
Typeface.createFromFile(tempFile).let {
|
||||||
tempFile.delete() // delete tempfile after usage
|
if (!tempFile.delete()) {
|
||||||
typeface
|
// delete tempfile after usage
|
||||||
|
}
|
||||||
|
it
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
|
|
Loading…
Reference in a new issue