re-add background to app icon in about screen

This commit is contained in:
Helium314 2025-03-14 22:57:00 +01:00
parent 18a328cd2b
commit d3401e5c04
3 changed files with 27 additions and 3 deletions

View file

@ -1,13 +1,18 @@
// SPDX-License-Identifier: GPL-3.0-only
package helium314.keyboard.settings
import android.graphics.drawable.VectorDrawable
import androidx.annotation.DrawableRes
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
@ -17,8 +22,13 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.toBitmap
import androidx.core.util.TypedValueCompat
@Composable
fun WithSmallTitle(
@ -31,6 +41,19 @@ fun WithSmallTitle(
}
}
/** Icon if resource is a vector image, (bitmap) Image otherwise */
@Composable
fun IconOrImage(@DrawableRes resId: Int, name: String?, sizeDp: Float) {
val ctx = LocalContext.current
val drawable = ContextCompat.getDrawable(ctx, resId)
if (drawable is VectorDrawable)
Icon(painterResource(resId), name, Modifier.size(sizeDp.dp))
else {
val px = TypedValueCompat.dpToPx(sizeDp, ctx.resources.displayMetrics).toInt()
Image(drawable!!.toBitmap(px, px).asImageBitmap(), name)
}
}
@Composable
fun <T>DropDownField(
items: List<T>,

View file

@ -29,6 +29,7 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import helium314.keyboard.latin.R
import helium314.keyboard.settings.IconOrImage
import helium314.keyboard.settings.Theme
import helium314.keyboard.settings.previewDark
@ -69,7 +70,7 @@ fun Preference(
verticalAlignment = Alignment.CenterVertically
) {
if (icon != null)
Icon(painterResource(icon), name, modifier = Modifier.size(36.dp))
IconOrImage(icon, name, 36f)
Column(modifier = Modifier.weight(1f)) {
Text(text = name, style = MaterialTheme.typography.bodyLarge)
if (description != null) {

View file

@ -69,7 +69,7 @@ fun createAboutSettings(context: Context) = listOf(
name = it.title,
description = it.description,
onClick = { },
icon = R.drawable.ic_launcher_foreground // use the bitmap trick here if we really want the colored icon
icon = R.mipmap.ic_launcher_round
)
},
Setting(context, SettingsWithoutKey.VERSION, R.string.version) {