Use ShapedLauncherIcon instead of LauncherIconView in icon settings
This commit is contained in:
parent
667ec0f932
commit
983920730f
@ -165,9 +165,8 @@ fun ShapedLauncherIcon(
|
|||||||
|
|
||||||
val LocalIconShape = compositionLocalOf<Shape> { CircleShape }
|
val LocalIconShape = compositionLocalOf<Shape> { CircleShape }
|
||||||
|
|
||||||
@Composable
|
fun getShape(iconShape: IconShape): Shape {
|
||||||
fun ProvideIconShape(iconShape: IconShape, content: @Composable () -> Unit) {
|
return when (iconShape) {
|
||||||
val shape = when (iconShape) {
|
|
||||||
IconShape.PlatformDefault -> PlatformShape
|
IconShape.PlatformDefault -> PlatformShape
|
||||||
IconShape.Circle -> CircleShape
|
IconShape.Circle -> CircleShape
|
||||||
IconShape.Square -> RectangleShape
|
IconShape.Square -> RectangleShape
|
||||||
@ -179,6 +178,11 @@ fun ProvideIconShape(iconShape: IconShape, content: @Composable () -> Unit) {
|
|||||||
IconShape.EasterEgg -> EasterEggShape
|
IconShape.EasterEgg -> EasterEggShape
|
||||||
IconShape.UNRECOGNIZED -> CircleShape
|
IconShape.UNRECOGNIZED -> CircleShape
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ProvideIconShape(iconShape: IconShape, content: @Composable () -> Unit) {
|
||||||
|
val shape = getShape(iconShape)
|
||||||
CompositionLocalProvider(
|
CompositionLocalProvider(
|
||||||
LocalIconShape provides shape,
|
LocalIconShape provides shape,
|
||||||
content = content
|
content = content
|
||||||
|
|||||||
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -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.ColorScheme
|
||||||
import de.mm20.launcher2.preferences.Settings.AppearanceSettings.Theme
|
import de.mm20.launcher2.preferences.Settings.AppearanceSettings.Theme
|
||||||
import de.mm20.launcher2.ui.R
|
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.component.preferences.*
|
||||||
import de.mm20.launcher2.ui.launcher.search.SearchBar
|
import de.mm20.launcher2.ui.launcher.search.SearchBar
|
||||||
import de.mm20.launcher2.ui.launcher.search.SearchBarLevel
|
import de.mm20.launcher2.ui.launcher.search.SearchBarLevel
|
||||||
import de.mm20.launcher2.ui.legacy.view.LauncherIconView
|
|
||||||
import de.mm20.launcher2.ui.locals.LocalNavController
|
import de.mm20.launcher2.ui.locals.LocalNavController
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.isActive
|
import kotlinx.coroutines.isActive
|
||||||
@ -347,26 +348,21 @@ fun IconShapePreference(
|
|||||||
.padding(8.dp),
|
.padding(8.dp),
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
) {
|
) {
|
||||||
AndroidView(factory = { context ->
|
ShapedLauncherIcon(
|
||||||
LauncherIconView(context).apply {
|
size = 48.dp,
|
||||||
shape = it
|
icon = LauncherIcon(
|
||||||
icon = LauncherIcon(
|
foreground = AppCompatResources.getDrawable(
|
||||||
foreground = AppCompatResources.getDrawable(
|
LocalContext.current,
|
||||||
context,
|
R.mipmap.ic_launcher_foreground
|
||||||
R.mipmap.ic_launcher_foreground
|
)!!,
|
||||||
)!!,
|
background = ColorDrawable(LocalContext.current.getColor(R.color.ic_launcher_background))
|
||||||
background = ColorDrawable(context.getColor(R.color.ic_launcher_background))
|
),
|
||||||
)
|
onClick = {
|
||||||
setOnClickListener { _ ->
|
onValueChanged(it)
|
||||||
onValueChanged(it)
|
showDialog = false
|
||||||
showDialog = false
|
},
|
||||||
}
|
shape = getShape(it)
|
||||||
layoutParams = ViewGroup.LayoutParams(
|
)
|
||||||
(48 * context.dp).toInt(),
|
|
||||||
(48 * context.dp).toInt(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
Text(
|
Text(
|
||||||
getShapeName(it) ?: "",
|
getShapeName(it) ?: "",
|
||||||
textAlign = TextAlign.Center,
|
textAlign = TextAlign.Center,
|
||||||
@ -430,31 +426,25 @@ fun LegacyIconBackgroundPreference(
|
|||||||
.padding(8.dp),
|
.padding(8.dp),
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
) {
|
) {
|
||||||
AndroidView(factory = { context ->
|
ShapedLauncherIcon(
|
||||||
LauncherIconView(context).apply {
|
size = 48.dp,
|
||||||
shape = iconShape
|
icon = LauncherIcon(
|
||||||
icon = LauncherIcon(
|
foreground = AppCompatResources.getDrawable(
|
||||||
foreground = AppCompatResources.getDrawable(
|
LocalContext.current,
|
||||||
context,
|
R.mipmap.ic_launcher_foreground
|
||||||
R.mipmap.ic_launcher_foreground
|
)!!,
|
||||||
)!!,
|
background = null,
|
||||||
background = null,
|
autoGenerateBackgroundMode = when (it) {
|
||||||
autoGenerateBackgroundMode = when (it) {
|
IconSettings.LegacyIconBackground.Dynamic -> LauncherIcon.BACKGROUND_DYNAMIC
|
||||||
IconSettings.LegacyIconBackground.Dynamic -> LauncherIcon.BACKGROUND_DYNAMIC
|
IconSettings.LegacyIconBackground.None -> LauncherIcon.BACKGROUND_NONE
|
||||||
IconSettings.LegacyIconBackground.None -> LauncherIcon.BACKGROUND_NONE
|
else -> LauncherIcon.BACKGROUND_WHITE
|
||||||
else -> LauncherIcon.BACKGROUND_WHITE
|
|
||||||
}
|
|
||||||
)
|
|
||||||
setOnClickListener { _ ->
|
|
||||||
onValueChanged(it)
|
|
||||||
showDialog = false
|
|
||||||
}
|
}
|
||||||
layoutParams = ViewGroup.LayoutParams(
|
),
|
||||||
(48 * context.dp).toInt(),
|
onClick = {
|
||||||
(48 * context.dp).toInt(),
|
onValueChanged(it)
|
||||||
)
|
showDialog = false
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user