fix: Link app drawer background opacity to correct colors (#6636)

Signed-off-by: Pun Butrach <pun.butrach@gmail.com>
This commit is contained in:
Pun Butrach authored and GitHub committed 2026-05-10 20:05:50 +08:00
1 parent b8066dc7e4
commit 0bd70f3bd0
5 files changed
+112 -43

No files matched your search

@@ -26,6 +26,7 @@ import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCH
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALLAPPS_TAP_ON_PERSONAL_TAB;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALLAPPS_TAP_ON_WORK_TAB;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
import static com.android.launcher3.util.ScrollableLayoutManager.PREDICTIVE_BACK_MIN_SCALE;
import static com.android.launcher3.views.RecyclerViewFastScroller.FastScrollerLocation.ALL_APPS_SCROLLER;
import static com.android.window.flags2.Flags.predictiveBackThreeButtonNav;
@@ -50,6 +51,7 @@ import android.os.UserManager;
import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseArray;
import android.view.CrossWindowBlurListeners;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
@@ -57,6 +59,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.ViewOutlineProvider;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.RelativeLayout;
@@ -66,6 +69,7 @@ import androidx.annotation.Px;
import androidx.annotation.VisibleForTesting;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.graphics.ColorUtils;
import androidx.core.math.MathUtils;
import androidx.core.util.Consumer;
import androidx.recyclerview.widget.RecyclerView;
@@ -114,6 +118,7 @@ import app.lawnchair.font.FontManager;
import app.lawnchair.preferences.PreferenceManager;
import app.lawnchair.preferences2.PreferenceManager2;
import app.lawnchair.theme.color.tokens.ColorTokens;
import app.lawnchair.util.LawnchairUtilsKt;
import app.lawnchair.ui.StretchRecyclerViewContainer;
/**
@@ -199,9 +204,14 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
private int mTabsProtectionAlpha;
@Nullable private AllAppsTransitionController mAllAppsTransitionController;
@Nullable private java.util.function.Consumer<Boolean> mCrossWindowBlurListener;
private final PreferenceManager2 pref2;
private final PreferenceManager pref;
// LC-Note: Allapps cache colour
private int mCachedBottomSheetBgColor;
public ActivityAllAppsContainerView(Context context) {
this(context, null);
}
@@ -346,6 +356,9 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
mBottomSheetBackgroundColorLegacy = ColorTokens.SurfaceDimColor.resolveColor(getContext());
// LC-Note: Update our allapps cached colour
updateBottomSheetBackgroundColor();
updateBackgroundVisibility(mActivityContext.getDeviceProfile());
mSearchUiManager.initializeSearch(this);
}
@@ -354,19 +367,44 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (isSearchBarFloating()) {
// Note: for Taskbar this is removed in TaskbarAllAppsController#cleanUpOverlay when the
// panel is closed. Can't do so in onDetach because we are also a child of drag layer
// so can't remove its views during that dispatch.
mActivityContext.getDragLayer().addView(mSearchContainer);
mSearchUiDelegate.onInitializeSearchBar();
}
mActivityContext.addOnDeviceProfileChangeListener(this);
if (Utilities.ATLEAST_S) {
java.util.function.Consumer<Boolean> listener = enabled -> {
if (updateBottomSheetBackgroundColor(enabled)) {
invalidate();
}
};
mCrossWindowBlurListener = listener;
UI_HELPER_EXECUTOR.execute(() -> {
try {
CrossWindowBlurListeners.getInstance()
.addListener(MAIN_EXECUTOR, listener);
} catch (Throwable t) {
// LC-Ignored
}
});
}
}
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
mActivityContext.removeOnDeviceProfileChangeListener(this);
if (mCrossWindowBlurListener != null) {
java.util.function.Consumer<Boolean> listener = mCrossWindowBlurListener;
UI_HELPER_EXECUTOR.execute(() -> {
try {
CrossWindowBlurListeners.getInstance()
.removeListener(listener);
} catch (Throwable t) {
// LC-Ignored
}
});
mCrossWindowBlurListener = null;
}
}
public SearchUiManager getSearchUiManager() {
@@ -864,22 +902,17 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
}
protected int getHeaderColor(float blendRatio) {
float opacity = 0.0f;
var showHeaderBackground = PreferenceExtensionsKt.firstBlocking(
pref2.getAppDrawerSearchBarBackground());
if (showHeaderBackground) {
opacity = pref.getDrawerOpacity().get();
}
var colorOptions = PreferenceExtensionsKt.firstBlocking(pref2.getAppDrawerBackgroundColor());
var color = colorOptions.getColorPreferenceEntry().getLightColor().invoke(mActivityContext);
if (color != 0) {
mScrimColor = color;
}
if (!mActivityContext.getDeviceProfile().shouldShowAllAppsOnSheet()) {
float opacity = mSearchContainer.getAlpha();
var showHeaderBackground = PreferenceExtensionsKt.firstBlocking(
pref2.getAppDrawerSearchBarBackground());
if (showHeaderBackground) {
opacity = pref.getDrawerOpacity().get();
}
opacity = MathUtils.clamp(opacity, 0f, 1f);
return ColorUtils.setAlphaComponent(
ColorUtils.blendARGB(mScrimColor, mHeaderProtectionColor, blendRatio),
(int) (opacity * 255));
ColorUtils.blendARGB(getBackgroundColor(), mHeaderProtectionColor, blendRatio),
Math.round(opacity * 255));
}
return isBackgroundBlurEnabled()
? ColorUtils.setAlphaComponent(mHeaderProtectionColor, (int) (blendRatio * 255))
@@ -891,15 +924,32 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
? getBottomSheetBackgroundColor() : mScrimColor;
}
// LC-Note: Hey! We cache this! see updateBottomSheetBackgroundColor() for more details.
int getBottomSheetBackgroundColor() {
return mCachedBottomSheetBgColor;
}
// LC-Note: This is getBottomSheetBackgroundColor() in AOSP, but we refactor it to cache our prefs.
private boolean updateBottomSheetBackgroundColor() {
return updateBottomSheetBackgroundColor(mActivityContext.isAllAppsBackgroundBlurEnabled());
}
// LC-Note: For listener to avoid querying stale value.
private boolean updateBottomSheetBackgroundColor(boolean blurEnabled) {
int defaultColor;
if (!Flags.allAppsBlur()) {
return mBottomSheetBackgroundColorLegacy;
defaultColor = mBottomSheetBackgroundColorLegacy;
} else if (!blurEnabled) {
defaultColor = mBottomSheetBackgroundColorBlurFallback;
} else {
defaultColor = mBottomSheetBackgroundColorOverBlur;
}
if (!mActivityContext.isAllAppsBackgroundBlurEnabled()) {
// Don't apply any alpha if the blur is disabled.
return mBottomSheetBackgroundColorBlurFallback;
int newColor = LawnchairUtilsKt.getAllAppsBackgroundColor(mActivityContext, defaultColor);
if (mCachedBottomSheetBgColor != newColor) {
mCachedBottomSheetBgColor = newColor;
return true;
}
return mBottomSheetBackgroundColorOverBlur;
return false;
}
boolean isBackgroundBlurEnabled() {
@@ -1095,9 +1145,18 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
}
updateBackgroundVisibility(dp);
boolean needsInvalidate = false;
int navBarScrimColor = Themes.getNavBarScrimColor(mActivityContext);
if (mNavBarScrimPaint.getColor() != navBarScrimColor) {
mNavBarScrimPaint.setColor(navBarScrimColor);
needsInvalidate = true;
}
// LC-Note: Update our allapps cached colour
if (updateBottomSheetBackgroundColor()) {
needsInvalidate = true;
}
if (needsInvalidate) {
invalidate();
}
}