From f628796fc636b90e2af32bb7896c91e8d959a35e Mon Sep 17 00:00:00 2001 From: Ats Jenk Date: Tue, 2 Apr 2024 16:23:45 -0700 Subject: [PATCH] Update bubble bar bounds in shell Shell keeps track of bubble bar bounds for positioning and animating the expanded view. Bubble bar location can be changed when dragging the expanded view or bubble bar itself. Previously bounds were only reported when expanding a bubble. But after adding drag support, bounds can change outside of expand action. Implement a new bubbles API to report bubble bar bounds to shell whenever they change in launcher. Keep track of last reported bounds to ensure that we only send bounds over when they change and when expand API has not already reported the bounds. Bug: 332423960 Flag: ACONFIG com.android.wm.shell.enable_bubble_bar DEVELOPMENT Test: drag expanded bubble from one side to the other, collapse it, observe that collapse animation collapses the view into the bar Change-Id: If1bf31a04b8f134a1b055fddccd276e924ed98b6 --- .../taskbar/bubbles/BubbleBarController.java | 38 ++++++++++++++----- .../bubbles/BubbleBarViewController.java | 35 +++++++++++++++-- .../com/android/quickstep/SystemUiProxy.java | 12 ++++++ 3 files changed, 72 insertions(+), 13 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarController.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarController.java index c1c76d0a01..bae30e316e 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarController.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarController.java @@ -151,6 +151,9 @@ public class BubbleBarController extends IBubblesListener.Stub { private BubbleStashController mBubbleStashController; private BubbleStashedHandleViewController mBubbleStashedHandleViewController; + // Keep track of bubble bar bounds sent to shell to avoid sending duplicate updates + private final Rect mLastSentBubbleBarBounds = new Rect(); + /** * Similar to {@link BubbleBarUpdate} but rather than {@link BubbleInfo}s it uses * {@link BubbleBarBubble}s so that it can be used to update the views. @@ -221,6 +224,7 @@ public class BubbleBarController extends IBubblesListener.Stub { !sBubbleBarEnabled || mBubbles.isEmpty()); mBubbleBarViewController.setUpdateSelectedBubbleAfterCollapse( key -> setSelectedBubbleInternal(mBubbles.get(key))); + mBubbleBarViewController.setBoundsChangeListener(this::onBubbleBarBoundsChanged); }); } @@ -426,7 +430,9 @@ public class BubbleBarController extends IBubblesListener.Stub { info.getFlags() | Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION); mSelectedBubble.getView().updateDotVisibility(true /* animate */); } - mSystemUiProxy.showBubble(getSelectedBubbleKey(), getExpandedBubbleBarDisplayBounds()); + Rect bounds = getExpandedBubbleBarDisplayBounds(); + mLastSentBubbleBarBounds.set(bounds); + mSystemUiProxy.showBubble(getSelectedBubbleKey(), bounds); } else { Log.w(TAG, "Trying to show the selected bubble but it's null"); } @@ -609,27 +615,39 @@ public class BubbleBarController extends IBubblesListener.Stub { return mIconFactory.createBadgedIconBitmap(drawable).icon; } + private void onBubbleBarBoundsChanged(Rect newBounds) { + Rect displayBounds = convertToDisplayBounds(newBounds); + // Only send bounds over if they changed + if (!displayBounds.equals(mLastSentBubbleBarBounds)) { + mLastSentBubbleBarBounds.set(displayBounds); + mSystemUiProxy.setBubbleBarBounds(displayBounds); + } + } + /** * Get bounds of the bubble bar as if it would be expanded. * Calculates the bounds instead of retrieving current view location as the view may be * animating. */ private Rect getExpandedBubbleBarDisplayBounds() { + return convertToDisplayBounds(mBarView.getBubbleBarBounds()); + } + + private Rect convertToDisplayBounds(Rect currentBarBounds) { Point displaySize = DisplayController.INSTANCE.get(mContext).getInfo().currentSize; - Rect currentBarBounds = mBarView.getBubbleBarBounds(); - Rect location = new Rect(); + Rect displayBounds = new Rect(); // currentBarBounds is only useful for distance from left or right edge. // It contains the current bounds, calculate the expanded bounds. if (mBarView.getBubbleBarLocation().isOnLeft(mBarView.isLayoutRtl())) { - location.left = currentBarBounds.left; - location.right = (int) (currentBarBounds.left + mBarView.expandedWidth()); + displayBounds.left = currentBarBounds.left; + displayBounds.right = (int) (currentBarBounds.left + mBarView.expandedWidth()); } else { - location.left = (int) (currentBarBounds.right - mBarView.expandedWidth()); - location.right = currentBarBounds.right; + displayBounds.left = (int) (currentBarBounds.right - mBarView.expandedWidth()); + displayBounds.right = currentBarBounds.right; } final int translation = (int) abs(mBubbleStashController.getBubbleBarTranslationY()); - location.top = displaySize.y - currentBarBounds.height() - translation; - location.bottom = displaySize.y - translation; - return location; + displayBounds.top = displaySize.y - currentBarBounds.height() - translation; + displayBounds.bottom = displaySize.y - translation; + return displayBounds; } } diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java index 96d91eae49..06769c530a 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java @@ -27,6 +27,7 @@ import android.view.View; import android.widget.FrameLayout; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.android.launcher3.R; import com.android.launcher3.anim.AnimatedFloat; @@ -84,6 +85,11 @@ public class BubbleBarViewController { private BubbleBarViewAnimator mBubbleBarViewAnimator; + @Nullable + private BubbleBarBoundsChangeListener mBoundsChangeListener; + + private final Rect mPreviousBubbleBarBounds = new Rect(); + public BubbleBarViewController(TaskbarActivityContext activity, BubbleBarView barView) { mActivity = activity; mBarView = barView; @@ -113,9 +119,17 @@ public class BubbleBarViewController { mBubbleBarClickListener = v -> onBubbleBarClicked(); mBubbleDragController.setupBubbleBarView(mBarView); mBarView.setOnClickListener(mBubbleBarClickListener); - mBarView.addOnLayoutChangeListener((view, i, i1, i2, i3, i4, i5, i6, i7) -> - mTaskbarInsetsController.onTaskbarOrBubblebarWindowHeightOrInsetsChanged() - ); + mBarView.addOnLayoutChangeListener( + (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> { + mTaskbarInsetsController.onTaskbarOrBubblebarWindowHeightOrInsetsChanged(); + Rect bubbleBarBounds = mBarView.getBubbleBarBounds(); + if (!bubbleBarBounds.equals(mPreviousBubbleBarBounds)) { + mPreviousBubbleBarBounds.set(bubbleBarBounds); + if (mBoundsChangeListener != null) { + mBoundsChangeListener.onBoundsChanged(bubbleBarBounds); + } + } + }); mBubbleBarViewAnimator = new BubbleBarViewAnimator(mBarView, mBubbleStashController); } @@ -426,4 +440,19 @@ public class BubbleBarViewController { public void onDismissAllBubblesWhileDragging() { mSystemUiProxy.removeAllBubbles(); } + + /** + * Set listener to be notified when bubble bar bounds have changed + */ + public void setBoundsChangeListener(@Nullable BubbleBarBoundsChangeListener listener) { + mBoundsChangeListener = listener; + } + + /** + * Listener to receive updates about bubble bar bounds changing + */ + public interface BubbleBarBoundsChangeListener { + /** Called when bounds have changed */ + void onBoundsChanged(Rect newBounds); + } } diff --git a/quickstep/src/com/android/quickstep/SystemUiProxy.java b/quickstep/src/com/android/quickstep/SystemUiProxy.java index 3c3307ac59..675ef9e1ca 100644 --- a/quickstep/src/com/android/quickstep/SystemUiProxy.java +++ b/quickstep/src/com/android/quickstep/SystemUiProxy.java @@ -821,6 +821,18 @@ public class SystemUiProxy implements ISystemUiProxy, NavHandle { } } + /** + * Tells SysUI the bounds for the bubble bar + * @param bubbleBarBounds bounds of the bubble bar in display coordinates + */ + public void setBubbleBarBounds(Rect bubbleBarBounds) { + try { + mBubbles.setBubbleBarBounds(bubbleBarBounds); + } catch (RemoteException e) { + Log.w(TAG, "Failed call setBubbleBarBounds"); + } + } + // // Splitscreen //