diff --git a/lawnchair/src/app/lawnchair/preferences/PreferenceManager.kt b/lawnchair/src/app/lawnchair/preferences/PreferenceManager.kt index bd5f63a4aa..1638561eef 100644 --- a/lawnchair/src/app/lawnchair/preferences/PreferenceManager.kt +++ b/lawnchair/src/app/lawnchair/preferences/PreferenceManager.kt @@ -17,13 +17,17 @@ package app.lawnchair.preferences import android.content.Context +import android.util.Log import androidx.compose.runtime.Composable import androidx.compose.ui.platform.LocalContext import app.lawnchair.LawnchairLauncher import app.lawnchair.font.FontCache +import app.lawnchair.icons.CustomAdaptiveIconDrawable import app.lawnchair.ui.theme.LAWNCHAIR_BLUE import com.android.launcher3.InvariantDeviceProfile import com.android.launcher3.Utilities +import com.android.launcher3.graphics.IconShape +import com.android.launcher3.icons.IconProvider import com.android.launcher3.util.MainThreadInitializedObject class PreferenceManager private constructor(private val context: Context) : BasePreferenceManager(context) { @@ -85,12 +89,43 @@ class PreferenceManager private constructor(private val context: Context) : Base val allAppsIconLabels = BoolPref("pref_allAppsIconLabels", true, reloadGrid) val searchAutoShowKeyboard = BoolPref("pref_searchAutoShowKeyboard", false) val enableDebugMenu = BoolPref("pref_enableDebugMenu", false) + val customIconShape = StringPref("pref_customIconShape", "", this::onIconShapeChanged) private val fontCache = FontCache.INSTANCE.get(context) val workspaceFont = FontPref("pref_workspaceFont", fontCache.uiTextMedium, recreate) + private val maskPathMap = mapOf( + "circle" to "M50 0C77.6 0 100 22.4 100 50C100 77.6 77.6 100 50 100C22.4 100 0 77.6 0 50C0 22.4 22.4 0 50 0Z", + "roundedRect" to "M50,0L88,0 C94.4,0 100,5.4 100 12 L100,88 C100,94.6 94.6 100 88 100 L12,100 C5.4,100 0,94.6 0,88 L0 12 C0 5.4 5.4 0 12 0 L50,0 Z", + "squircle" to "M50,0 C10,0 0,10 0,50 0,90 10,100 50,100 90,100 100,90 100,50 100,10 90,0 50,0 Z", + "pebble" to "MM55,0 C25,0 0,25 0,50 0,78 28,100 55,100 85,100 100,85 100,58 100,30 86,0 55,0 Z", + ) + init { sp.registerOnSharedPreferenceChangeListener(this) + initializeIconShape() + } + + // TODO: move these somewhere else + private fun initializeIconShape() { + var maskPath = maskPathMap[customIconShape.get()] + if (maskPath == null) { + val resId = IconProvider.CONFIG_ICON_MASK_RES_ID + if (resId != 0) { + maskPath = context.getString(resId) + } + } + if (maskPath == null) { + maskPath = maskPathMap["circle"] + } + CustomAdaptiveIconDrawable.sInitialized = true + CustomAdaptiveIconDrawable.sMaskPath = maskPath + } + + private fun onIconShapeChanged() { + initializeIconShape() + IconShape.init(context) + idp.onPreferencesChanged(context) } companion object { diff --git a/lawnchair/src/app/lawnchair/ui/preferences/DebugMenuPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/DebugMenuPreferences.kt index 6a7f4d174b..b47aed5123 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/DebugMenuPreferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/DebugMenuPreferences.kt @@ -4,6 +4,8 @@ import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.runtime.Composable import androidx.navigation.NavGraphBuilder +import app.lawnchair.preferences.getAdapter +import app.lawnchair.preferences.preferenceManager import app.lawnchair.ui.preferences.components.* @ExperimentalMaterialApi @@ -19,9 +21,24 @@ fun NavGraphBuilder.debugMenuGraph(route: String) { @ExperimentalAnimationApi @Composable fun DebugMenuPreferences() { + val prefs = preferenceManager() PreferenceLayout( label = "Debug Menu" ) { - + PreferenceGroup { + ListPreference( + adapter = prefs.customIconShape.getAdapter(), + entries = iconShapeEntries, + label = "Icon Shape" + ) + } } } + +private val iconShapeEntries = listOf( + ListPreferenceEntry("") { "System" }, + ListPreferenceEntry("circle") { "Circle" }, + ListPreferenceEntry("roundedRect") { "Rounded Rectangle" }, + ListPreferenceEntry("squircle") { "Squircle" }, + ListPreferenceEntry("pebble") { "Pebble" }, +) diff --git a/platform_frameworks_libs_systemui b/platform_frameworks_libs_systemui index c7456f2f15..adf21d4abf 160000 --- a/platform_frameworks_libs_systemui +++ b/platform_frameworks_libs_systemui @@ -1 +1 @@ -Subproject commit c7456f2f15685b3ffe347acecbff70a923682b93 +Subproject commit adf21d4abfdef821dc5cb78844e3ba03945cc20a diff --git a/src/com/android/launcher3/MainProcessInitializer.java b/src/com/android/launcher3/MainProcessInitializer.java index 888dbd65c9..472519436a 100644 --- a/src/com/android/launcher3/MainProcessInitializer.java +++ b/src/com/android/launcher3/MainProcessInitializer.java @@ -29,6 +29,8 @@ import com.android.launcher3.util.ResourceBasedOverride; import org.chickenhook.restrictionbypass.Unseal; +import app.lawnchair.preferences.PreferenceManager; + /** * Utility class to handle one time initializations of the main process */ @@ -44,6 +46,7 @@ public class MainProcessInitializer implements ResourceBasedOverride { Log.e(TAG, "Unseal fail!"); e.printStackTrace(); } + PreferenceManager.getInstance(context); Overrides.getObject( MainProcessInitializer.class, context, R.string.main_process_initializer_class) .init(context);