feat: Promote folder shape customisation to stable (#6701)

This commit is contained in:
Pun Butrach authored and GitHub committed 2026-04-27 14:23:36 +00:00
1 parent a64dc43be7
commit 817512351b
11 files changed
+111 -191

No files matched your search

+5 -2
View File
@@ -231,8 +231,8 @@
<string name="material_expressive_label">Material 3 Expressive</string>
<string name="material_expressive_description">Enable Material 3 Expressive changes in workspace</string>
<string name="experimental_folder_shape_modify_label">Customizable folder shape</string>
<string name="folder_shape_label">Folder</string>
<string name="folder_shape_label">Folder shape</string>
<string name="folder_label">Folder</string>
<string name="app_icon_shape_label">App</string>
<string name="gesturenavcontract_label">Use GestureNavContract API</string>
@@ -340,6 +340,9 @@
<string name="custom_icon_shape">Custom icon shape</string>
<string name="custom_icon_shape_create">Create custom icon shape</string>
<string name="custom_icon_shape_edit">Edit custom icon shape</string>
<string name="custom_folder_shape">Custom folder shape</string>
<string name="custom_folder_shape_create">Create custom folder shape</string>
<string name="custom_folder_shape_edit">Edit custom folder shape</string>
<string name="custom_icon_shape_corner">Corner shape</string>
<string name="custom_icon_shape_corner_round">Round</string>
<string name="custom_icon_shape_corner_squircle">Smooth</string>
@@ -61,6 +61,8 @@ constructor(
merge(
prefs2.iconShape.get(),
prefs2.customIconShape.get(),
prefs2.folderShape.get(),
prefs2.customFolderShape.get(),
).onEach { verifyIconState() }
.launchIn(scope)
@@ -93,30 +95,31 @@ constructor(
val currentFolderShape: IconShape = try {
prefs2.folderShape.firstBlocking()
} catch (e: Exception) {
Log.d(TAG, "Error getting icon shape", e)
Log.d(TAG, "Error getting folder shape", e)
IconShape.Circle
}
val currentPrefs1State = prefs1State()
val appShapeKey = currentAppShape.getHashString() + currentPrefs1State
val folderShapeKey = currentFolderShape.getHashString() + currentPrefs1State
val combinedKey = "$appShapeKey:$folderShapeKey"
val appShape =
if (oldState != null && oldState.iconMask == appShapeKey) {
if (oldState != null && (oldState.iconShape as? PathShapeDelegate)?.iconShape == currentAppShape) {
oldState.iconShape
} else {
PathShapeDelegate(currentAppShape)
}
val folderShape =
if (oldState != null && oldState.iconMask == folderShapeKey) {
oldState.iconShape
if (oldState != null && (oldState.folderShape as? PathShapeDelegate)?.iconShape == currentFolderShape) {
oldState.folderShape
} else {
PathShapeDelegate(currentFolderShape)
}
return IconState(
iconMask = appShapeKey,
iconMask = combinedKey,
folderRadius = 1f,
shapeRadius = 1f,
themeController = iconControllerFactory.createThemeController(),
@@ -282,6 +282,8 @@ sealed class IconShape {
// Format: v1|<topLeft>|<topRight>|<bottomLeft>|<bottomRight>
override fun toString(): String = "v$version|$topLeft|$topRight|$bottomLeft|$bottomRight"
override fun getHashString(): String = toString()
companion object {
/** Parses [value], returning null for invalid or unsupported serialized input. */
fun fromStringOrNull(value: String): CustomCornerBased? {
@@ -31,7 +31,7 @@ import com.android.launcher3.views.ClipPathView
* when the IconShape provides an SVG path string. The shape is assumed
* to be defined within a [0, 0, 100, 100] viewport.
*/
data class PathShapeDelegate(private val iconShape: IconShape) : ShapeDelegate {
data class PathShapeDelegate(val iconShape: IconShape) : ShapeDelegate {
private val basePath: Path = iconShape.getMaskPath()
private val tmpPath = Path()
@@ -164,6 +164,19 @@ class PreferenceManager2 @Inject constructor(
onSet = { it?.let(iconShape::setBlocking) },
)
val customFolderShape = preference(
key = stringPreferencesKey(name = "custom_folder_shape"),
defaultValue = null,
parse = {
IconShape.CustomCornerBased.fromStringOrNull(value = it)
?: IconShape.CustomCornerBased(
IconShapeManager.getSystemIconShape(context).findNearestShape(),
)
},
save = { it.toString() },
onSet = { it?.let(folderShape::setBlocking) },
)
val alwaysReloadIcons = preference(
key = booleanPreferencesKey(name = "always_reload_icons"),
defaultValue = context.resources.getBoolean(R.bool.config_default_always_reload_icons),
@@ -423,12 +436,6 @@ class PreferenceManager2 @Inject constructor(
},
)
val enableFolderIconShapeCustomization = preference(
key = booleanPreferencesKey(name = "enable_folder_icon_shape_customization"),
defaultValue = context.resources.getBoolean(R.bool.config_default_enable_folder_icon_shape_customization),
onSet = { reloadHelper.reloadIcons() },
)
val autoShowKeyboardInDrawer = preference(
key = booleanPreferencesKey(name = "auto_show_keyboard_in_drawer"),
defaultValue = context.resources.getBoolean(R.bool.config_default_auto_show_keyboard_in_drawer),
@@ -63,13 +63,17 @@ import kotlin.toString
@Composable
fun CustomIconShapePreference(
modifier: Modifier = Modifier,
currentTab: ShapeRoute = ShapeRoute.APP_SHAPE,
) {
val preferenceManager2 = preferenceManager2()
val customIconShapeAdapter = preferenceManager2.customIconShape.getAdapter()
val customIconShapeAdapter = when (currentTab) {
ShapeRoute.APP_SHAPE -> preferenceManager2.customIconShape.getAdapter()
ShapeRoute.FOLDER_SHAPE -> preferenceManager2.customFolderShape.getAdapter()
}
val appliedIconShape = customIconShapeAdapter.state.value
val selectedIconShape = remember {
val selectedIconShape = remember(currentTab) {
mutableStateOf(IconShape.CustomCornerBased(appliedIconShape ?: IconShape.Circle))
}
@@ -80,8 +84,13 @@ fun CustomIconShapePreference(
}
}
val label = when (currentTab) {
ShapeRoute.APP_SHAPE -> stringResource(id = R.string.custom_icon_shape)
ShapeRoute.FOLDER_SHAPE -> stringResource(id = R.string.custom_folder_shape)
}
PreferenceLayout(
label = stringResource(id = R.string.custom_icon_shape),
label = label,
modifier = modifier,
horizontalAlignment = Alignment.CenterHorizontally,
bottomBar = {
@@ -72,49 +72,6 @@ fun ExperimentalFeaturesPreferences(
Modifier,
stringResource(R.string.workspace_label),
) {
Item {
// LC-Note: The feature is pretty much ready,
// we just need some minor UI planning then we should be good to promote the feature
// to stable.
val getFolderIconShapeCustomizationAdapter = prefs2.enableFolderIconShapeCustomization.getAdapter()
val enableFolderIconShapeCustomizationAdapter = remember(prefs2) {
getFolderIconShapeCustomizationAdapter
}
val folderShapeAdapter = prefs2.folderShape.getAdapter()
val folderShapeDefault = prefs2.folderShape.defaultValue
val enabled = enableFolderIconShapeCustomizationAdapter.state.value
NavigationActionPreference(
label = stringResource(id = R.string.experimental_folder_shape_modify_label),
destination = if (enabled) GeneralIconShape(ShapeRoute.FOLDER_SHAPE) else null,
subtitle = folderIconShapeSubtitle,
endWidget = {
if (enabled) {
VerticalDivider(modifier = Modifier.padding(horizontal = 16.dp))
}
Switch(
checked = enabled,
onCheckedChange = {
mMSDLPlayerWrapper.playToken(if (it) MSDLToken.SWITCH_ON else MSDLToken.SWITCH_OFF)
enableFolderIconShapeCustomizationAdapter.onChange(it)
// Clean-up when user disables folder shape customisation.
if (!it) {
folderShapeAdapter.onChange(folderShapeDefault)
}
},
thumbContent = {
Icon(
imageVector = if (enabled) Icons.Filled.Check else Icons.Filled.Close,
contentDescription = null,
modifier = Modifier.size(SwitchDefaults.IconSize),
)
},
)
},
)
}
Item {
SwitchPreference(
adapter = prefs2.enableFontSelection.getAdapter(),
@@ -18,16 +18,19 @@ package app.lawnchair.ui.preferences.destinations
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import app.lawnchair.preferences.getAdapter
import app.lawnchair.preferences.preferenceManager
import app.lawnchair.preferences2.preferenceManager2
import app.lawnchair.ui.preferences.LocalIsExpandedScreen
import app.lawnchair.ui.preferences.components.NavigationActionPreference
import app.lawnchair.ui.preferences.components.colorpreference.ColorPreference
import app.lawnchair.ui.preferences.components.controls.SliderPreference
import app.lawnchair.ui.preferences.components.controls.SwitchPreference
import app.lawnchair.ui.preferences.components.layout.PreferenceGroup
import app.lawnchair.ui.preferences.components.layout.PreferenceLayout
import app.lawnchair.ui.preferences.navigation.GeneralIconShape
import com.android.launcher3.R
@Composable
@@ -39,9 +42,25 @@ fun FolderPreferences(
backArrowVisible = !LocalIsExpandedScreen.current,
modifier = modifier,
) {
val context = LocalContext.current
val prefs = preferenceManager()
val prefs2 = preferenceManager2()
val folderIconShapeAdapter = prefs2.folderShape.getAdapter()
val folderIconShapeSubtitle = iconShapeEntries(context)
.firstOrNull { it.value == folderIconShapeAdapter.state.value }
?.label?.invoke()
?: stringResource(id = R.string.custom)
PreferenceGroup(heading = stringResource(id = R.string.general_label)) {
Item {
NavigationActionPreference(
label = stringResource(id = R.string.folder_shape_label),
destination = GeneralIconShape(ShapeRoute.FOLDER_SHAPE),
subtitle = folderIconShapeSubtitle,
endWidget = {
IconShapePreview(iconShape = folderIconShapeAdapter.state.value)
},
)
}
Item { ColorPreference(preference = prefs2.folderColor) }
Item {
SliderPreference(
@@ -38,6 +38,7 @@ import androidx.compose.material3.RadioButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@@ -113,47 +114,51 @@ fun ShapePreference(
modifier: Modifier = Modifier,
currentTab: ShapeRoute = ShapeRoute.APP_SHAPE,
) {
val prefs2 = preferenceManager2()
if (prefs2.enableFolderIconShapeCustomization.getAdapter().state.value) {
TwoTabPreferenceLayout(
label = stringResource(id = R.string.icon_shape_label),
backArrowVisible = !LocalIsExpandedScreen.current,
defaultPage = currentTab.ordinal,
firstPageLabel = stringResource(id = R.string.app_icon_shape_label),
firstPageContent = {
AppIconShapeContent()
},
secondPageLabel = stringResource(id = R.string.folder_shape_label),
secondPageContent = {
FolderShapeContent()
},
modifier = modifier,
)
} else {
IconShapePreference()
}
TwoTabPreferenceLayout(
label = stringResource(id = R.string.icon_shape_label),
backArrowVisible = !LocalIsExpandedScreen.current,
defaultPage = currentTab.ordinal,
firstPageLabel = stringResource(id = R.string.app_icon_shape_label),
firstPageContent = {
ShapeTabContent(currentTab = ShapeRoute.APP_SHAPE)
},
secondPageLabel = stringResource(id = R.string.folder_label),
secondPageContent = {
ShapeTabContent(currentTab = ShapeRoute.FOLDER_SHAPE)
},
modifier = modifier,
)
}
@Composable
private fun AppIconShapeContent() {
private fun ShapeTabContent(currentTab: ShapeRoute) {
val context = LocalContext.current
val preferenceManager2 = preferenceManager2()
val entries = remember { iconShapeEntries(context) }
val iconShapeAdapter = preferenceManager2.iconShape.getAdapter()
val customIconShape = preferenceManager2.customIconShape.asState()
val shapeAdapter = when (currentTab) {
ShapeRoute.APP_SHAPE -> preferenceManager2.iconShape.getAdapter()
ShapeRoute.FOLDER_SHAPE -> preferenceManager2.folderShape.getAdapter()
}
val customShape by when (currentTab) {
ShapeRoute.APP_SHAPE -> preferenceManager2.customIconShape.asState()
ShapeRoute.FOLDER_SHAPE -> preferenceManager2.customFolderShape.asState()
}
PreferenceGroup(
heading = stringResource(id = R.string.custom),
) {
Item(visible = customIconShape.value != null) {
CustomIconShapePreferenceOption(
iconShapeAdapter = iconShapeAdapter,
customIconShape = customIconShape.value!!,
)
customShape?.let { shape ->
Item {
CustomIconShapePreferenceOption(
iconShapeAdapter = shapeAdapter,
customIconShape = shape,
)
}
}
Item {
ModifyCustomIconShapePreference(
customIconShape = customIconShape.value,
customIconShape = customShape,
currentTab = currentTab,
)
}
}
@@ -166,11 +171,11 @@ private fun AppIconShapeContent() {
enabled = item.enabled,
title = { Text(item.label()) },
modifier = Modifier.clickable(item.enabled) {
iconShapeAdapter.onChange(newValue = item.value)
shapeAdapter.onChange(newValue = item.value)
},
startWidget = {
RadioButton(
selected = item.value == iconShapeAdapter.state.value,
selected = item.value == shapeAdapter.state.value,
onClick = null,
enabled = item.enabled,
)
@@ -184,97 +189,6 @@ private fun AppIconShapeContent() {
}
}
@Composable
private fun FolderShapeContent() {
val context = LocalContext.current
val preferenceManager2 = preferenceManager2()
val entries = remember { iconShapeEntries(context) }
val folderShapeAdapter = preferenceManager2.folderShape.getAdapter()
PreferenceGroup(
heading = stringResource(id = R.string.presets),
) {
entries.forEach { item ->
Item {
PreferenceTemplate(
enabled = item.enabled,
title = { Text(item.label()) },
modifier = Modifier.clickable(item.enabled) {
folderShapeAdapter.onChange(newValue = item.value)
},
startWidget = {
RadioButton(
selected = item.value == folderShapeAdapter.state.value,
onClick = null,
enabled = item.enabled,
)
},
endWidget = {
IconShapePreview(iconShape = item.value)
},
)
}
}
}
}
@Composable
fun IconShapePreference(
modifier: Modifier = Modifier,
) {
val context = LocalContext.current
val preferenceManager2 = preferenceManager2()
val entries = remember { iconShapeEntries(context) }
val iconShapeAdapter = preferenceManager2.iconShape.getAdapter()
val customIconShape = preferenceManager2.customIconShape.asState()
PreferenceLayout(
label = stringResource(id = R.string.icon_shape_label),
modifier = modifier,
) {
PreferenceGroup(
heading = stringResource(id = R.string.custom),
) {
Item(visible = customIconShape.value != null) {
CustomIconShapePreferenceOption(
iconShapeAdapter = iconShapeAdapter,
customIconShape = customIconShape.value!!,
)
}
Item {
ModifyCustomIconShapePreference(
customIconShape = customIconShape.value,
)
}
}
PreferenceGroup(
heading = stringResource(id = R.string.presets),
) {
entries.forEach { item ->
Item {
PreferenceTemplate(
enabled = item.enabled,
title = { Text(item.label()) },
modifier = Modifier.clickable(item.enabled) {
iconShapeAdapter.onChange(newValue = item.value)
},
startWidget = {
RadioButton(
selected = item.value == iconShapeAdapter.state.value,
onClick = null,
enabled = item.enabled,
)
},
endWidget = {
IconShapePreview(iconShape = item.value)
},
)
}
}
}
}
}
@Composable
private fun CustomIconShapePreferenceOption(
iconShapeAdapter: PreferenceAdapter<IconShape>,
@@ -301,18 +215,20 @@ private fun CustomIconShapePreferenceOption(
@Composable
private fun ModifyCustomIconShapePreference(
customIconShape: IconShape?,
currentTab: ShapeRoute,
modifier: Modifier = Modifier,
) {
val navController = LocalNavController.current
val route = GeneralCustomIconShapeCreator
val route = GeneralCustomIconShapeCreator(selectedId = currentTab)
val created = customIconShape != null
val text = if (created) {
stringResource(id = R.string.custom_icon_shape_edit)
} else {
stringResource(id = R.string.custom_icon_shape_create)
}
val text = stringResource(
when (currentTab) {
ShapeRoute.APP_SHAPE -> if (created) R.string.custom_icon_shape_edit else R.string.custom_icon_shape_create
ShapeRoute.FOLDER_SHAPE -> if (created) R.string.custom_folder_shape_edit else R.string.custom_folder_shape_create
},
)
val icon = if (created) Icons.Rounded.Edit else Icons.Rounded.Add
@@ -42,7 +42,6 @@ import app.lawnchair.ui.preferences.destinations.HomeScreenGridPreferences
import app.lawnchair.ui.preferences.destinations.HomeScreenPreferences
import app.lawnchair.ui.preferences.destinations.IconPackPreferences
import app.lawnchair.ui.preferences.destinations.IconPickerPreference
import app.lawnchair.ui.preferences.destinations.IconShapePreference
import app.lawnchair.ui.preferences.destinations.LauncherPopupPreference
import app.lawnchair.ui.preferences.destinations.PickAppForGesture
import app.lawnchair.ui.preferences.destinations.PreferencesDashboard
@@ -122,8 +121,11 @@ fun PreferenceNavigation(
ShapePreference(currentTab = route.selectedId)
}
composable<GeneralCustomIconShapeCreator>(
deepLinks = getDeepLink(GeneralCustomIconShapeCreator),
) { CustomIconShapePreference() }
deepLinks = getDeepLink(GeneralCustomIconShapeCreator()),
) { backStackEntry ->
val route: GeneralCustomIconShapeCreator = backStackEntry.toRoute()
CustomIconShapePreference(currentTab = route.selectedId)
}
composable<HomeScreen>(
deepLinks = getDeepLink(HomeScreen),
@@ -121,7 +121,9 @@ data object GeneralIconPack : PreferenceRoute, PreferenceDeepLink {
data class GeneralIconShape(val selectedId: ShapeRoute = ShapeRoute.APP_SHAPE) : PreferenceRoute
@Serializable
data object GeneralCustomIconShapeCreator : PreferenceRoute, PreferenceDeepLink {
data class GeneralCustomIconShapeCreator(val selectedId: ShapeRoute = ShapeRoute.APP_SHAPE) :
PreferenceRoute,
PreferenceDeepLink {
override val deepLink = "$URI/general-icon-shape-creator"
}