Merge "Send bubble bar distance to shell" into main

This commit is contained in:
Liran Binyamin authored and Android (Google) Code Review committed 2025-05-02 14:35:40 -07:00
commit 00dc879e2c
8 files changed
+33 -44

No files matched your search

@@ -123,8 +123,7 @@ public class BubbleBarController extends IBubblesListener.Stub {
private BubbleCreator mBubbleCreator;
private BubbleBarLocationListener mBubbleBarLocationListener;
// Cache last sent top coordinate to avoid sending duplicate updates to shell
private int mLastSentBubbleBarTop;
private int mLastSentBubbleBarTopToScreenBottom;
private boolean mIsImeVisible = false;
@@ -554,8 +553,8 @@ public class BubbleBarController extends IBubblesListener.Stub {
/** Tells WMShell to show the currently selected bubble. */
public void showSelectedBubble() {
if (getSelectedBubbleKey() != null) {
mLastSentBubbleBarTop = mBarView.getRestingTopPositionOnScreen();
mSystemUiProxy.showBubble(getSelectedBubbleKey(), mLastSentBubbleBarTop);
mLastSentBubbleBarTopToScreenBottom = mBarView.getTopToScreenBottom();
mSystemUiProxy.showBubble(getSelectedBubbleKey(), mLastSentBubbleBarTopToScreenBottom);
} else {
Log.w(TAG, "Trying to show the selected bubble but it's null");
}
@@ -653,10 +652,10 @@ public class BubbleBarController extends IBubblesListener.Stub {
}
private void onBubbleBarBoundsChanged(boolean forceUpdate) {
int newTop = mBarView.getRestingTopPositionOnScreen();
if (newTop != mLastSentBubbleBarTop || forceUpdate) {
mLastSentBubbleBarTop = newTop;
mSystemUiProxy.updateBubbleBarTopOnScreen(newTop);
int bubbleBarTopToScreenBottom = mBarView.getTopToScreenBottom();
if (bubbleBarTopToScreenBottom != mLastSentBubbleBarTopToScreenBottom || forceUpdate) {
mLastSentBubbleBarTopToScreenBottom = bubbleBarTopToScreenBottom;
mSystemUiProxy.updateBubbleBarTopToScreenBottom(bubbleBarTopToScreenBottom);
}
}
@@ -652,13 +652,15 @@ public class BubbleBarView extends FrameLayout {
}
}
/**
* Get bubble bar top coordinate on screen when bar is resting
*/
public int getRestingTopPositionOnScreen() {
int displayHeight = mController.getScreenHeight();
/** Get the distance between the bubble bar top coordinate and the bottom of the screen */
public int getTopToScreenBottom() {
// the bottom of the bubble bar is aligned with the bottom of the screen. the distance
// between the top of the bubble bar and the bottom of the screen is the height of the
// bubble bar minus the y translation. since the bubble bar is always above the bottom of
// the screen, the translation is negative and the overall result is a positive value that
// represents the distance
int bubbleBarHeight = getBubbleBarBounds().height();
return displayHeight - bubbleBarHeight + (int) mController.getBubbleBarTranslationY();
return bubbleBarHeight - (int) mController.getBubbleBarTranslationY();
}
/** Returns the bounds with translation that may have been applied. */
@@ -1672,9 +1674,6 @@ public class BubbleBarView extends FrameLayout {
/** Interface for BubbleBarView to communicate with its controller. */
public interface Controller {
/** Returns the screen height. */
int getScreenHeight();
/** Returns the translation Y that the bubble bar should have. */
float getBubbleBarTranslationY();
@@ -280,11 +280,6 @@ public class BubbleBarViewController {
: PINNING_PERSISTENT;
mBubbleBarPinning.updateValue(pinningValue);
mBarView.setController(new BubbleBarView.Controller() {
@Override
public int getScreenHeight() {
return mActivity.getScreenSize().y;
}
@Override
public float getBubbleBarTranslationY() {
return mBubbleStashController.getBubbleBarTranslationY();
@@ -741,7 +736,8 @@ public class BubbleBarViewController {
public boolean isEventOverBubbleBar(MotionEvent event) {
if (!isBubbleBarVisible()) return false;
final Rect bounds = getBubbleBarBounds();
final int bubbleBarTopOnScreen = mBarView.getRestingTopPositionOnScreen();
final int bubbleBarTopOnScreen =
mActivity.getScreenSize().y - mBarView.getTopToScreenBottom();
final float x = event.getX();
return event.getRawY() >= bubbleBarTopOnScreen && x >= bounds.left && x <= bounds.right;
}
@@ -1359,7 +1355,7 @@ public class BubbleBarViewController {
* Notifies SystemUI to expand the selected bubble when the bubble is released.
*/
public void onBubbleDragRelease(BubbleBarLocation location) {
mSystemUiProxy.stopBubbleDrag(location, mBarView.getRestingTopPositionOnScreen());
mSystemUiProxy.stopBubbleDrag(location, mBarView.getTopToScreenBottom());
}
/** Handle given bubble being dismissed */
@@ -588,10 +588,13 @@ class SystemUiProxy @Inject constructor(@ApplicationContext private val context:
* Tells SysUI to show the bubble with the provided key.
*
* @param key the key of the bubble to show.
* @param top top coordinate of bubble bar on screen
* @param bubbleBarTopToScreenBottom distance between the top coordinate of bubble bar and the
* bottom of the screen
*/
fun showBubble(key: String?, top: Int) =
executeWithErrorLog({ "Failed call showBubble" }) { bubbles?.showBubble(key, top) }
fun showBubble(key: String?, bubbleBarTopToScreenBottom: Int) =
executeWithErrorLog({ "Failed call showBubble" }) {
bubbles?.showBubble(key, bubbleBarTopToScreenBottom)
}
/** Tells SysUI to remove all bubbles. */
fun removeAllBubbles() =
@@ -617,11 +620,12 @@ class SystemUiProxy @Inject constructor(@ApplicationContext private val context:
* expanded.
*
* @param location location of the bubble bar
* @param top new top coordinate for bubble bar on screen
* @param bubbleBarTopToScreenBottom distance between the new top coordinate for bubble bar and
* the bottom of the screen
*/
fun stopBubbleDrag(location: BubbleBarLocation?, top: Int) =
fun stopBubbleDrag(location: BubbleBarLocation?, bubbleBarTopToScreenBottom: Int) =
executeWithErrorLog({ "Failed call stopBubbleDrag" }) {
bubbles?.stopBubbleDrag(location, top)
bubbles?.stopBubbleDrag(location, bubbleBarTopToScreenBottom)
}
/**
@@ -657,13 +661,12 @@ class SystemUiProxy @Inject constructor(@ApplicationContext private val context:
}
/**
* Tells SysUI the top coordinate of bubble bar on screen
*
* @param topOnScreen top coordinate for bubble bar on screen
* Tells SysUI the distance between the top coordinate of the bubble bar and the bottom of the
* screen
*/
fun updateBubbleBarTopOnScreen(topOnScreen: Int) =
executeWithErrorLog({ "Failed call updateBubbleBarTopOnScreen" }) {
bubbles?.updateBubbleBarTopOnScreen(topOnScreen)
fun updateBubbleBarTopToScreenBottom(bubbleBarTopToScreenBottom: Int) =
executeWithErrorLog({ "Failed call updateBubbleBarTopToScreenBottom" }) {
bubbles?.updateBubbleBarTopToScreenBottom(bubbleBarTopToScreenBottom)
}
/**
@@ -127,8 +127,6 @@ class BubbleBarViewScreenshotTest(emulationSpec: DeviceEmulationSpec) {
bubbleBarView.setPadding(0, paddingTop, 0, 0)
bubbleBarView.setController(
object : BubbleBarView.Controller {
override fun getScreenHeight(): Int = 0
override fun getBubbleBarTranslationY(): Float = 0f
override fun onBubbleBarTouched() {}
@@ -394,8 +394,6 @@ class PersistentBubbleStashControllerTest {
bubbleBarView.layoutParams = FrameLayout.LayoutParams(0, 0)
bubbleBarView.setController(
object : BubbleBarView.Controller {
override fun getScreenHeight(): Int = 0
override fun getBubbleBarTranslationY(): Float = 0f
override fun onBubbleBarTouched() {}
@@ -559,8 +559,6 @@ class TransientBubbleStashControllerTest {
FrameLayout.LayoutParams(BUBBLE_BAR_WIDTH, BUBBLE_BAR_HEIGHT)
bubbleBarView.setController(
object : BubbleBarView.Controller {
override fun getScreenHeight(): Int = 0
override fun getBubbleBarTranslationY(): Float = 0f
override fun onBubbleBarTouched() {}
@@ -1398,8 +1398,6 @@ class BubbleBarViewAnimatorTest {
bubbleBarView = BubbleBarView(context)
bubbleBarView.setController(
object : BubbleBarView.Controller {
override fun getScreenHeight(): Int = 0
override fun getBubbleBarTranslationY(): Float = 0f
override fun onBubbleBarTouched() {}