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

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

Set a maximum expanded view width for large screens

We previously set a constant width for the expanded view in large
screen devices, but some display configuration may not be able to
fit that width. This change checks that the expanded view can fit
in the screen, and otherwise sets it to fill the screen with equal
padding on both sides.

Flag: EXEMPT bugfix
Fixes: 382256445
Test: atest BubblePositionerTest
Test: manual
       - adb shell wm size 1340x800
       - adb shell wm density 213
       - set device orientation to portrait
       - send floating bubble and expand it
       - observe expanded view fits in screen
Change-Id: Ifbf203cf03fcb1a9f511f8de96a2f37a26d42c6b
parent c9b66b17
Loading
Loading
Loading
Loading
+65 −1
Original line number Diff line number Diff line
@@ -602,8 +602,72 @@ class BubblePositionerTest {
        testGetBubbleBarExpandedViewBounds(onLeft = false, isOverflow = true)
    }

    @Test
    fun getExpandedViewContainerPadding_largeScreen_fitsMaxViewWidth() {
        val expandedViewWidth = context.resources.getDimensionPixelSize(
            R.dimen.bubble_expanded_view_largescreen_width
        )
        // set the screen size so that it is wide enough to fit the maximum width size
        val screenWidth = expandedViewWidth * 2
        positioner.update(
            defaultDeviceConfig.copy(
                windowBounds = Rect(0, 0, screenWidth, 2000),
                isLargeScreen = true,
                isLandscape = false
            )
        )
        val paddings =
            positioner.getExpandedViewContainerPadding(/* onLeft= */ true, /* isOverflow= */ false)

        val padding = context.resources.getDimensionPixelSize(
            R.dimen.bubble_expanded_view_largescreen_landscape_padding
        )
        val right = screenWidth - expandedViewWidth - padding
        assertThat(paddings).isEqualTo(intArrayOf(padding - positioner.pointerSize, 0, right, 0))
    }

    @Test
    fun getExpandedViewContainerPadding_largeScreen_doesNotFitMaxViewWidth() {
        positioner.update(
            defaultDeviceConfig.copy(
                windowBounds = Rect(0, 0, 600, 2000),
                isLargeScreen = true,
                isLandscape = false
            )
        )
        val paddings =
            positioner.getExpandedViewContainerPadding(/* onLeft= */ true, /* isOverflow= */ false)

        val padding = context.resources.getDimensionPixelSize(
            R.dimen.bubble_expanded_view_largescreen_landscape_padding
        )
        // the screen is not wide enough to fit the maximum width size, so the view fills the screen
        // minus left and right padding
        assertThat(paddings).isEqualTo(intArrayOf(padding - positioner.pointerSize, 0, padding, 0))
    }

    @Test
    fun getExpandedViewContainerPadding_smallTablet() {
        val screenWidth = 500
        positioner.update(
            defaultDeviceConfig.copy(
                windowBounds = Rect(0, 0, screenWidth, 2000),
                isLargeScreen = true,
                isSmallTablet = true,
                isLandscape = false
            )
        )
        val paddings =
            positioner.getExpandedViewContainerPadding(/* onLeft= */ true, /* isOverflow= */ false)

        // for small tablets, the view width is set to be 0.72 * screen width
        val viewWidth = (screenWidth * 0.72).toInt()
        val padding = (screenWidth - viewWidth) / 2
        assertThat(paddings).isEqualTo(intArrayOf(padding - positioner.pointerSize, 0, padding, 0))
    }

    private fun testGetBubbleBarExpandedViewBounds(onLeft: Boolean, isOverflow: Boolean) {
        positioner.setShowingInBubbleBar(true)
        positioner.isShowingInBubbleBar = true
        val windowBounds = Rect(0, 0, 2000, 2600)
        val insets = Insets.of(10, 20, 5, 15)
        val deviceConfig =
+5 −2
Original line number Diff line number Diff line
@@ -163,8 +163,11 @@ public class BubblePositioner {
            mExpandedViewLargeScreenWidth = (int) (bounds.width()
                    * EXPANDED_VIEW_SMALL_TABLET_WIDTH_PERCENT);
        } else {
            mExpandedViewLargeScreenWidth =
                    res.getDimensionPixelSize(R.dimen.bubble_expanded_view_largescreen_width);
            int expandedViewLargeScreenSpacing = res.getDimensionPixelSize(
                    R.dimen.bubble_expanded_view_largescreen_landscape_padding);
            mExpandedViewLargeScreenWidth = Math.min(
                    res.getDimensionPixelSize(R.dimen.bubble_expanded_view_largescreen_width),
                    bounds.width() - expandedViewLargeScreenSpacing * 2);
        }
        if (mDeviceConfig.isLargeScreen()) {
            if (mDeviceConfig.isSmallTablet()) {