Skip to content

Commit

Permalink
feat : App drawer color
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSluffy committed Jan 7, 2025
1 parent 134c219 commit 66928cc
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lawnchair/res/values/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
1 change: 1 addition & 0 deletions lawnchair/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down
9 changes: 8 additions & 1 deletion lawnchair/src/app/lawnchair/util/LawnchairUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ public float[] getOverviewScaleAndOffset(Launcher launcher) {

@Override
public int getWorkspaceScrimColor(Launcher launcher) {
return LawnchairUtilsKt.getAllAppsScrimColor(launcher);
return launcher.getDeviceProfile().isTablet
? launcher.getResources().getColor(android.R.color.transparent)
: LawnchairUtilsKt.getAllAppsScrimColor(launcher);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void setValue(ActivityAllAppsContainerView<?> containerView, float v) {
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;

Expand Down Expand Up @@ -832,6 +832,11 @@ protected void updateHeaderScroll(int scrolledOffset) {

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));
Expand Down

0 comments on commit 66928cc

Please sign in to comment.