Merge "Shift transient taskbar to ensure 12dp distance with the bubble bar." into main

This commit is contained in:
Mykola Podolian authored and Android (Google) Code Review committed 2025-01-13 12:52:21 -08:00
commit fc8db9afc3
9 files changed
+193 -47

No files matched your search

+1
View File
@@ -471,6 +471,7 @@
<dimen name="bubblebar_icon_spacing_persistent_taskbar">@dimen/bubblebar_icon_spacing</dimen>
<dimen name="bubblebar_expanded_icon_spacing">12dp</dimen>
<dimen name="bubblebar_icon_elevation">1dp</dimen>
<dimen name="bubblebar_transient_taskbar_min_distance">12dp</dimen>
<!-- Bubble bar dismiss view -->
<dimen name="bubblebar_dismiss_target_size">@dimen/floating_dismiss_background_size</dimen>
@@ -271,8 +271,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
mWindowManager = c.getSystemService(WindowManager.class);
// Inflate views.
final boolean isTransientTaskbar = DisplayController.isTransientTaskbar(this)
&& !isPhoneMode();
boolean isTransientTaskbar = isTransientTaskbar();
int taskbarLayout = isTransientTaskbar ? R.layout.transient_taskbar : R.layout.taskbar;
mDragLayer = (TaskbarDragLayer) mLayoutInflater.inflate(taskbarLayout, null, false);
TaskbarView taskbarView = mDragLayer.findViewById(R.id.taskbar_view);
@@ -385,6 +384,11 @@ public class TaskbarActivityContext extends BaseTaskbarContext {
dispatchDeviceProfileChanged();
}
/** Returns whether current taskbar is transient. */
public boolean isTransientTaskbar() {
return DisplayController.isTransientTaskbar(this) && !isPhoneMode();
}
/**
* Copy the original DeviceProfile, match the number of hotseat icons and qsb width and update
* the icon size
@@ -57,6 +57,7 @@ class TaskbarBackgroundRenderer(private val context: TaskbarActivityContext) {
var backgroundHeight = context.deviceProfile.taskbarHeight.toFloat()
var translationYForSwipe = 0f
var translationYForStash = 0f
var translationXForBubbleBar = 0f
private val transientBackgroundBounds = context.transientTaskbarBounds
@@ -244,12 +245,12 @@ class TaskbarBackgroundRenderer(private val context: TaskbarActivityContext) {
setColorAlphaBound(Color.BLACK, Math.round(newShadowAlpha)),
)
strokePaint.alpha = (paint.alpha * strokeAlpha) / 255
val currentTranslationX = translationXForBubbleBar * progress
lastDrawnTransientRect.set(
transientBackgroundBounds.left + halfWidthDelta,
transientBackgroundBounds.left + halfWidthDelta + currentTranslationX,
bottom - newBackgroundHeight,
transientBackgroundBounds.right - halfWidthDelta,
bottom
transientBackgroundBounds.right - halfWidthDelta + currentTranslationX,
bottom,
)
val horizontalInset = fullWidth * widthInsetPercentage
lastDrawnTransientRect.inset(horizontalInset, 0f)
@@ -254,6 +254,11 @@ public class TaskbarDragLayer extends BaseDragLayer<TaskbarActivityContext> {
invalidate();
}
protected void setBackgroundTranslationXForBubbleBar(float translationX) {
mBackgroundRenderer.setTranslationXForBubbleBar(translationX);
invalidate();
}
/** Returns the bounds in DragLayer coordinates of where the transient background was drawn. */
protected RectF getLastDrawnTransientRect() {
return mBackgroundRenderer.getLastDrawnTransientRect();
@@ -197,6 +197,13 @@ public class TaskbarDragLayerController implements TaskbarControllers.LoggableTa
mTaskbarDragLayer.setBackgroundTranslationYForSwipe(transY);
}
/**
* Sets the translation of the background for the bubble bar.
*/
public void setTranslationXForBubbleBar(float transX) {
mTaskbarDragLayer.setBackgroundTranslationXForBubbleBar(transX);
}
/**
* Sets the translation of the background during the spring on stash animation.
*/
@@ -40,6 +40,7 @@ import static com.android.launcher3.taskbar.TaskbarPinningController.PINNING_TRA
import static com.android.launcher3.taskbar.bubbles.BubbleBarView.FADE_IN_ANIM_ALPHA_DURATION_MS;
import static com.android.launcher3.taskbar.bubbles.BubbleBarView.FADE_OUT_ANIM_POSITION_DURATION_MS;
import static com.android.launcher3.util.MultiPropertyFactory.MULTI_PROPERTY_VALUE;
import static com.android.launcher3.util.MultiTranslateDelegate.INDEX_BUBBLE_BAR_ANIM;
import static com.android.launcher3.util.MultiTranslateDelegate.INDEX_NAV_BAR_ANIM;
import static com.android.launcher3.util.MultiTranslateDelegate.INDEX_TASKBAR_ALIGNMENT_ANIM;
import static com.android.launcher3.util.MultiTranslateDelegate.INDEX_TASKBAR_PINNING_ANIM;
@@ -81,6 +82,7 @@ import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.TaskItemInfo;
import com.android.launcher3.taskbar.bubbles.BubbleBarController;
import com.android.launcher3.taskbar.bubbles.BubbleControllers;
import com.android.launcher3.util.DisplayController;
import com.android.launcher3.util.ItemInfoMatcher;
import com.android.launcher3.util.LauncherBindableItemsContainer;
@@ -109,6 +111,8 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar
private static final Runnable NO_OP = () -> { };
public static long TRANSLATION_X_FOR_BUBBLEBAR_ANIM_DURATION_MS = 250;
public static final int ALPHA_INDEX_HOME = 0;
public static final int ALPHA_INDEX_KEYGUARD = 1;
public static final int ALPHA_INDEX_STASH = 2;
@@ -132,6 +136,7 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar
private static final int TRANSITION_FADE_OUT_DURATION = 83;
private final TaskbarActivityContext mActivity;
private @Nullable TaskbarDragLayerController mDragLayerController;
private final TaskbarView mTaskbarView;
private final MultiValueAlpha mTaskbarIconAlpha;
private final AnimatedFloat mTaskbarIconScaleForStash = new AnimatedFloat(this::updateScale);
@@ -144,15 +149,22 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar
this::updateTaskbarIconsScale);
private final AnimatedFloat mTaskbarIconTranslationXForPinning = new AnimatedFloat(
this::updateTaskbarIconTranslationXForPinning);
() -> updateTaskbarIconTranslationXForPinning());
private final AnimatedFloat mIconsTranslationXForNavbar = new AnimatedFloat(
this::updateTranslationXForNavBar);
private final AnimatedFloat mTranslationXForBubbleBar = new AnimatedFloat(
this::updateTranslationXForBubbleBar);
@Nullable
private Animator mTaskbarShiftXAnim;
@Nullable
private BubbleBarLocation mCurrentBubbleBarLocation;
@Nullable
private BubbleControllers mBubbleControllers = null;
@Nullable
private ObjectAnimator mTranslationXAnimation;
private final AnimatedFloat mTaskbarIconTranslationYForPinning = new AnimatedFloat(
this::updateTranslationY);
@@ -174,11 +186,12 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar
private final View.OnLayoutChangeListener mTaskbarViewLayoutChangeListener =
(v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
if (!taskbarRecentsLayoutTransition()) {
updateTaskbarIconTranslationXForPinning();
}
if (BubbleBarController.isBubbleBarEnabled()) {
mControllers.navbarButtonsViewController.onLayoutsUpdated();
// update shiftX is handled with the animation at the end of the method
updateTaskbarIconTranslationXForPinning(/* updateShiftXForBubbleBar = */ false);
}
if (mBubbleControllers == null) return;
mControllers.navbarButtonsViewController.onLayoutsUpdated();
adjustTaskbarXForBubbleBar();
};
// Animation to align icons with Launcher, created lazily. This allows the controller to be
@@ -222,11 +235,11 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar
mIsRtl = Utilities.isRtl(mTaskbarView.getResources());
mTaskbarLeftRightMargin = mActivity.getResources().getDimensionPixelSize(
R.dimen.transient_taskbar_padding);
}
public void init(TaskbarControllers controllers) {
mControllers = controllers;
controllers.bubbleControllers.ifPresent(bc -> mBubbleControllers = bc);
mTaskbarView.init(TaskbarViewCallbacksFactory.newInstance(mActivity).create(
mActivity, mControllers, mTaskbarView));
mTaskbarView.getLayoutParams().height = mActivity.isPhoneMode()
@@ -252,7 +265,7 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar
controllers.navbarButtonsViewController.getTaskbarNavButtonTranslationY();
mTaskbarNavButtonTranslationYForInAppDisplay = controllers.navbarButtonsViewController
.getTaskbarNavButtonTranslationYForInAppDisplay();
mDragLayerController = controllers.taskbarDragLayerController;
mActivity.addOnDeviceProfileChangeListener(mDeviceProfileChangeListener);
if (ENABLE_TASKBAR_NAVBAR_UNIFICATION) {
@@ -270,24 +283,59 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar
@Override
public void onBubbleBarLocationUpdated(BubbleBarLocation location) {
updateCurrentBubbleBarLocation(location);
if (!shouldMoveTaskbarOnBubbleBarLocationUpdate()) return;
cancelTaskbarShiftAnimation();
// reset translation x, taskbar will position icons with the updated location
mIconsTranslationXForNavbar.updateValue(0);
mTaskbarView.onBubbleBarLocationUpdated(location);
if (mActivity.isTransientTaskbar()) {
translateTaskbarXForBubbleBar(/* animate= */ false);
} else if (mActivity.shouldStartAlignTaskbar()) {
cancelTaskbarShiftAnimation();
// reset translation x, taskbar will position icons with the updated location
mIconsTranslationXForNavbar.updateValue(0);
mTaskbarView.onBubbleBarLocationUpdated(location);
}
}
/** Animates start aligned taskbar accordingly to the bubble bar position. */
@Override
public void onBubbleBarLocationAnimated(BubbleBarLocation location) {
if (!updateCurrentBubbleBarLocation(location)
|| !shouldMoveTaskbarOnBubbleBarLocationUpdate()) {
return;
boolean locationUpdated = updateCurrentBubbleBarLocation(location);
if (mActivity.isTransientTaskbar()) {
translateTaskbarXForBubbleBar(/* animate= */ true);
} else if (locationUpdated && mActivity.shouldStartAlignTaskbar()) {
cancelTaskbarShiftAnimation();
float translationX = mTaskbarView.getTranslationXForBubbleBarPosition(location);
mTaskbarShiftXAnim = createTaskbarIconsShiftAnimator(translationX);
mTaskbarShiftXAnim.start();
}
cancelTaskbarShiftAnimation();
float translationX = mTaskbarView.getTranslationXForBubbleBarPosition(location);
mTaskbarShiftXAnim = createTaskbarIconsShiftAnimator(translationX);
mTaskbarShiftXAnim.start();
}
private void translateTaskbarXForBubbleBar(boolean animate) {
cancelCurrentTranslationXAnimation();
if (!mActivity.isTransientTaskbar()) return;
int shiftX = getTransientTaskbarShiftXForBubbleBar();
if (animate) {
mTranslationXAnimation = mTranslationXForBubbleBar.animateToValue(shiftX);
mTranslationXAnimation.setInterpolator(EMPHASIZED);
mTranslationXAnimation.setDuration(TRANSLATION_X_FOR_BUBBLEBAR_ANIM_DURATION_MS);
mTranslationXAnimation.start();
} else {
mTranslationXForBubbleBar.updateValue(shiftX);
}
}
private void cancelCurrentTranslationXAnimation() {
if (mTranslationXAnimation != null) {
if (mTranslationXAnimation.isRunning()) {
mTranslationXAnimation.cancel();
}
mTranslationXAnimation = null;
}
}
private int getTransientTaskbarShiftXForBubbleBar() {
if (mBubbleControllers == null || !mActivity.isTransientTaskbar()) {
return 0;
}
return mBubbleControllers.bubbleBarViewController
.getTransientTaskbarTranslationXForBubbleBar(mCurrentBubbleBarLocation);
}
/** Updates the mCurrentBubbleBarLocation, returns {@code} true if location is updated. */
@@ -300,13 +348,6 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar
}
}
/** Returns whether taskbar should be moved on the bubble bar location update. */
private boolean shouldMoveTaskbarOnBubbleBarLocationUpdate() {
return mControllers.bubbleControllers.isPresent()
&& mActivity.shouldStartAlignTaskbar()
&& mActivity.isThreeButtonNav();
}
private void cancelTaskbarShiftAnimation() {
if (mTaskbarShiftXAnim != null) {
mTaskbarShiftXAnim.cancel();
@@ -450,16 +491,26 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar
}
void updateTaskbarIconTranslationXForPinning() {
updateTaskbarIconTranslationXForPinning(/* updateShiftXForBubbleBar = */ true);
}
void updateTaskbarIconTranslationXForPinning(boolean updateShiftXForBubbleBar) {
View[] iconViews = mTaskbarView.getIconViews();
float scale = mTaskbarIconTranslationXForPinning.value;
float transientTaskbarAllAppsOffset = mActivity.getResources().getDimension(
mTaskbarView.getAllAppsButtonContainer().getAllAppsButtonTranslationXOffset(true));
float persistentTaskbarAllAppsOffset = mActivity.getResources().getDimension(
mTaskbarView.getAllAppsButtonContainer().getAllAppsButtonTranslationXOffset(false));
if (mBubbleControllers != null && updateShiftXForBubbleBar) {
cancelCurrentTranslationXAnimation();
int translationXForTransientTaskbar = mBubbleControllers.bubbleBarViewController
.getTransientTaskbarTranslationXForBubbleBar(mCurrentBubbleBarLocation);
float currentTranslationXForTransientTaskbar = mapRange(scale,
translationXForTransientTaskbar, 0);
mTranslationXForBubbleBar.updateValue(currentTranslationXForTransientTaskbar);
}
float allAppIconTranslateRange = mapRange(scale, transientTaskbarAllAppsOffset,
persistentTaskbarAllAppsOffset);
// Task icons are laid out so the taskbar content is centered. The taskbar width (used for
// centering taskbar icons) depends on the all apps button X translation, and is different
// for persistent and transient taskbar. If the offset used for current taskbar layout is
@@ -551,13 +602,23 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar
}
private void updateTranslationXForNavBar() {
updateIconViewsTranslationX(INDEX_NAV_BAR_ANIM, mIconsTranslationXForNavbar.value);
}
private void updateTranslationXForBubbleBar() {
float translationX = mTranslationXForBubbleBar.value;
updateIconViewsTranslationX(INDEX_BUBBLE_BAR_ANIM, translationX);
if (mDragLayerController != null) {
mDragLayerController.setTranslationXForBubbleBar(translationX);
}
}
private void updateIconViewsTranslationX(int translationXChannel, float translationX) {
View[] iconViews = mTaskbarView.getIconViews();
float translationX = mIconsTranslationXForNavbar.value;
for (int iconIndex = 0; iconIndex < iconViews.length; iconIndex++) {
View iconView = iconViews[iconIndex];
for (View iconView : iconViews) {
MultiTranslateDelegate translateDelegate =
((Reorderable) iconView).getTranslateDelegate();
translateDelegate.getTranslationX(INDEX_NAV_BAR_ANIM).setValue(translationX);
translateDelegate.getTranslationX(translationXChannel).setValue(translationX);
}
}
@@ -811,6 +872,13 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar
if (mTaskbarView.updateMaxNumIcons()) {
commitRunningAppsToUI();
}
adjustTaskbarXForBubbleBar();
}
private void adjustTaskbarXForBubbleBar() {
if (mBubbleControllers != null && mActivity.isTransientTaskbar()) {
translateTaskbarXForBubbleBar(/* animate= */ true);
}
}
/**
@@ -841,7 +909,17 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar
setter.setFloat(mTaskbarIconTranslationYForHome, VALUE, -offsetY, interpolator);
setter.setFloat(mTaskbarNavButtonTranslationY, VALUE, -offsetY, interpolator);
setter.setFloat(mTaskbarNavButtonTranslationYForInAppDisplay, VALUE, offsetY, interpolator);
if (mBubbleControllers != null
&& mCurrentBubbleBarLocation != null
&& mActivity.isTransientTaskbar()) {
int offsetX = mBubbleControllers.bubbleBarViewController
.getTransientTaskbarTranslationXForBubbleBar(mCurrentBubbleBarLocation);
if (offsetX != 0) {
// if taskbar should be adjusted for the bubble bar adjust the taskbar translation
mTranslationXForBubbleBar.updateValue(offsetX);
setter.setFloat(mTranslationXForBubbleBar, VALUE, 0, interpolator);
}
}
int collapsedHeight = mActivity.getDefaultTaskbarWindowSize();
int expandedHeight = Math.max(collapsedHeight, taskbarDp.taskbarHeight + offsetY);
setter.addOnFrameListener(anim -> mActivity.setTaskbarWindowSize(
@@ -1042,8 +1120,8 @@ public class TaskbarViewController implements TaskbarControllers.LoggableTaskbar
}
private boolean bubbleBarHasBubbles() {
return mControllers.bubbleControllers.isPresent()
&& mControllers.bubbleControllers.get().bubbleBarViewController.hasBubbles();
return mBubbleControllers != null
&& mBubbleControllers.bubbleBarViewController.hasBubbles();
}
public void onRotationChanged(DeviceProfile deviceProfile) {
@@ -1339,6 +1339,14 @@ public class BubbleBarView extends FrameLayout {
return getScaledIconSize() + mIconOverlapAmount + 2 * mBubbleBarPadding;
}
float getCollapsedWidthForIconSizeAndPadding(int iconSize, int bubbleBarPadding) {
final int bubbleChildCount = Math.min(getBubbleChildCount(), MAX_VISIBLE_BUBBLES_COLLAPSED);
if (bubbleChildCount == 0) return 0;
final int spacesCount = bubbleChildCount - 1;
final float horizontalPadding = 2 * bubbleBarPadding;
return iconSize * bubbleChildCount + mIconOverlapAmount * spacesCount + horizontalPadding;
}
/** Returns the child count excluding the overflow if it's present. */
int getBubbleChildCount() {
return hasOverflow() ? getChildCount() - 1 : getChildCount();
@@ -122,7 +122,8 @@ public class BubbleBarViewController {
private float mBubbleBarSwipeUpTranslationY;
// Modified when bubble bar is springing back into the stash handle.
private float mBubbleBarStashTranslationY;
// Minimum distance between the BubbleBar and the taskbar
private final int mBubbleBarTaskbarMinDistance;
// Whether the bar is hidden for a sysui state.
private boolean mHiddenForSysui;
// Whether the bar is hidden because there are no bubbles.
@@ -150,10 +151,11 @@ public class BubbleBarViewController {
mBubbleBarContainer = bubbleBarContainer;
mSystemUiProxy = SystemUiProxy.INSTANCE.get(mActivity);
mBubbleBarAlpha = new MultiValueAlpha(mBarView, 1 /* num alpha channels */);
mIconSize = activity.getResources().getDimensionPixelSize(
R.dimen.bubblebar_icon_size);
mDragElevation = activity.getResources().getDimensionPixelSize(
R.dimen.bubblebar_drag_elevation);
Resources res = activity.getResources();
mIconSize = res.getDimensionPixelSize(R.dimen.bubblebar_icon_size);
mBubbleBarTaskbarMinDistance = res.getDimensionPixelSize(
R.dimen.bubblebar_transient_taskbar_min_distance);
mDragElevation = res.getDimensionPixelSize(R.dimen.bubblebar_drag_elevation);
mTaskbarTranslationDelta = getBubbleBarTranslationDeltaForTaskbar(activity);
}
@@ -664,6 +666,45 @@ public class BubbleBarViewController {
}
}
/**
* Returns the translation X of the transient taskbar according to the bubble bar location
* regardless of the current taskbar mode.
*/
public int getTransientTaskbarTranslationXForBubbleBar(BubbleBarLocation location) {
int taskbarShift = 0;
if (!isBubbleBarVisible() || mTaskbarViewPropertiesProvider == null) return taskbarShift;
Rect taskbarViewBounds = mTaskbarViewPropertiesProvider.getTaskbarViewBounds();
if (taskbarViewBounds.isEmpty()) return taskbarShift;
int actualDistance =
getDistanceBetweenTransientTaskbarAndBubbleBar(location, taskbarViewBounds);
if (actualDistance < mBubbleBarTaskbarMinDistance) {
taskbarShift = mBubbleBarTaskbarMinDistance - actualDistance;
if (!location.isOnLeft(mBarView.isLayoutRtl())) {
taskbarShift = -taskbarShift;
}
}
return taskbarShift;
}
private int getDistanceBetweenTransientTaskbarAndBubbleBar(BubbleBarLocation location,
Rect taskbarViewBounds) {
Resources res = mActivity.getResources();
DeviceProfile transientDp = mActivity.getTransientTaskbarDeviceProfile();
int transientIconSize = getBubbleBarIconSizeFromDeviceProfile(res, transientDp);
int transientPadding = getBubbleBarPaddingFromDeviceProfile(res, transientDp);
int transientWidthWithMargin = (int) (mBarView.getCollapsedWidthForIconSizeAndPadding(
transientIconSize, transientPadding) + mBarView.getHorizontalMargin());
int distance;
if (location.isOnLeft(mBarView.isLayoutRtl())) {
distance = taskbarViewBounds.left - transientWidthWithMargin;
} else {
int displayWidth = res.getDisplayMetrics().widthPixels;
int bubbleBarLeft = displayWidth - transientWidthWithMargin;
distance = bubbleBarLeft - taskbarViewBounds.right;
}
return distance;
}
//
// Modifying view related properties.
//
@@ -38,6 +38,7 @@ public class MultiTranslateDelegate {
public static final int INDEX_TASKBAR_REVEAL_ANIM = 4;
public static final int INDEX_TASKBAR_PINNING_ANIM = 5;
public static final int INDEX_NAV_BAR_ANIM = 6;
public static final int INDEX_BUBBLE_BAR_ANIM = 7;
// Affect all items inside of a MultipageCellLayout
public static final int INDEX_CELLAYOUT_MULTIPAGE_SPACING = 3;
@@ -48,7 +49,7 @@ public class MultiTranslateDelegate {
// Specific for hotseat items when adjusting for bubbles
public static final int INDEX_BUBBLE_ADJUSTMENT_ANIM = 3;
public static final int COUNT = 7;
public static final int COUNT = 8;
private final MultiPropertyFactory<View> mTranslationX;
private final MultiPropertyFactory<View> mTranslationY;