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 {
|
||||
|
||||
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) {
|
||||
ResFormat.TTF -> {
|
||||
// Workaround with temporary File, Typeface.createFromFileDescriptor(null, value, 0, value.size) more simple not available
|
||||
val tempFile = File.createTempFile("temp", ".ttf")
|
||||
val fileOutputStream = FileOutputStream(tempFile)
|
||||
fileOutputStream.write(value)
|
||||
fileOutputStream.close()
|
||||
File.createTempFile("temp", ".ttf").let { tempFile ->
|
||||
FileOutputStream(tempFile).let { fileOutputStream ->
|
||||
fileOutputStream.write(value)
|
||||
fileOutputStream.close()
|
||||
}
|
||||
|
||||
val typeface = Typeface.createFromFile(tempFile)
|
||||
tempFile.delete() // delete tempfile after usage
|
||||
typeface
|
||||
Typeface.createFromFile(tempFile).let {
|
||||
if (!tempFile.delete()) {
|
||||
// delete tempfile after usage
|
||||
}
|
||||
it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else -> {
|
||||
|
|
Loading…
Reference in a new issue