diff --git a/app/src/main/java/helium314/keyboard/settings/Misc.kt b/app/src/main/java/helium314/keyboard/settings/Misc.kt index 05925afb..d295c2eb 100644 --- a/app/src/main/java/helium314/keyboard/settings/Misc.kt +++ b/app/src/main/java/helium314/keyboard/settings/Misc.kt @@ -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 DropDownField( items: List, diff --git a/app/src/main/java/helium314/keyboard/settings/preferences/Preference.kt b/app/src/main/java/helium314/keyboard/settings/preferences/Preference.kt index 33cd45b6..00a30c23 100644 --- a/app/src/main/java/helium314/keyboard/settings/preferences/Preference.kt +++ b/app/src/main/java/helium314/keyboard/settings/preferences/Preference.kt @@ -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) { diff --git a/app/src/main/java/helium314/keyboard/settings/screens/AboutScreen.kt b/app/src/main/java/helium314/keyboard/settings/screens/AboutScreen.kt index 0b827952..56281034 100644 --- a/app/src/main/java/helium314/keyboard/settings/screens/AboutScreen.kt +++ b/app/src/main/java/helium314/keyboard/settings/screens/AboutScreen.kt @@ -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) {