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

Commit c8aa3a6c authored by Liran Binyamin's avatar Liran Binyamin
Browse files

Bubble bar expanded view handle menu fixes

1. Notify the menu view controller listener that the menu is visible
   at the start rather than at the end. This ensures that the task
   view is setting an obscured area so it doesn't process touches
   while the menu is animating in.

2. Set the handle menu alpha to 1 at the beginning of the expansion
   animation. As part of the switch animation, we set the alpha of
   the handle for the bubble we are switching from to 0.

Also added a unit test for BubbleBarMenuViewController

Flag: com.android.wm.shell.enable_bubble_bar
Fixes: 399153287
Fixes: 397710596
Test: atest BubbleBarMenuViewController
Test: manual
       - have 2 bubbles in the bar
       - tap on the bar to expand
       - tap on other bubble to switch
       - tap on handle menu and dismiss bubble
       - observe handle is visible in the newly selected bubble
Test: manual
       - expand bubble bar
       - tap on handle menu and quickly try to tap on an item
          - easier to test by changing the animation durations
       - observe touch is handled correctly
Change-Id: I11c170f6293b5a24534933a6c19ef64d1b2de2f7
parent a6383fb7
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -9,6 +9,9 @@
        <activity android:name="com.android.wm.shell.bubbles.bar.BubbleBarAnimationHelperTest$TestActivity"
            android:exported="true"/>

        <activity android:name="com.android.wm.shell.bubbles.bar.BubbleBarMenuViewControllerTest$TestActivity"
            android:exported="true"/>

        <activity android:name=".bubbles.TestActivity"
            android:allowEmbedded="true"
            android:documentLaunchMode="always"
+2 −0
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@
    <application>
        <activity android:name="com.android.wm.shell.bubbles.bar.BubbleBarAnimationHelperTest$TestActivity"
            android:exported="true"/>
        <activity android:name="com.android.wm.shell.bubbles.bar.BubbleBarMenuViewControllerTest$TestActivity"
            android:exported="true"/>
    </application>
</manifest>
+128 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.wm.shell.bubbles.bar

import android.animation.AnimatorTestRule
import android.app.Activity
import android.content.Context
import android.os.Bundle
import android.widget.FrameLayout
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import androidx.test.platform.app.InstrumentationRegistry
import com.android.wm.shell.bubbles.Bubble
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

/** Tests for [BubbleBarMenuViewController]. */
@SmallTest
@RunWith(AndroidJUnit4::class)
class BubbleBarMenuViewControllerTest {

    @get:Rule
    val animatorTestRule: AnimatorTestRule = AnimatorTestRule(this)
    private lateinit var activityScenario: ActivityScenario<TestActivity>
    private val context = ApplicationProvider.getApplicationContext<Context>()

    private lateinit var menuViewController: BubbleBarMenuViewController
    private val listener = TestListener()
    private lateinit var container: FrameLayout

    @Before
    fun setUp() {
        activityScenario = ActivityScenario.launch(TestActivity::class.java)
        activityScenario.onActivity { activity -> container = activity.container }
        val handleView = BubbleBarHandleView(context)
        menuViewController = BubbleBarMenuViewController(context, handleView, container)
        menuViewController.setListener(listener)
    }

    @Test
    fun showMenu_immediatelyUpdatesVisibility() {
        activityScenario.onActivity {
            menuViewController.showMenu(/* animated= */ true)
        }
        InstrumentationRegistry.getInstrumentation().waitForIdleSync()
        assertThat(listener.visible).isTrue()

        // advance the animator timer since the actual visibility of the menu is updated in the
        // middle of the animation
        activityScenario.onActivity {
            animatorTestRule.advanceTimeBy(600)
        }
        assertThat(menuViewController.isMenuVisible).isTrue()
    }

    @Test
    fun hideMenu_updatesVisibilityAfterAnimationEnds() {
        activityScenario.onActivity {
            menuViewController.showMenu(/* animated= */ true)
        }
        InstrumentationRegistry.getInstrumentation().waitForIdleSync()
        assertThat(listener.visible).isTrue()

        activityScenario.onActivity {
            animatorTestRule.advanceTimeBy(600)
        }
        assertThat(menuViewController.isMenuVisible).isTrue()

        activityScenario.onActivity {
            menuViewController.hideMenu(/* animated= */ true)
        }
        InstrumentationRegistry.getInstrumentation().waitForIdleSync()

        // check that the listener hasn't been notified yet
        assertThat(listener.visible).isTrue()

        activityScenario.onActivity {
            animatorTestRule.advanceTimeBy(600)
        }
        assertThat(listener.visible).isFalse()
        assertThat(menuViewController.isMenuVisible).isFalse()
    }

    private class TestListener : BubbleBarMenuViewController.Listener {

        var visible = false

        override fun onMenuVisibilityChanged(visible: Boolean) {
            this.visible = visible
        }

        override fun onUnBubbleConversation(bubble: Bubble?) {}

        override fun onOpenAppSettings(bubble: Bubble?) {}

        override fun onDismissBubble(bubble: Bubble?) {}

        override fun onMoveToFullscreen(bubble: Bubble?) {}
    }

    class TestActivity : Activity() {
        lateinit var container: FrameLayout
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            container = FrameLayout(applicationContext)
            setContentView(container)
        }
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -141,6 +141,7 @@ public class BubbleBarAnimationHelper {
        bbev.setAnimationMatrix(mExpandedViewContainerMatrix);

        bbev.animateExpansionWhenTaskViewVisible(() -> {
            bbev.getHandleView().setAlpha(1);
            ObjectAnimator alphaAnim = createAlphaAnimator(bbev, /* visible= */ true);
            alphaAnim.setDuration(EXPANDED_VIEW_EXPAND_ALPHA_DURATION);
            alphaAnim.setInterpolator(Interpolators.PANEL_CLOSE_ACCELERATED);
+4 −6
Original line number Diff line number Diff line
@@ -86,12 +86,10 @@ class BubbleBarMenuViewController {
        runOnMenuIsMeasured(() -> {
            mMenuView.setVisibility(View.VISIBLE);
            mScrimView.setVisibility(View.VISIBLE);
            Runnable endActions = () -> {
                mMenuView.getChildAt(0).requestAccessibilityFocus();
            if (mListener != null) {
                mListener.onMenuVisibilityChanged(true /* isShown */);
            }
            };
            Runnable endActions = () -> mMenuView.getChildAt(0).requestAccessibilityFocus();
            if (animated) {
                animateTransition(true /* show */, endActions);
            } else {