feat : App drawer color

This commit is contained in:
MrSluffy
2025-01-07 14:29:00 +08:00
parent 134c2193d2
commit 66928cc74d
8 changed files with 38 additions and 3 deletions

View File

@@ -81,6 +81,9 @@
<!-- which hotseat bg color to use by default -->
<string name="config_default_hotseat_bg_color" translatable="false">default</string>
<!-- which app drawer bg color to use by default -->
<string name="config_default_app_drawer_bg_color" translatable="false">default</string>
<!-- which smartspace mode to use by default -->
<string name="config_default_smartspace_mode" translatable="false">lawnchair</string>

View File

@@ -620,6 +620,7 @@
<string name="app_drawer_columns">App drawer columns</string>
<string name="row_height_label">Row height</string>
<string name="app_drawer_indent_label">Horizontal padding</string>
<string name="app_drawer_bg_color_label">Background color</string>
<!-- HiddenAppsPreferences -->
<string name="hide_from_drawer">Hide from app drawer</string>

View File

@@ -139,6 +139,14 @@ class PreferenceManager2 private constructor(private val context: Context) : Pre
defaultValue = ColorOption.fromString(context.getString(R.string.config_default_hotseat_bg_color)),
)
val appDrawerBackgroundColor = preference(
key = stringPreferencesKey(name = "app_drawer_bg_color"),
parse = ColorOption::fromString,
save = ColorOption::toString,
onSet = { reloadHelper.reloadGrid() },
defaultValue = ColorOption.fromString(context.getString(R.string.config_default_app_drawer_bg_color)),
)
val notificationDotColor = preference(
key = stringPreferencesKey(name = "notification_dot_color"),
parse = ColorOption::fromString,

View File

@@ -31,6 +31,13 @@ class ColorPreferenceModelList(context: Context) {
dynamicEntries = dynamicColorsWithDefault,
),
)
registerModel(
ColorPreferenceModel(
prefObject = prefs.appDrawerBackgroundColor,
labelRes = R.string.app_drawer_bg_color_label,
dynamicEntries = dynamicColorsWithDefault,
),
)
registerModel(
ColorPreferenceModel(
prefObject = prefs.notificationDotColor,

View File

@@ -26,6 +26,7 @@ import app.lawnchair.preferences2.preferenceManager2
import app.lawnchair.ui.preferences.LocalIsExpandedScreen
import app.lawnchair.ui.preferences.components.NavigationActionPreference
import app.lawnchair.ui.preferences.components.SuggestionsPreference
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.DividerColumn
@@ -53,6 +54,7 @@ fun AppDrawerPreferences(
modifier = modifier,
) {
PreferenceGroup(heading = stringResource(id = R.string.general_label)) {
ColorPreference(preference = prefs2.appDrawerBackgroundColor)
SliderPreference(
label = stringResource(id = R.string.background_opacity),
adapter = prefs.drawerOpacity.getAdapter(),

View File

@@ -45,6 +45,7 @@ import androidx.core.graphics.ColorUtils
import androidx.core.os.UserManagerCompat
import app.lawnchair.preferences.PreferenceManager
import app.lawnchair.preferences2.PreferenceManager2
import app.lawnchair.theme.color.ColorOption
import app.lawnchair.theme.color.tokens.ColorTokens
import com.android.launcher3.R
import com.android.launcher3.Utilities
@@ -175,7 +176,13 @@ fun getFolderBackgroundAlpha(context: Context): Int {
fun getAllAppsScrimColor(context: Context): Int {
val opacity = PreferenceManager.getInstance(context).drawerOpacity.get()
val scrimColor = ColorTokens.AllAppsScrimColor.resolveColor(context)
val prefs2 = PreferenceManager2.getInstance(context)
var scrimColor = ColorTokens.AllAppsScrimColor.resolveColor(context)
val colorOptions: ColorOption = prefs2.appDrawerBackgroundColor.firstBlocking()
val color = colorOptions.colorPreferenceEntry.lightColor.invoke(context)
if (color != 0) {
scrimColor = color
}
val alpha = (opacity * 255).roundToInt()
return ColorUtils.setAlphaComponent(scrimColor, alpha)
}

View File

@@ -217,6 +217,8 @@ public class AllAppsState extends LauncherState {
@Override
public int getWorkspaceScrimColor(Launcher launcher) {
return LawnchairUtilsKt.getAllAppsScrimColor(launcher);
return launcher.getDeviceProfile().isTablet
? launcher.getResources().getColor(android.R.color.transparent)
: LawnchairUtilsKt.getAllAppsScrimColor(launcher);
}
}

View File

@@ -151,7 +151,7 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
protected WorkProfileManager mWorkManager;
protected final PrivateProfileManager mPrivateProfileManager;
protected final Point mFastScrollerOffset = new Point();
protected final int mScrimColor;
protected int mScrimColor;
protected final float mHeaderThreshold;
protected final AllAppsSearchUiDelegate mSearchUiDelegate;
@@ -832,6 +832,11 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
protected int getHeaderColor(float blendRatio) {
var opacity = pref.getDrawerOpacity().get();
var colorOptions = PreferenceExtensionsKt.firstBlocking(pref2.getAppDrawerBackgroundColor());
var color = colorOptions.getColorPreferenceEntry().getLightColor().invoke(mContext);
if (color != 0) {
mScrimColor = color;
}
return ColorUtils.setAlphaComponent(
ColorUtils.blendARGB(mScrimColor, mHeaderProtectionColor, blendRatio),
Math.round(opacity * 255));