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

Commit 1f4c46c7 authored by Ats Jenk's avatar Ats Jenk
Browse files

Reuse existing handle color when switching bubbles

Allow setting initial handle color if the region sampling has not been
enabled on the bubble bar expanded view handle.
When switching between bubbles, set the initial color for the handle as
the handle color of the currently open bubble.

Bug: 276747288
Test: atest BubbleBarHandleViewTest
Test: atest WMShellMultivalentTestsOnDevice:com.android.wm.shell.bubbles.bar.BubbleBarAnimationHelperTest
Test: atest WMShellRobolectricTests:com.android.wm.shell.bubbles.bar.BubbleBarAnimationHelperTest
Flag: com.android.wm.shell.enable_bubble_bar
Change-Id: If06b73985aa0adc07ce6ded3d809d961a58bbdfd
parent 844a76e7
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -129,6 +129,24 @@ class BubbleBarAnimationHelperTest {
        assertThat(toBubble.bubbleBarExpandedView?.isSurfaceZOrderedOnTop).isFalse()
    }

    @Test
    fun animateSwitch_bubbleToBubble_handleColorTransferred() {
        val fromBubble = createBubble(key = "from").initialize(container)
        fromBubble.bubbleBarExpandedView!!
            .handleView
            .updateHandleColor(/* isRegionDark= */ true, /* animated= */ false)
        val toBubble = createBubble(key = "to").initialize(container)

        getInstrumentation().runOnMainSync {
            animationHelper.animateSwitch(fromBubble, toBubble, /* afterAnimation= */ null)
            animatorTestRule.advanceTimeBy(1000)
        }
        getInstrumentation().waitForIdleSync()

        assertThat(toBubble.bubbleBarExpandedView!!.handleView.handleColor)
            .isEqualTo(fromBubble.bubbleBarExpandedView!!.handleView.handleColor)
    }

    @Test
    fun animateSwitch_bubbleToOverflow_oldHiddenNewShown() {
        val fromBubble = createBubble(key = "from").initialize(container)
+1 −0
Original line number Diff line number Diff line
@@ -272,6 +272,7 @@ public class BubbleBarAnimationHelper {
        final float startTx = getSwitchAnimationInitialTx(endTx);
        toBbev.setTranslationX(startTx);
        toBbev.getHandleView().setAlpha(0f);
        toBbev.getHandleView().setHandleInitialColor(fromBbev.getHandleView().getHandleColor());

        toBbev.animateExpansionWhenTaskViewVisible(() -> {
            AnimatorSet switchAnim = new AnimatorSet();
+17 −1
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ public class BubbleBarHandleView extends View {
    @Nullable
    private ObjectAnimator mColorChangeAnim;
    private @ColorInt int mRegionSamplerColor;
    private boolean mHasSampledColor;

    public BubbleBarHandleView(Context context) {
        this(context, null /* attrs */);
@@ -102,7 +103,11 @@ public class BubbleBarHandleView extends View {
        invalidate();
    }

    private int getHandleColor() {
    /**
     * Get current color value for the handle
     */
    @ColorInt
    public int getHandleColor() {
        return mHandlePaint.getColor();
    }

@@ -127,6 +132,16 @@ public class BubbleBarHandleView extends View {
        invalidate();
    }

    /**
     * Set initial color for the handle. Takes effect if the
     * {@link #updateHandleColor(boolean, boolean)} has not been called.
     */
    public void setHandleInitialColor(@ColorInt int color) {
        if (!mHasSampledColor) {
            setHandleColor(color);
        }
    }

    /**
     * Updates the handle color.
     *
@@ -139,6 +154,7 @@ public class BubbleBarHandleView extends View {
        if (newColor == mRegionSamplerColor) {
            return;
        }
        mHasSampledColor = true;
        mRegionSamplerColor = newColor;
        if (mColorChangeAnim != null) {
            mColorChangeAnim.cancel();
+17 −0
Original line number Diff line number Diff line
@@ -15,9 +15,12 @@
 */
package com.android.wm.shell.bubbles.bar;

import static com.google.common.truth.Truth.assertThat;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import android.graphics.Color;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;

@@ -61,4 +64,18 @@ public class BubbleBarHandleViewTest extends ShellTestCase {
        assertEquals(handleColor,
                ContextCompat.getColor(mContext, R.color.bubble_bar_expanded_view_handle_light));
    }

    @Test
    public void testSetHandleInitialColor_beforeUpdateHandleColor_updatesColor() {
        mHandleView.setHandleInitialColor(Color.RED);
        assertThat(mHandleView.getHandleColor()).isEqualTo(Color.RED);
    }

    @Test
    public void testSetHandleInitialColor_afterUpdateHandleColor_doesNotUpdateColor() {
        mHandleView.updateHandleColor(/* isRegionDark= */ true, /* animated= */ false);
        mHandleView.setHandleInitialColor(Color.RED);
        assertThat(mHandleView.getHandleColor()).isEqualTo(
                ContextCompat.getColor(mContext, R.color.bubble_bar_expanded_view_handle_light));
    }
}