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

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

Update bubble expanded view size and margins

This change updates the bubble expanded view on large screens according to specs
https://www.figma.com/file/00VWOwhcuElG8StuLKYu5Z/Bubbles?type=design&node-id=4693-139011&mode=design&t=U6QGHMrGe0K1zY93-0

Also see:
https://screenshot.googleplex.com/AaxBXDdr7s4RmWS
https://screenshot.googleplex.com/6xavE6hnxVqT36E

Fixes: 301232987
Test: atest BubblePositionerTest

Change-Id: Ib01c240594a761b553cc853a8a077cb54cee7679
parent e9438760
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -143,7 +143,9 @@
    <dimen name="bubble_expanded_view_padding">16dp</dimen>
    <!-- Padding for the edge of the expanded view that is closest to the edge of the screen used
         when displaying in landscape on a large screen. -->
    <dimen name="bubble_expanded_view_largescreen_landscape_padding">128dp</dimen>
    <dimen name="bubble_expanded_view_largescreen_landscape_padding">102dp</dimen>
    <!-- The width of the expanded view on large screens. -->
    <dimen name="bubble_expanded_view_largescreen_width">540dp</dimen>
    <!-- This should be at least the size of bubble_expanded_view_padding; it is used to include
         a slight touch slop around the expanded view. -->
    <dimen name="bubble_expanded_view_slop">8dp</dimen>
+23 −15
Original line number Diff line number Diff line
@@ -54,10 +54,6 @@ public class BubblePositioner {
    public static final float FLYOUT_MAX_WIDTH_PERCENT_LARGE_SCREEN = 0.3f;
    /** The max percent of screen width to use for the flyout on phone. */
    public static final float FLYOUT_MAX_WIDTH_PERCENT = 0.6f;
    /** The percent of screen width for the expanded view on a large screen. **/
    private static final float EXPANDED_VIEW_LARGE_SCREEN_LANDSCAPE_WIDTH_PERCENT = 0.48f;
    /** The percent of screen width for the expanded view on a large screen. **/
    private static final float EXPANDED_VIEW_LARGE_SCREEN_PORTRAIT_WIDTH_PERCENT = 0.70f;
    /** The percent of screen width for the expanded view on a small tablet. **/
    private static final float EXPANDED_VIEW_SMALL_TABLET_WIDTH_PERCENT = 0.72f;
    /** The percent of screen width for the expanded view when shown in the bubble bar. **/
@@ -95,6 +91,7 @@ public class BubblePositioner {
    private int mPointerWidth;
    private int mPointerHeight;
    private int mPointerOverlap;
    private int mManageButtonHeightIncludingMargins;
    private int mManageButtonHeight;
    private int mOverflowHeight;
    private int mMinimumFlyoutWidthLargeScreen;
@@ -176,21 +173,20 @@ public class BubblePositioner {
            mExpandedViewLargeScreenWidth = (int) (bounds.width()
                    * EXPANDED_VIEW_SMALL_TABLET_WIDTH_PERCENT);
        } else {
            mExpandedViewLargeScreenWidth = isLandscape()
                    ? (int) (bounds.width() * EXPANDED_VIEW_LARGE_SCREEN_LANDSCAPE_WIDTH_PERCENT)
                    : (int) (bounds.width() * EXPANDED_VIEW_LARGE_SCREEN_PORTRAIT_WIDTH_PERCENT);
            mExpandedViewLargeScreenWidth =
                    res.getDimensionPixelSize(R.dimen.bubble_expanded_view_largescreen_width);
        }
        if (mIsLargeScreen) {
            if (isLandscape() && !mIsSmallTablet) {
            if (mIsSmallTablet) {
                final int centeredInset = (bounds.width() - mExpandedViewLargeScreenWidth) / 2;
                mExpandedViewLargeScreenInsetClosestEdge = centeredInset;
                mExpandedViewLargeScreenInsetFurthestEdge = centeredInset;
            } else {
                mExpandedViewLargeScreenInsetClosestEdge = res.getDimensionPixelSize(
                        R.dimen.bubble_expanded_view_largescreen_landscape_padding);
                mExpandedViewLargeScreenInsetFurthestEdge = bounds.width()
                        - mExpandedViewLargeScreenInsetClosestEdge
                        - mExpandedViewLargeScreenWidth;
            } else {
                final int centeredInset = (bounds.width() - mExpandedViewLargeScreenWidth) / 2;
                mExpandedViewLargeScreenInsetClosestEdge = centeredInset;
                mExpandedViewLargeScreenInsetFurthestEdge = centeredInset;
            }
        } else {
            mExpandedViewLargeScreenInsetClosestEdge = mExpandedViewPadding;
@@ -202,7 +198,9 @@ public class BubblePositioner {
        mPointerHeight = res.getDimensionPixelSize(R.dimen.bubble_pointer_height);
        mPointerMargin = res.getDimensionPixelSize(R.dimen.bubble_pointer_margin);
        mPointerOverlap = res.getDimensionPixelSize(R.dimen.bubble_pointer_overlap);
        mManageButtonHeight = res.getDimensionPixelSize(R.dimen.bubble_manage_button_total_height);
        mManageButtonHeightIncludingMargins =
                res.getDimensionPixelSize(R.dimen.bubble_manage_button_total_height);
        mManageButtonHeight = res.getDimensionPixelSize(R.dimen.bubble_manage_button_height);
        mExpandedViewMinHeight = res.getDimensionPixelSize(R.dimen.bubble_expanded_default_height);
        mOverflowHeight = res.getDimensionPixelSize(R.dimen.bubble_overflow_height);
        mMinimumFlyoutWidthLargeScreen = res.getDimensionPixelSize(
@@ -420,7 +418,7 @@ public class BubblePositioner {
        int pointerSize = showBubblesVertically()
                ? mPointerWidth
                : (mPointerHeight + mPointerMargin);
        int bottomPadding = isOverflow ? mExpandedViewPadding : mManageButtonHeight;
        int bottomPadding = isOverflow ? mExpandedViewPadding : mManageButtonHeightIncludingMargins;
        return getAvailableRect().height()
                - expandedContainerY
                - paddingTop
@@ -438,6 +436,15 @@ public class BubblePositioner {
            // overflow in landscape on phone is max
            return MAX_HEIGHT;
        }

        if (mIsLargeScreen && !mIsSmallTablet && !isOverflow) {
            // the expanded view height on large tablets is calculated based on the shortest screen
            // size and is the same in both portrait and landscape
            int maxVerticalInset = Math.max(mInsets.top, mInsets.bottom);
            int shortestScreenSide = Math.min(mScreenRect.height(), mScreenRect.width());
            return shortestScreenSide - 2 * maxVerticalInset - mManageButtonHeight;
        }

        float desiredHeight = isOverflow
                ? mOverflowHeight
                : ((Bubble) bubble).getDesiredHeight(mContext);
@@ -466,7 +473,8 @@ public class BubblePositioner {
            return topAlignment;
        }
        // If we're here, we're showing vertically & developer has made height less than maximum.
        int manageButtonHeight = isOverflow ? mExpandedViewPadding : mManageButtonHeight;
        int manageButtonHeight =
                isOverflow ? mExpandedViewPadding : mManageButtonHeightIncludingMargins;
        float pointerPosition = getPointerPosition(bubblePosition);
        float bottomIfCentered = pointerPosition + (expandedViewHeight / 2) + manageButtonHeight;
        float topIfCentered = pointerPosition - (expandedViewHeight / 2);
+33 −0
Original line number Diff line number Diff line
@@ -22,20 +22,24 @@ import static android.view.View.LAYOUT_DIRECTION_LTR;
import static android.view.View.LAYOUT_DIRECTION_RTL;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;

import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Insets;
import android.graphics.PointF;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.UserHandle;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.testing.TestableResources;
import android.util.DisplayMetrics;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.view.WindowMetrics;
@@ -257,6 +261,27 @@ public class BubblePositionerTest extends ShellTestCase {
        assertThat(mPositioner.hasUserModifiedDefaultPosition()).isTrue();
    }

    @Test
    public void testExpandedViewHeight_onLargeTablet() {
        Insets insets = Insets.of(10, 20, 5, 15);
        Rect screenBounds = new Rect(0, 0, 1800, 2600);

        new WindowManagerConfig()
                .setLargeScreen()
                .setInsets(insets)
                .setScreenBounds(screenBounds)
                .setUpConfig();
        mPositioner.update();

        Intent intent = new Intent(Intent.ACTION_VIEW).setPackage(mContext.getPackageName());
        Bubble bubble = Bubble.createAppBubble(intent, new UserHandle(1), null, directExecutor());

        int manageButtonHeight =
                mContext.getResources().getDimensionPixelSize(R.dimen.bubble_manage_button_height);
        float expectedHeight = 1800 - 2 * 20 - manageButtonHeight;
        assertThat(mPositioner.getExpandedViewHeight(bubble)).isWithin(0.1f).of(expectedHeight);
    }

    /**
     * Calculates the Y position bubbles should be placed based on the config. Based on
     * the calculations in {@link BubblePositioner#getDefaultStartPosition()} and
@@ -323,6 +348,8 @@ public class BubblePositionerTest extends ShellTestCase {
                    ? MIN_WIDTH_FOR_TABLET
                    : MIN_WIDTH_FOR_TABLET - 1;
            mConfiguration.orientation = mOrientation;
            mConfiguration.screenWidthDp = pxToDp(mScreenBounds.width());
            mConfiguration.screenHeightDp = pxToDp(mScreenBounds.height());

            when(mConfiguration.getLayoutDirection()).thenReturn(mLayoutDirection);
            WindowInsets windowInsets = mock(WindowInsets.class);
@@ -331,5 +358,11 @@ public class BubblePositionerTest extends ShellTestCase {
            when(mWindowMetrics.getBounds()).thenReturn(mScreenBounds);
            when(mWindowManager.getCurrentWindowMetrics()).thenReturn(mWindowMetrics);
        }

        private int pxToDp(float px) {
            int dpi = mContext.getResources().getDisplayMetrics().densityDpi;
            float dp = px / ((float) dpi / DisplayMetrics.DENSITY_DEFAULT);
            return (int) dp;
        }
    }
}