Use ShapedLauncherIcon instead of LauncherIconView in icon settings

This commit is contained in:
MM20 2022-03-05 17:14:55 +01:00
parent 667ec0f932
commit 983920730f
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
3 changed files with 41 additions and 94 deletions

View File

@ -165,9 +165,8 @@ fun ShapedLauncherIcon(
val LocalIconShape = compositionLocalOf<Shape> { CircleShape }
@Composable
fun ProvideIconShape(iconShape: IconShape, content: @Composable () -> Unit) {
val shape = when (iconShape) {
fun getShape(iconShape: IconShape): Shape {
return when (iconShape) {
IconShape.PlatformDefault -> PlatformShape
IconShape.Circle -> CircleShape
IconShape.Square -> RectangleShape
@ -179,6 +178,11 @@ fun ProvideIconShape(iconShape: IconShape, content: @Composable () -> Unit) {
IconShape.EasterEgg -> EasterEggShape
IconShape.UNRECOGNIZED -> CircleShape
}
}
@Composable
fun ProvideIconShape(iconShape: IconShape, content: @Composable () -> Unit) {
val shape = getShape(iconShape)
CompositionLocalProvider(
LocalIconShape provides shape,
content = content

View File

@ -1,47 +0,0 @@
package de.mm20.launcher2.ui.legacy.transition
import android.animation.Animator
import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.view.ViewGroup
import androidx.transition.Transition
import androidx.transition.TransitionValues
import de.mm20.launcher2.ui.legacy.view.LauncherIconView
class LauncherIconViewTransition : Transition() {
override fun captureStartValues(transitionValues: TransitionValues) {
if (transitionValues.view is LauncherIconView) {
transitionValues.values[PROP_FG_SCALE] = (transitionValues.view as LauncherIconView).foregroundScale
transitionValues.values[PROP_BG_SCALE] = (transitionValues.view as LauncherIconView).backgroundScale
}
}
override fun captureEndValues(transitionValues: TransitionValues) {
if (transitionValues.view is LauncherIconView) {
transitionValues.values[PROP_FG_SCALE] = (transitionValues.view as LauncherIconView).foregroundScale
transitionValues.values[PROP_BG_SCALE] = (transitionValues.view as LauncherIconView).backgroundScale
}
}
override fun createAnimator(sceneRoot: ViewGroup, startValues: TransitionValues?, endValues: TransitionValues?): Animator? {
if (startValues == null || endValues == null) return null
if(startValues.view !is LauncherIconView || endValues.view !is LauncherIconView) return null
val startFg = startValues.values[PROP_FG_SCALE] as Float
val endFg = endValues.values[PROP_FG_SCALE] as Float
val startBg = startValues.values[PROP_BG_SCALE] as Float
val endBg = endValues.values[PROP_BG_SCALE] as Float
return AnimatorSet().apply {
playTogether(
ObjectAnimator.ofFloat(startValues.view as LauncherIconView, "foregroundScale", startFg, endFg),
ObjectAnimator.ofFloat(startValues.view as LauncherIconView, "backgroundScale", startBg, endBg)
)
}
}
companion object {
private const val PROP_FG_SCALE = "mm20:app:launcherIconFgScale"
private const val PROP_BG_SCALE = "mm20:app:launcherIconBgScale"
private const val PROP_SIZE = "mm20:app:launcherIconSize"
}
}

View File

@ -33,10 +33,11 @@ import de.mm20.launcher2.preferences.Settings.*
import de.mm20.launcher2.preferences.Settings.AppearanceSettings.ColorScheme
import de.mm20.launcher2.preferences.Settings.AppearanceSettings.Theme
import de.mm20.launcher2.ui.R
import de.mm20.launcher2.ui.component.ShapedLauncherIcon
import de.mm20.launcher2.ui.component.getShape
import de.mm20.launcher2.ui.component.preferences.*
import de.mm20.launcher2.ui.launcher.search.SearchBar
import de.mm20.launcher2.ui.launcher.search.SearchBarLevel
import de.mm20.launcher2.ui.legacy.view.LauncherIconView
import de.mm20.launcher2.ui.locals.LocalNavController
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
@ -347,26 +348,21 @@ fun IconShapePreference(
.padding(8.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
AndroidView(factory = { context ->
LauncherIconView(context).apply {
shape = it
icon = LauncherIcon(
foreground = AppCompatResources.getDrawable(
context,
R.mipmap.ic_launcher_foreground
)!!,
background = ColorDrawable(context.getColor(R.color.ic_launcher_background))
)
setOnClickListener { _ ->
onValueChanged(it)
showDialog = false
}
layoutParams = ViewGroup.LayoutParams(
(48 * context.dp).toInt(),
(48 * context.dp).toInt(),
)
}
})
ShapedLauncherIcon(
size = 48.dp,
icon = LauncherIcon(
foreground = AppCompatResources.getDrawable(
LocalContext.current,
R.mipmap.ic_launcher_foreground
)!!,
background = ColorDrawable(LocalContext.current.getColor(R.color.ic_launcher_background))
),
onClick = {
onValueChanged(it)
showDialog = false
},
shape = getShape(it)
)
Text(
getShapeName(it) ?: "",
textAlign = TextAlign.Center,
@ -430,31 +426,25 @@ fun LegacyIconBackgroundPreference(
.padding(8.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
AndroidView(factory = { context ->
LauncherIconView(context).apply {
shape = iconShape
icon = LauncherIcon(
foreground = AppCompatResources.getDrawable(
context,
R.mipmap.ic_launcher_foreground
)!!,
background = null,
autoGenerateBackgroundMode = when (it) {
IconSettings.LegacyIconBackground.Dynamic -> LauncherIcon.BACKGROUND_DYNAMIC
IconSettings.LegacyIconBackground.None -> LauncherIcon.BACKGROUND_NONE
else -> LauncherIcon.BACKGROUND_WHITE
}
)
setOnClickListener { _ ->
onValueChanged(it)
showDialog = false
ShapedLauncherIcon(
size = 48.dp,
icon = LauncherIcon(
foreground = AppCompatResources.getDrawable(
LocalContext.current,
R.mipmap.ic_launcher_foreground
)!!,
background = null,
autoGenerateBackgroundMode = when (it) {
IconSettings.LegacyIconBackground.Dynamic -> LauncherIcon.BACKGROUND_DYNAMIC
IconSettings.LegacyIconBackground.None -> LauncherIcon.BACKGROUND_NONE
else -> LauncherIcon.BACKGROUND_WHITE
}
layoutParams = ViewGroup.LayoutParams(
(48 * context.dp).toInt(),
(48 * context.dp).toInt(),
)
),
onClick = {
onValueChanged(it)
showDialog = false
}
})
)
}
}
}