mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-01 00:06:47 +00:00
Implement light mode for persistent Taskbar.
NavbarButtonsViewController has been massaged to make sure the buttons contrast well with the color of the Taskbar background that they are on, if applicable. Test: Manual Fix: 268052229 Change-Id: I917a1a1be013c304910b0f674ae8a13abb8e47a1 Merged-In: I917a1a1be013c304910b0f674ae8a13abb8e47a1
This commit is contained in:
@@ -125,8 +125,10 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
|
||||
private static final int FLAG_SMALL_SCREEN = 1 << 13;
|
||||
private static final int FLAG_SLIDE_IN_VIEW_VISIBLE = 1 << 14;
|
||||
|
||||
/** Flags where a UI could be over a slide in view, so the color override should be disabled. */
|
||||
private static final int FLAGS_SLIDE_IN_VIEW_ICON_COLOR_OVERRIDE_DISABLED =
|
||||
/**
|
||||
* Flags where a UI could be over Taskbar surfaces, so the color override should be disabled.
|
||||
*/
|
||||
private static final int FLAGS_ON_BACKGROUND_COLOR_OVERRIDE_DISABLED =
|
||||
FLAG_NOTIFICATION_SHADE_EXPANDED | FLAG_VOICE_INTERACTION_WINDOW_SHOWING;
|
||||
|
||||
private static final String NAV_BUTTONS_SEPARATE_WINDOW_TITLE = "Taskbar Nav Buttons";
|
||||
@@ -148,8 +150,8 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
|
||||
private final ViewGroup mStartContextualContainer;
|
||||
private final int mLightIconColor;
|
||||
private final int mDarkIconColor;
|
||||
/** Color to use for navigation bar buttons, if a slide in view is visible. */
|
||||
private final int mSlideInViewIconColor;
|
||||
/** Color to use for navigation bar buttons, if they are on on a Taskbar surface background. */
|
||||
private final int mOnBackgroundIconColor;
|
||||
|
||||
private final AnimatedFloat mTaskbarNavButtonTranslationY = new AnimatedFloat(
|
||||
this::updateNavButtonTranslationY);
|
||||
@@ -160,13 +162,18 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
|
||||
// Used for System UI state updates that should translate the nav button for in-app display.
|
||||
private final AnimatedFloat mNavButtonInAppDisplayProgressForSysui = new AnimatedFloat(
|
||||
this::updateNavButtonInAppDisplayProgressForSysui);
|
||||
/** Expected nav button dark intensity communicated via the framework. */
|
||||
private final AnimatedFloat mTaskbarNavButtonDarkIntensity = new AnimatedFloat(
|
||||
this::updateNavButtonDarkIntensity);
|
||||
private final AnimatedFloat mNavButtonDarkIntensityMultiplier = new AnimatedFloat(
|
||||
this::updateNavButtonDarkIntensity);
|
||||
/** Overrides the navigation button color to {@code mSlideInViewIconColor} when {@code 1}. */
|
||||
private final AnimatedFloat mSlideInViewNavButtonColorOverride = new AnimatedFloat(
|
||||
this::updateNavButtonDarkIntensity);
|
||||
this::updateNavButtonColor);
|
||||
/** {@code 1} if the Taskbar background color is fully opaque. */
|
||||
private final AnimatedFloat mOnTaskbarBackgroundNavButtonColorOverride = new AnimatedFloat(
|
||||
this::updateNavButtonColor);
|
||||
/** {@code 1} if a Taskbar slide in overlay is visible over Taskbar. */
|
||||
private final AnimatedFloat mSlideInViewVisibleNavButtonColorOverride = new AnimatedFloat(
|
||||
this::updateNavButtonColor);
|
||||
/** Disables the {@link #mOnBackgroundIconColor} override if {@code 0}. */
|
||||
private final AnimatedFloat mOnBackgroundNavButtonColorOverrideMultiplier = new AnimatedFloat(
|
||||
this::updateNavButtonColor);
|
||||
private final RotationButtonListener mRotationButtonListener = new RotationButtonListener();
|
||||
|
||||
private final Rect mFloatingRotationButtonBounds = new Rect();
|
||||
@@ -199,8 +206,7 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
|
||||
|
||||
mLightIconColor = context.getColor(R.color.taskbar_nav_icon_light_color);
|
||||
mDarkIconColor = context.getColor(R.color.taskbar_nav_icon_dark_color);
|
||||
// Can precompute color since dark theme change recreates taskbar.
|
||||
mSlideInViewIconColor = Utilities.isDarkTheme(context) ? mLightIconColor : mDarkIconColor;
|
||||
mOnBackgroundIconColor = Utilities.isDarkTheme(context) ? mLightIconColor : mDarkIconColor;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -266,10 +272,15 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
|
||||
flags -> (flags & FLAG_IME_VISIBLE) != 0 && !isInKidsMode, AnimatedFloat.VALUE,
|
||||
transForIme, defaultButtonTransY));
|
||||
|
||||
// Start at 1 because relevant flags are unset at init.
|
||||
mOnBackgroundNavButtonColorOverrideMultiplier.value = 1;
|
||||
mPropertyHolders.add(new StatePropertyHolder(
|
||||
mSlideInViewNavButtonColorOverride,
|
||||
flags -> ((flags & FLAG_SLIDE_IN_VIEW_VISIBLE) != 0)
|
||||
&& ((flags & FLAGS_SLIDE_IN_VIEW_ICON_COLOR_OVERRIDE_DISABLED) == 0)));
|
||||
mOnBackgroundNavButtonColorOverrideMultiplier,
|
||||
flags -> (flags & FLAGS_ON_BACKGROUND_COLOR_OVERRIDE_DISABLED) == 0));
|
||||
|
||||
mPropertyHolders.add(new StatePropertyHolder(
|
||||
mSlideInViewVisibleNavButtonColorOverride,
|
||||
flags -> (flags & FLAG_SLIDE_IN_VIEW_VISIBLE) != 0));
|
||||
|
||||
if (alwaysShowButtons) {
|
||||
initButtons(mNavButtonContainer, mEndContextualContainer,
|
||||
@@ -569,9 +580,9 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
|
||||
return mTaskbarNavButtonDarkIntensity;
|
||||
}
|
||||
|
||||
/** Use to determine whether to use the dark intensity requested by the underlying app */
|
||||
public AnimatedFloat getNavButtonDarkIntensityMultiplier() {
|
||||
return mNavButtonDarkIntensityMultiplier;
|
||||
/** Use to override the nav button color with {@link #mOnBackgroundIconColor}. */
|
||||
public AnimatedFloat getOnTaskbarBackgroundNavButtonColorOverride() {
|
||||
return mOnTaskbarBackgroundNavButtonColorOverride;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -617,14 +628,20 @@ public class NavbarButtonsViewController implements TaskbarControllers.LoggableT
|
||||
+ inAppDisplayAdjustmentTranslationY);
|
||||
}
|
||||
|
||||
private void updateNavButtonDarkIntensity() {
|
||||
float darkIntensity = mTaskbarNavButtonDarkIntensity.value
|
||||
* mNavButtonDarkIntensityMultiplier.value;
|
||||
ArgbEvaluator argbEvaluator = ArgbEvaluator.getInstance();
|
||||
int iconColor = (int) argbEvaluator.evaluate(
|
||||
darkIntensity, mLightIconColor, mDarkIconColor);
|
||||
iconColor = (int) argbEvaluator.evaluate(
|
||||
mSlideInViewNavButtonColorOverride.value, iconColor, mSlideInViewIconColor);
|
||||
private void updateNavButtonColor() {
|
||||
final ArgbEvaluator argbEvaluator = ArgbEvaluator.getInstance();
|
||||
final int sysUiNavButtonIconColor = (int) argbEvaluator.evaluate(
|
||||
mTaskbarNavButtonDarkIntensity.value,
|
||||
mLightIconColor,
|
||||
mDarkIconColor);
|
||||
// Override the color from framework if nav buttons are over an opaque Taskbar surface.
|
||||
final int iconColor = (int) argbEvaluator.evaluate(
|
||||
mOnBackgroundNavButtonColorOverrideMultiplier.value
|
||||
* Math.max(
|
||||
mOnTaskbarBackgroundNavButtonColorOverride.value,
|
||||
mSlideInViewVisibleNavButtonColorOverride.value),
|
||||
sysUiNavButtonIconColor,
|
||||
mOnBackgroundIconColor);
|
||||
for (ImageView button : mAllButtons) {
|
||||
button.setImageTintList(ColorStateList.valueOf(iconColor));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user