Add support for dark tint on taskbar nav buttons

Tint the buttons when taskbar isn't drawing a background (either due to alpha or offset).

Test: Dark icons on a light wallpaper on home screen, dark icons when light IME is showing
Bug: 204256643
Change-Id: Iae634a1b604f50edc102905abd0d812a43c5346e
This commit is contained in:
Tony Wickham 2021-11-04 16:53:59 -07:00
parent b797ca77b2
commit 9ceae57095
8 changed files with 78 additions and 17 deletions

View File

@ -16,7 +16,7 @@
-->
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/taskbar_icon_selection_ripple">
android:color="@color/taskbar_nav_icon_selection_ripple">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="@android:color/white" />

View File

@ -15,7 +15,10 @@
-->
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="@dimen/taskbar_nav_buttons_size"
android:layout_height="@dimen/taskbar_nav_buttons_size"
android:background="@drawable/taskbar_icon_click_feedback_roundrect"
android:scaleType="center"/>
android:scaleType="center"
android:tint="@color/taskbar_nav_icon_light_color"
tools:ignore="UseAppTint" />

View File

@ -25,14 +25,14 @@
<!-- Taskbar -->
<color name="taskbar_background">@color/overview_scrim_dark</color>
<color name="taskbar_icon_selection_ripple">#E0E0E0</color>
<color name="taskbar_nav_icon_selection_ripple">#E0E0E0</color>
<color name="taskbar_nav_icon_light_color">#ffffff</color>
<!-- The dark navigation button color is only used in the rare cases that taskbar isn't drawing
its background and the underlying app has requested dark buttons. -->
<color name="taskbar_nav_icon_dark_color">#99000000</color>
<color name="taskbar_stashed_handle_light_color">#EBffffff</color>
<color name="taskbar_stashed_handle_dark_color">#99000000</color>
<color name="rotation_button_light_color">#FFF</color>
<color name="rotation_button_dark_color">#99000000</color>
<!-- Gesture navigation tutorial -->
<color name="gesture_tutorial_back_arrow_color">#FFFFFFFF</color>

View File

@ -15,8 +15,6 @@
*/
package com.android.launcher3.taskbar;
import static android.view.WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL;
import static com.android.launcher3.LauncherAnimUtils.VIEW_TRANSLATE_X;
import static com.android.launcher3.taskbar.TaskbarNavButtonController.BUTTON_A11Y;
import static com.android.launcher3.taskbar.TaskbarNavButtonController.BUTTON_A11Y_LONG_CLICK;
@ -36,11 +34,11 @@ import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_N
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_OVERVIEW_DISABLED;
import static com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_QUICK_SETTINGS_EXPANDED;
import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator;
import android.annotation.DrawableRes;
import android.annotation.IdRes;
import android.annotation.LayoutRes;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Rect;
import android.graphics.Region;
@ -94,7 +92,7 @@ public class NavbarButtonsViewController {
private View.OnLongClickListener mA11yLongClickListener;
private final ArrayList<StatePropertyHolder> mPropertyHolders = new ArrayList<>();
private final ArrayList<View> mAllButtons = new ArrayList<>();
private final ArrayList<ImageView> mAllButtons = new ArrayList<>();
private int mState;
private final TaskbarActivityContext mContext;
@ -103,11 +101,17 @@ public class NavbarButtonsViewController {
// Used for IME+A11Y buttons
private final ViewGroup mEndContextualContainer;
private final ViewGroup mStartContextualContainer;
private final int mLightIconColor;
private final int mDarkIconColor;
private final AnimatedFloat mTaskbarNavButtonTranslationY = new AnimatedFloat(
this::updateNavButtonTranslationY);
private final AnimatedFloat mNavButtonTranslationYMultiplier = new AnimatedFloat(
this::updateNavButtonTranslationY);
private final AnimatedFloat mTaskbarNavButtonDarkIntensity = new AnimatedFloat(
this::updateNavButtonDarkIntensity);
private final AnimatedFloat mNavButtonDarkIntensityMultiplier = new AnimatedFloat(
this::updateNavButtonDarkIntensity);
private final RotationButtonListener mRotationButtonListener = new RotationButtonListener();
private final Rect mFloatingRotationButtonBounds = new Rect();
@ -125,6 +129,9 @@ public class NavbarButtonsViewController {
mNavButtonContainer = mNavButtonsView.findViewById(R.id.end_nav_buttons);
mEndContextualContainer = mNavButtonsView.findViewById(R.id.end_contextual_buttons);
mStartContextualContainer = mNavButtonsView.findViewById(R.id.start_contextual_buttons);
mLightIconColor = context.getColor(R.color.taskbar_nav_icon_light_color);
mDarkIconColor = context.getColor(R.color.taskbar_nav_icon_dark_color);
}
/**
@ -379,6 +386,16 @@ public class NavbarButtonsViewController {
return mTaskbarNavButtonTranslationY;
}
/** Use to set the dark intensity for the all nav+contextual buttons */
public AnimatedFloat getTaskbarNavButtonDarkIntensity() {
return mTaskbarNavButtonDarkIntensity;
}
/** Use to determine whether to use the dark intensity requested by the underlying app */
public AnimatedFloat getNavButtonDarkIntensityMultiplier() {
return mNavButtonDarkIntensityMultiplier;
}
/**
* Does not call {@link #applyState()}. Don't forget to!
*/
@ -402,6 +419,16 @@ public class NavbarButtonsViewController {
* mNavButtonTranslationYMultiplier.value);
}
private void updateNavButtonDarkIntensity() {
float darkIntensity = mTaskbarNavButtonDarkIntensity.value
* mNavButtonDarkIntensityMultiplier.value;
int iconColor = (int) ArgbEvaluator.getInstance().evaluate(darkIntensity, mLightIconColor,
mDarkIconColor);
for (ImageView button : mAllButtons) {
button.setImageTintList(ColorStateList.valueOf(iconColor));
}
}
private ImageView addButton(@DrawableRes int drawableId, @TaskbarButton int buttonType,
ViewGroup parent, TaskbarNavButtonController navButtonController, @IdRes int id) {
return addButton(drawableId, buttonType, parent, navButtonController, id,

View File

@ -151,8 +151,8 @@ public class TaskbarActivityContext extends ContextThemeWrapper implements Activ
buttonController,
new NavbarButtonsViewController(this, navButtonsView),
new RotationButtonController(this,
c.getColor(R.color.rotation_button_light_color),
c.getColor(R.color.rotation_button_dark_color),
c.getColor(R.color.taskbar_nav_icon_light_color),
c.getColor(R.color.taskbar_nav_icon_dark_color),
R.drawable.ic_sysbar_rotate_button_ccw_start_0,
R.drawable.ic_sysbar_rotate_button_ccw_start_90,
R.drawable.ic_sysbar_rotate_button_cw_start_0,
@ -394,6 +394,11 @@ public class TaskbarActivityContext extends ContextThemeWrapper implements Activ
mControllers.rotationButtonController.onBehaviorChanged(displayId, behavior);
}
public void onNavButtonsDarkIntensityChanged(float darkIntensity) {
mControllers.navbarButtonsViewController.getTaskbarNavButtonDarkIntensity()
.updateValue(darkIntensity);
}
/**
* Updates the TaskbarContainer to MATCH_PARENT vs original Taskbar size.
*/

View File

@ -52,6 +52,9 @@ public class TaskbarDragLayerController {
// Initialized in init.
private TaskbarControllers mControllers;
private AnimatedFloat mNavButtonDarkIntensityMultiplier;
private float mLastSetBackgroundAlpha;
public TaskbarDragLayerController(TaskbarActivityContext activity,
TaskbarDragLayer taskbarDragLayer) {
@ -65,6 +68,9 @@ public class TaskbarDragLayerController {
mControllers = controllers;
mTaskbarDragLayer.init(new TaskbarDragLayerCallbacks());
mNavButtonDarkIntensityMultiplier = mControllers.navbarButtonsViewController
.getNavButtonDarkIntensityMultiplier();
mBgTaskbar.value = 1;
mKeyguardBgTaskbar.value = 1;
mNotificationShadeBgTaskbar.value = 1;
@ -114,13 +120,22 @@ public class TaskbarDragLayerController {
final float bgNavbar = mBgNavbar.value;
final float bgTaskbar = mBgTaskbar.value * mKeyguardBgTaskbar.value
* mNotificationShadeBgTaskbar.value;
mTaskbarDragLayer.setTaskbarBackgroundAlpha(
mBgOverride.value * Math.max(bgNavbar, bgTaskbar)
);
mLastSetBackgroundAlpha = mBgOverride.value * Math.max(bgNavbar, bgTaskbar);
mTaskbarDragLayer.setTaskbarBackgroundAlpha(mLastSetBackgroundAlpha);
updateNavBarDarkIntensityMultiplier();
}
private void updateBackgroundOffset() {
mTaskbarDragLayer.setTaskbarBackgroundOffset(mBgOffset.value);
updateNavBarDarkIntensityMultiplier();
}
private void updateNavBarDarkIntensityMultiplier() {
// Zero out the app-requested dark intensity when we're drawing our own background.
float effectiveBgAlpha = mLastSetBackgroundAlpha * (1 - mBgOffset.value);
mNavButtonDarkIntensityMultiplier.updateValue(1 - effectiveBgAlpha);
}
/**

View File

@ -42,7 +42,6 @@ import com.android.launcher3.DeviceProfile;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.statemanager.StatefulActivity;
import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.DisplayController.Info;
import com.android.launcher3.util.SettingsCache;
@ -269,6 +268,12 @@ public class TaskbarManager implements DisplayController.DisplayInfoChangeListen
}
}
public void onNavButtonsDarkIntensityChanged(float darkIntensity) {
if (mTaskbarActivityContext != null) {
mTaskbarActivityContext.onNavButtonsDarkIntensityChanged(darkIntensity);
}
}
/**
* Called when the manager is no longer needed
*/

View File

@ -289,6 +289,12 @@ public class TouchInteractionService extends Service
.onSystemBarAttributesChanged(displayId, behavior));
}
@Override
public void onNavButtonsDarkIntensityChanged(float darkIntensity) {
executeForTaskbarManager(() -> mTaskbarManager
.onNavButtonsDarkIntensityChanged(darkIntensity));
}
private void executeForTaskbarManager(final Runnable r) {
MAIN_EXECUTOR.execute(() -> {
if (mTaskbarManager == null) {