Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5ae0d284 authored by Ats Jenk's avatar Ats Jenk
Browse files

Add a bubble API to ask launcher to animate bubble bar location

Instead of updating bubble bar location in launcher while we are
dragging the expanded view, create an API to animate bubble bar to a new
location.
The animated location is transient and won't update the layout location.

Bug: 330585402
Test: drag bubbles left and right
Flag: ACONFIG com.android.wm.shell.enable_bubble_bar DEVELOPMENT
Change-Id: Idb1fddeb261ece24933e5962857c5e322ca29890
parent 403429e3
Loading
Loading
Loading
Loading
+28 −4
Original line number Diff line number Diff line
@@ -105,18 +105,21 @@ class BubbleExpandedViewPinControllerTest {
    }

    @Test
    fun onDragUpdate_stayOnSameSide() {
    fun drag_stayOnSameSide() {
        runOnMainSync {
            controller.onDragStart(initialLocationOnLeft = false)
            controller.onDragUpdate(pointOnRight.x, pointOnRight.y)
            controller.onDragEnd()
        }
        waitForAnimateIn()
        assertThat(dropTargetView).isNull()
        assertThat(testListener.locationChanges).isEmpty()
        assertThat(testListener.locationReleases).containsExactly(BubbleBarLocation.RIGHT)
    }

    @Test
    fun onDragUpdate_toLeft() {
    fun drag_toLeft() {
        // Drag to left, but don't finish
        runOnMainSync {
            controller.onDragStart(initialLocationOnLeft = false)
            controller.onDragUpdate(pointOnLeft.x, pointOnLeft.y)
@@ -132,10 +135,16 @@ class BubbleExpandedViewPinControllerTest {
            .isEqualTo(expectedDropTargetBounds.height())

        assertThat(testListener.locationChanges).containsExactly(BubbleBarLocation.LEFT)
        assertThat(testListener.locationReleases).isEmpty()

        // Finish the drag
        runOnMainSync { controller.onDragEnd() }
        assertThat(testListener.locationReleases).containsExactly(BubbleBarLocation.LEFT)
    }

    @Test
    fun onDragUpdate_toLeftAndBackToRight() {
    fun drag_toLeftAndBackToRight() {
        // Drag to left
        runOnMainSync {
            controller.onDragStart(initialLocationOnLeft = false)
            controller.onDragUpdate(pointOnLeft.x, pointOnLeft.y)
@@ -143,6 +152,7 @@ class BubbleExpandedViewPinControllerTest {
        waitForAnimateIn()
        assertThat(dropTargetView).isNotNull()

        // Drag to right
        runOnMainSync { controller.onDragUpdate(pointOnRight.x, pointOnRight.y) }
        // We have to wait for existing drop target to animate out and new to animate in
        waitForAnimateOut()
@@ -158,10 +168,15 @@ class BubbleExpandedViewPinControllerTest {

        assertThat(testListener.locationChanges)
            .containsExactly(BubbleBarLocation.LEFT, BubbleBarLocation.RIGHT)
        assertThat(testListener.locationReleases).isEmpty()

        // Release the view
        runOnMainSync { controller.onDragEnd() }
        assertThat(testListener.locationReleases).containsExactly(BubbleBarLocation.RIGHT)
    }

    @Test
    fun onDragUpdate_toLeftInExclusionRect() {
    fun drag_toLeftInExclusionRect() {
        runOnMainSync {
            controller.onDragStart(initialLocationOnLeft = false)
            // Exclusion rect is around the bottom center area of the screen
@@ -170,6 +185,10 @@ class BubbleExpandedViewPinControllerTest {
        waitForAnimateIn()
        assertThat(dropTargetView).isNull()
        assertThat(testListener.locationChanges).isEmpty()
        assertThat(testListener.locationReleases).isEmpty()

        runOnMainSync { controller.onDragEnd() }
        assertThat(testListener.locationReleases).containsExactly(BubbleBarLocation.RIGHT)
    }

    @Test
@@ -256,8 +275,13 @@ class BubbleExpandedViewPinControllerTest {

    internal class TestLocationChangeListener : BaseBubblePinController.LocationChangeListener {
        val locationChanges = mutableListOf<BubbleBarLocation>()
        val locationReleases = mutableListOf<BubbleBarLocation>()
        override fun onChange(location: BubbleBarLocation) {
            locationChanges.add(location)
        }

        override fun onRelease(location: BubbleBarLocation) {
            locationReleases.add(location)
        }
    }
}
+23 −8
Original line number Diff line number Diff line
@@ -725,6 +725,17 @@ public class BubbleController implements ConfigurationChangeListener,
        }
    }

    /**
     * Animate bubble bar to the given location. The location change is transient. It does not
     * update the state of the bubble bar.
     * To update bubble bar pinned location, use {@link #setBubbleBarLocation(BubbleBarLocation)}.
     */
    public void animateBubbleBarLocation(BubbleBarLocation bubbleBarLocation) {
        if (canShowAsBubbleBar()) {
            mBubbleStateListener.animateBubbleBarLocation(bubbleBarLocation);
        }
    }

    /** Whether this userId belongs to the current user. */
    private boolean isCurrentProfile(int userId) {
        return userId == UserHandle.USER_ALL
@@ -2250,7 +2261,6 @@ public class BubbleController implements ConfigurationChangeListener,
        private final SingleInstanceRemoteListener<BubbleController, IBubblesListener> mListener;
        private final Bubbles.BubbleStateListener mBubbleListener =
                new Bubbles.BubbleStateListener() {

                    @Override
                    public void onBubbleStateChange(BubbleBarUpdate update) {
                        Bundle b = new Bundle();
@@ -2258,6 +2268,11 @@ public class BubbleController implements ConfigurationChangeListener,
                        b.putParcelable(BubbleBarUpdate.BUNDLE_KEY, update);
                        mListener.call(l -> l.onBubbleStateChange(b));
                    }

                    @Override
                    public void animateBubbleBarLocation(BubbleBarLocation location) {
                        mListener.call(l -> l.animateBubbleBarLocation(location));
                    }
                };

        IBubblesImpl(BubbleController controller) {
+7 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.window.ScreenCapture.SynchronousScreenCaptureListener;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;

import com.android.wm.shell.common.bubbles.BubbleBarLocation;
import com.android.wm.shell.common.bubbles.BubbleBarUpdate;
import com.android.wm.shell.shared.annotations.ExternalThread;

@@ -304,6 +305,12 @@ public interface Bubbles {
         * Called when the bubbles state changes.
         */
        void onBubbleStateChange(BubbleBarUpdate update);

        /**
         * Called when bubble bar should temporarily be animated to a new location.
         * Does not result in a state change.
         */
        void animateBubbleBarLocation(BubbleBarLocation location);
    }

    /** Listener to find out about stack expansion / collapse events. */
+8 −1
Original line number Diff line number Diff line
@@ -15,8 +15,9 @@
 */

package com.android.wm.shell.bubbles;
import android.os.Bundle;

import android.os.Bundle;
import com.android.wm.shell.common.bubbles.BubbleBarLocation;
/**
 * Listener interface that Launcher attaches to SystemUI to get bubbles callbacks.
 */
@@ -26,4 +27,10 @@ oneway interface IBubblesListener {
     * Called when the bubbles state changes.
     */
    void onBubbleStateChange(in Bundle update);

    /**
     * Called when bubble bar should temporarily be animated to a new location.
     * Does not result in a state change.
     */
    void animateBubbleBarLocation(in BubbleBarLocation location);
}
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -135,9 +135,9 @@ class BubbleBarExpandedViewDragController(

        private fun finishDrag() {
            if (!isStuckToDismiss) {
                animationHelper.animateToRestPosition()
                pinController.onDragEnd()
                dragListener.onReleased(inDismiss = false)
                animationHelper.animateToRestPosition()
                dismissView.hide()
            }
            isMoving = false
Loading