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

Commit 33319db6 authored by Mady Mellor's avatar Mady Mellor
Browse files

Modify the default position of bubbles on tablet to be centered

If we don't have a previous bubble position we use a default spot.

On phone we use an offset from the top of the device and place
bubbles based on that. This was also being used for tablet. This
CL modifies the behavior so that we'll center bubbles along the edge
for the default position on tablet. This makes them a little more
reachable for the larger screen size.

Bug: 283910436
Test: atest BubblePositionerTest
Change-Id: Ifc1a889809ea1be53e71c920e86e923b3cf98805
parent b738e935
Loading
Loading
Loading
Loading
+20 −8
Original line number Diff line number Diff line
@@ -661,14 +661,26 @@ public class BubblePositioner {
        final boolean startOnLeft =
                mContext.getResources().getConfiguration().getLayoutDirection()
                        != LAYOUT_DIRECTION_RTL;
        final RectF allowableStackPositionRegion = getAllowableStackPositionRegion(
                1 /* default starts with 1 bubble */);
        if (isLargeScreen()) {
            // We want the stack to be visually centered on the edge, so we need to base it
            // of a rect that includes insets.
            final float desiredY = mScreenRect.height() / 2f - (mBubbleSize / 2f);
            final float offset = desiredY / mScreenRect.height();
            return new BubbleStackView.RelativeStackPosition(
                    startOnLeft,
                    offset)
                    .getAbsolutePositionInRegion(allowableStackPositionRegion);
        } else {
            final float startingVerticalOffset = mContext.getResources().getDimensionPixelOffset(
                    R.dimen.bubble_stack_starting_offset_y);
            // TODO: placement bug here because mPositionRect doesn't handle the overhanging edge
            return new BubbleStackView.RelativeStackPosition(
                    startOnLeft,
                    startingVerticalOffset / mPositionRect.height())
                .getAbsolutePositionInRegion(getAllowableStackPositionRegion(
                        1 /* default starts with 1 bubble */));
                    .getAbsolutePositionInRegion(allowableStackPositionRegion);
        }
    }

    /**
+12 −2
Original line number Diff line number Diff line
@@ -209,9 +209,19 @@ public class BubblePositionerTest extends ShellTestCase {
     * {@link BubbleStackView.RelativeStackPosition}.
     */
    private float getDefaultYPosition() {
        final float desiredY = mContext.getResources().getDimensionPixelOffset(
        final boolean isTablet = mPositioner.isLargeScreen();

        // On tablet the position is centered, on phone it is an offset from the top.
        final float desiredY = isTablet
                ? mPositioner.getScreenRect().height() / 2f - (mPositioner.getBubbleSize() / 2f)
                : mContext.getResources().getDimensionPixelOffset(
                        R.dimen.bubble_stack_starting_offset_y);
        float offsetPercent = desiredY / mPositioner.getAvailableRect().height();
        // Since we're visually centering the bubbles on tablet, use total screen height rather
        // than the available height.
        final float height = isTablet
                ? mPositioner.getScreenRect().height()
                : mPositioner.getAvailableRect().height();
        float offsetPercent = desiredY / height;
        offsetPercent = Math.max(0f, Math.min(1f, offsetPercent));
        final RectF allowableStackRegion =
                mPositioner.getAllowableStackPositionRegion(1 /* bubbleCount */);