Update placement of the nav bar in persistent taskbar for 3 button nav

Implemented nav bar placement update to be located opposite to the
bubble bar.
When bubble bar is moved to the other side of the bar, 3 button nav will
swap sides (without animation).
If taskbar has to be repositioned it does that with the animation.

Test: TaskbarViewControllerTest
Bug: 346381754
Flag: com.android.wm.shell.enable_bubble_bar
Change-Id: Id031706183c60cbd9c67537b01530acb43bae614
This commit is contained in:
mpodolian
2024-08-30 17:34:23 -07:00
parent 9074e19dad
commit 04088ebef7
11 changed files with 288 additions and 34 deletions
@@ -87,6 +87,7 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar
private final boolean mIsRtl;
private final TaskbarActivityContext mActivityContext;
@Nullable private BubbleBarLocation mBubbleBarLocation = null;
// Initialized in init.
private TaskbarViewCallbacks mControllerCallbacks;
@@ -197,7 +198,7 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar
@Override
public void onDeviceProfileChanged(DeviceProfile dp) {
mShouldTryStartAlign = mActivityContext.isThreeButtonNav() && dp.startAlignTaskbar;
mShouldTryStartAlign = mActivityContext.shouldStartAlignTaskbar();
}
@Override
@@ -494,39 +495,60 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar
icon.setOnHoverListener(mControllerCallbacks.getIconOnHoverListener(icon));
}
/** Updates taskbar icons accordingly to the new bubble bar location. */
public void onBubbleBarLocationUpdated(BubbleBarLocation location) {
if (mBubbleBarLocation == location) return;
mBubbleBarLocation = location;
requestLayout();
}
/**
* Returns translation X for the taskbar icons for provided {@link BubbleBarLocation}. If the
* bubble bar is not enabled, or location of the bubble bar is the same, or taskbar is not start
* aligned - returns 0.
*/
public float getTranslationXForBubbleBarPosition(BubbleBarLocation location) {
if (!mControllerCallbacks.isBubbleBarEnabledInPersistentTaskbar()
|| location == mBubbleBarLocation
|| !mActivityContext.shouldStartAlignTaskbar()
) {
return 0;
}
Rect iconsBounds = getIconLayoutBounds();
return getTaskBarIconsEndForBubbleBarLocation(location) - iconsBounds.right;
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
int count = getChildCount();
DeviceProfile deviceProfile = mActivityContext.getDeviceProfile();
int spaceNeeded = getIconLayoutWidth();
int navSpaceNeeded = deviceProfile.hotseatBarEndOffset;
boolean layoutRtl = isLayoutRtl();
int centerAlignIconEnd = right - (right - left - spaceNeeded) / 2;
int iconEnd;
DeviceProfile deviceProfile = mActivityContext.getDeviceProfile();
int navSpaceNeeded = deviceProfile.hotseatBarEndOffset;
int centerAlignIconEnd = (right + left + spaceNeeded) / 2;
int iconEnd = centerAlignIconEnd;
if (mShouldTryStartAlign) {
// Taskbar is aligned to the start
int startSpacingPx = deviceProfile.inlineNavButtonsEndSpacingPx;
if (layoutRtl) {
iconEnd = right - startSpacingPx;
if (mControllerCallbacks.isBubbleBarEnabledInPersistentTaskbar()
&& mBubbleBarLocation != null
&& mActivityContext.shouldStartAlignTaskbar()) {
iconEnd = (int) getTaskBarIconsEndForBubbleBarLocation(mBubbleBarLocation);
} else {
iconEnd = startSpacingPx + spaceNeeded;
if (layoutRtl) {
iconEnd = right - startSpacingPx;
} else {
iconEnd = startSpacingPx + spaceNeeded;
}
boolean needMoreSpaceForNav = layoutRtl
? navSpaceNeeded > (iconEnd - spaceNeeded)
: iconEnd > (right - navSpaceNeeded);
if (needMoreSpaceForNav) {
// Add offset to account for nav bar when taskbar is centered
int offset = layoutRtl
? navSpaceNeeded - (centerAlignIconEnd - spaceNeeded)
: (right - navSpaceNeeded) - centerAlignIconEnd;
iconEnd = centerAlignIconEnd + offset;
}
}
} else {
iconEnd = centerAlignIconEnd;
}
boolean needMoreSpaceForNav = layoutRtl
? navSpaceNeeded > (iconEnd - spaceNeeded)
: iconEnd > (right - navSpaceNeeded);
if (needMoreSpaceForNav) {
// Add offset to account for nav bar when taskbar is centered
int offset = layoutRtl
? navSpaceNeeded - (centerAlignIconEnd - spaceNeeded)
: (right - navSpaceNeeded) - centerAlignIconEnd;
iconEnd = centerAlignIconEnd + offset;
}
// Currently, we support only one device with display cutout and we only are concern about
@@ -558,6 +580,7 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar
mIconLayoutBounds.right = iconEnd;
mIconLayoutBounds.top = (bottom - top - mIconTouchSize) / 2;
mIconLayoutBounds.bottom = mIconLayoutBounds.top + mIconTouchSize;
int count = getChildCount();
for (int i = count; i > 0; i--) {
View child = getChildAt(i - 1);
if (child == mQsb) {
@@ -770,4 +793,19 @@ public class TaskbarView extends FrameLayout implements FolderIcon.FolderIconPar
}
return mAllAppsButtonContainer;
}
/**
* This method only works for bubble bar enabled in persistent task bar and the taskbar is start
* aligned.
*/
private float getTaskBarIconsEndForBubbleBarLocation(BubbleBarLocation location) {
DeviceProfile deviceProfile = mActivityContext.getDeviceProfile();
boolean navbarOnRight = location.isOnLeft(isLayoutRtl());
int navSpaceNeeded = deviceProfile.hotseatBarEndOffset;
if (navbarOnRight) {
return getWidth() - navSpaceNeeded;
} else {
return navSpaceNeeded + getIconLayoutWidth();
}
}
}