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

Commit e3b51569 authored by Josh Tsuji's avatar Josh Tsuji Committed by Android (Google) Code Review
Browse files

Merge "Don't count overflow bubble in onChildAdded/Removed." into rvc-dev

parents 5f3d66bf 259c66b8
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -471,7 +471,8 @@ public class BubbleStackView extends FrameLayout {
        mExpandedViewPadding = res.getDimensionPixelSize(R.dimen.bubble_expanded_view_padding);
        int elevation = res.getDimensionPixelSize(R.dimen.bubble_elevation);

        mStackAnimationController = new StackAnimationController(floatingContentCoordinator);
        mStackAnimationController = new StackAnimationController(
                floatingContentCoordinator, this::getBubbleCount);

        mExpandedAnimationController = new ExpandedAnimationController(
                mDisplaySize, mExpandedViewPadding, res.getConfiguration().orientation);
+17 −3
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Set;
import java.util.function.IntSupplier;

/**
 * Animation controller for bubbles when they're in their stacked state. Stacked bubbles sit atop
@@ -241,9 +242,15 @@ public class StackAnimationController extends
        }
    };

    /** Returns the number of 'real' bubbles (excluding the overflow bubble). */
    private IntSupplier mBubbleCountSupplier;

    public StackAnimationController(
            FloatingContentCoordinator floatingContentCoordinator) {
            FloatingContentCoordinator floatingContentCoordinator,
            IntSupplier bubbleCountSupplier) {
        mFloatingContentCoordinator = floatingContentCoordinator;
        mBubbleCountSupplier = bubbleCountSupplier;

    }

    /**
@@ -669,6 +676,8 @@ public class StackAnimationController extends
                new SpringAnimation(this, firstBubbleProperty)
                        .setSpring(spring)
                        .addEndListener((dynamicAnimation, b, v, v1) -> {
                            mRestingStackPosition.set(mStackPosition);

                            if (after != null) {
                                for (Runnable callback : after) {
                                    callback.run();
@@ -736,7 +745,7 @@ public class StackAnimationController extends
            return;
        }

        if (mLayout.getChildCount() == 1) {
        if (getBubbleCount() == 1) {
            // If this is the first child added, position the stack in its starting position.
            moveStackToStartPosition();
        } else if (isStackPositionSet() && mLayout.indexOfChild(child) == 0) {
@@ -758,7 +767,7 @@ public class StackAnimationController extends
                .start();

        // If there are other bubbles, pull them into the correct position.
        if (mLayout.getChildCount() > 0) {
        if (getBubbleCount() > 0) {
            animationForChildAtIndex(0).translationX(mStackPosition.x).start();
        } else {
            // When all children are removed ensure stack position is sane
@@ -979,6 +988,11 @@ public class StackAnimationController extends
        return mMagnetizedStack;
    }

    /** Returns the number of 'real' bubbles (excluding overflow). */
    private int getBubbleCount() {
        return mBubbleCountSupplier.getAsInt();
    }

    /**
     * FloatProperty that uses {@link #moveFirstBubbleWithStackFollowing} to set the first bubble's
     * translation and animate the rest of the stack with it. A DynamicAnimation can animate this
+11 −3
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import org.mockito.Mock;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.function.IntSupplier;

@SmallTest
@RunWith(AndroidTestingRunner.class)
@@ -59,7 +60,13 @@ public class StackAnimationControllerTest extends PhysicsAnimationLayoutTestCase
    @Before
    public void setUp() throws Exception {
        super.setUp();
        mStackController = spy(new TestableStackController(mFloatingContentCoordinator));
        mStackController = spy(new TestableStackController(
                mFloatingContentCoordinator, new IntSupplier() {
                    @Override
                    public int getAsInt() {
                        return mLayout.getChildCount();
                    }
                }));
        mLayout.setActiveController(mStackController);
        addOneMoreThanBubbleLimitBubbles();
        mStackOffset = mLayout.getResources().getDimensionPixelSize(R.dimen.bubble_stack_offset);
@@ -295,8 +302,9 @@ public class StackAnimationControllerTest extends PhysicsAnimationLayoutTestCase
     */
    private class TestableStackController extends StackAnimationController {
        TestableStackController(
                FloatingContentCoordinator floatingContentCoordinator) {
            super(floatingContentCoordinator);
                FloatingContentCoordinator floatingContentCoordinator,
                IntSupplier bubbleCountSupplier) {
            super(floatingContentCoordinator, bubbleCountSupplier);
        }

        @Override