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

Commit 7943c7b5 authored by Mady Mellor's avatar Mady Mellor Committed by Android (Google) Code Review
Browse files

Merge changes from topic "landscape-jeeze" into qt-qpr1-dev

* changes:
  Restrict height of expanded view in landscape & fix left / right padding
  Restrict the space bubbles are centered in while in landscape
parents 4cb4e0a1 9be3bedc
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -105,6 +105,7 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
    private Drawable mAppIcon;

    private BubbleController mBubbleController = Dependency.get(BubbleController.class);
    private WindowManager mWindowManager;

    private BubbleStackView mStackView;

@@ -202,9 +203,9 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
        super(context, attrs, defStyleAttr, defStyleRes);
        mPm = context.getPackageManager();
        mDisplaySize = new Point();
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        // Get the real size -- this includes screen decorations (notches, statusbar, navbar).
        wm.getDefaultDisplay().getRealSize(mDisplaySize);
        mWindowManager.getDefaultDisplay().getRealSize(mDisplaySize);
        Resources res = getResources();
        mMinHeight = res.getDimensionPixelSize(R.dimen.bubble_expanded_default_height);
        mPointerMargin = res.getDimensionPixelSize(R.dimen.bubble_pointer_margin);
@@ -326,7 +327,10 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
        if (usingActivityView()) {
            int[] screenLoc = mActivityView.getLocationOnScreen();
            final int activityViewBottom = screenLoc[1] + mActivityView.getHeight();
            final int keyboardTop = mDisplaySize.y - insets.getSystemWindowInsetBottom();
            final int keyboardTop = mDisplaySize.y - Math.max(insets.getSystemWindowInsetBottom(),
                    insets.getDisplayCutout() != null
                            ? insets.getDisplayCutout().getSafeInsetBottom()
                            : 0);
            final int insetsBottom = Math.max(activityViewBottom - keyboardTop, 0);
            mActivityView.setForwardedInsets(Insets.of(0, 0, 0, insetsBottom));
        }
@@ -444,6 +448,7 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList
    }

    private int getMaxExpandedHeight() {
        mWindowManager.getDefaultDisplay().getRealSize(mDisplaySize);
        int[] windowLocation = mActivityView.getLocationOnScreen();
        int bottomInset = getRootWindowInsets() != null
                ? getRootWindowInsets().getStableInsetBottom()
+40 −7
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.service.notification.StatusBarNotification;
import android.util.Log;
import android.util.StatsLog;
import android.view.Choreographer;
import android.view.DisplayCutout;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
@@ -340,7 +341,8 @@ public class BubbleStackView extends FrameLayout {

        mDisplaySize = new Point();
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        wm.getDefaultDisplay().getSize(mDisplaySize);
        // We use the real size & subtract screen decorations / window insets ourselves when needed
        wm.getDefaultDisplay().getRealSize(mDisplaySize);

        mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);

@@ -417,7 +419,35 @@ public class BubbleStackView extends FrameLayout {

        mOrientationChangedListener =
                (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
                    mExpandedAnimationController.updateOrientation(mOrientation);
                    mExpandedAnimationController.updateOrientation(mOrientation, mDisplaySize);
                    mStackAnimationController.updateOrientation(mOrientation);

                    // Reposition & adjust the height for new orientation
                    if (mIsExpanded) {
                        mExpandedViewContainer.setTranslationY(getExpandedViewY());
                        mExpandedBubble.getExpandedView().updateView();
                    }

                    // Need to update the padding around the view
                    WindowInsets insets = getRootWindowInsets();
                    int leftPadding = mExpandedViewPadding;
                    int rightPadding = mExpandedViewPadding;
                    if (insets != null) {
                        // Can't have the expanded view overlaying notches
                        int cutoutLeft = 0;
                        int cutoutRight = 0;
                        DisplayCutout cutout = insets.getDisplayCutout();
                        if (cutout != null) {
                            cutoutLeft = cutout.getSafeInsetLeft();
                            cutoutRight = cutout.getSafeInsetRight();
                        }
                        // Or overlaying nav or status bar
                        leftPadding += Math.max(cutoutLeft, insets.getStableInsetLeft());
                        rightPadding += Math.max(cutoutRight, insets.getStableInsetRight());
                    }
                    mExpandedViewContainer.setPadding(leftPadding, mExpandedViewPadding,
                            rightPadding, mExpandedViewPadding);

                    if (mIsExpanded) {
                        // Re-draw bubble row and pointer for new orientation.
                        mExpandedAnimationController.expandFromStack(() -> {
@@ -488,6 +518,11 @@ public class BubbleStackView extends FrameLayout {
    public void onOrientationChanged(int orientation) {
        mOrientation = orientation;

        // Display size is based on the rotation device was in when requested, we should update it
        // We use the real size & subtract screen decorations / window insets ourselves when needed
        WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
        wm.getDefaultDisplay().getRealSize(mDisplaySize);

        // Some resources change depending on orientation
        Resources res = getContext().getResources();
        mStatusBarHeight = res.getDimensionPixelSize(
@@ -1589,11 +1624,9 @@ public class BubbleStackView extends FrameLayout {
        int index = getBubbleIndex(expandedBubble);
        float bubbleLeftFromScreenLeft = mExpandedAnimationController.getBubbleLeft(index);
        float halfBubble = mBubbleSize / 2f;

        // Bubbles live in expanded view container (x includes expanded view padding).
        // Pointer lives in expanded view, which has padding (x does not include padding).
        // Remove padding when deriving pointer location from bubbles.
        float bubbleCenter = bubbleLeftFromScreenLeft + halfBubble - mExpandedViewPadding;
        float bubbleCenter = bubbleLeftFromScreenLeft + halfBubble;
        // Padding might be adjusted for insets, so get it directly from the view
        bubbleCenter -= mExpandedViewContainer.getPaddingLeft();

        expandedBubble.getExpandedView().setPointerPosition(bubbleCenter);
    }
+62 −14
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.res.Resources;
import android.graphics.Path;
import android.graphics.Point;
import android.graphics.PointF;
import android.view.DisplayCutout;
import android.view.View;
import android.view.WindowInsets;

@@ -57,6 +58,9 @@ public class ExpandedAnimationController
    /** Stiffness for the expand/collapse path-following animation. */
    private static final int EXPAND_COLLAPSE_ANIM_STIFFNESS = 1000;

    /** What percentage of the screen to use when centering the bubbles in landscape. */
    private static final float CENTER_BUBBLES_LANDSCAPE_PERCENT = 0.66f;

    /** Horizontal offset between bubbles, which we need to know to re-stack them. */
    private float mStackOffsetPx;
    /** Space between status bar and bubbles in the expanded state. */
@@ -69,8 +73,8 @@ public class ExpandedAnimationController
    private Point mDisplaySize;
    /** Max number of bubbles shown in row above expanded view.*/
    private int mBubblesMaxRendered;
    /** Width of current screen orientation. */
    private float mScreenWidth;
    /** What the current screen orientation is. */
    private int mScreenOrientation;

    /** Whether the dragged-out bubble is in the dismiss target. */
    private boolean mIndividualBubbleWithinDismissTarget = false;
@@ -97,8 +101,7 @@ public class ExpandedAnimationController

    public ExpandedAnimationController(Point displaySize, int expandedViewPadding,
            int orientation) {
        mDisplaySize = displaySize;
        updateOrientation(orientation);
        updateOrientation(orientation, displaySize);
        mExpandedViewPadding = expandedViewPadding;
        mLauncherGridDiff = 30f;
    }
@@ -136,18 +139,16 @@ public class ExpandedAnimationController
    /**
     * Update effective screen width based on current orientation.
     * @param orientation Landscape or portrait.
     * @param displaySize Updated display size.
     */
    public void updateOrientation(int orientation) {
        if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
            mScreenWidth = mDisplaySize.y;
        } else {
            mScreenWidth = mDisplaySize.x;
        }
    public void updateOrientation(int orientation, Point displaySize) {
        mScreenOrientation = orientation;
        mDisplaySize = displaySize;
        if (mLayout != null) {
            Resources res = mLayout.getContext().getResources();
            mBubblePaddingTop = res.getDimensionPixelSize(R.dimen.bubble_padding_top);
            mStatusBarHeight = res.getDimensionPixelSize(
                    com.android.internal.R.dimen.status_bar_height);
            mBubblePaddingTop = res.getDimensionPixelSize(R.dimen.bubble_padding_top);
        }
    }

@@ -499,6 +500,50 @@ public class ExpandedAnimationController
        return getRowLeft() + bubbleFromRowLeft;
    }

    /**
     * When expanded, the bubbles are centered in the screen. In portrait, all available space is
     * used. In landscape we have too much space so the value is restricted. This method accounts
     * for window decorations (nav bar, cutouts).
     *
     * @return the desired width to display the expanded bubbles in.
     */
    private float getWidthForDisplayingBubbles() {
        final float availableWidth = getAvailableScreenWidth(true /* includeStableInsets */);
        if (mScreenOrientation == Configuration.ORIENTATION_LANDSCAPE) {
            // display size y in landscape will be the smaller dimension of the screen
            return Math.max(mDisplaySize.y, availableWidth * CENTER_BUBBLES_LANDSCAPE_PERCENT);
        } else {
            return availableWidth;
        }
    }

    /**
     * Determines the available screen width without the cutout.
     *
     * @param subtractStableInsets Whether or not stable insets should also be removed from the
     *                            returned width.
     * @return the total screen width available accounting for cutouts and insets,
     * iff {@param includeStableInsets} is true.
     */
    private float getAvailableScreenWidth(boolean subtractStableInsets) {
        float availableSize = mDisplaySize.x;
        WindowInsets insets = mLayout != null ? mLayout.getRootWindowInsets() : null;
        if (insets != null) {
            int cutoutLeft = 0;
            int cutoutRight = 0;
            DisplayCutout cutout = insets.getDisplayCutout();
            if (cutout != null) {
                cutoutLeft = cutout.getSafeInsetLeft();
                cutoutRight = cutout.getSafeInsetRight();
            }
            final int stableLeft = subtractStableInsets ? insets.getStableInsetLeft() : 0;
            final int stableRight = subtractStableInsets ? insets.getStableInsetRight() : 0;
            availableSize -= Math.max(stableLeft, cutoutLeft);
            availableSize -= Math.max(stableRight, cutoutRight);
        }
        return availableSize;
    }

    private float getRowLeft() {
        if (mLayout == null) {
            return 0;
@@ -510,9 +555,12 @@ public class ExpandedAnimationController
        final float totalGapWidth = (bubbleCount - 1) * getSpaceBetweenBubbles();
        final float rowWidth = totalGapWidth + totalBubbleWidth;

        final float centerScreen = mScreenWidth / 2f;
        // This display size we're using includes the size of the insets, we want the true
        // center of the display minus the notch here, which means we should include the
        // stable insets (e.g. status bar, nav bar) in this calculation.
        final float trueCenter = getAvailableScreenWidth(false /* subtractStableInsets */) / 2f;
        final float halfRow = rowWidth / 2f;
        final float rowLeft = centerScreen - halfRow;
        final float rowLeft = trueCenter - halfRow;

        return rowLeft;
    }
@@ -530,7 +578,7 @@ public class ExpandedAnimationController
         *  Launcher's app icon grid edge that we must match
         */
        final float rowMargins = (mExpandedViewPadding + mLauncherGridDiff) * 2;
        final float maxRowWidth = mScreenWidth - rowMargins;
        final float maxRowWidth = getWidthForDisplayingBubbles() - rowMargins;

        final float totalBubbleWidth = mBubblesMaxRendered * mBubbleSizePx;
        final float totalGapWidth = maxRowWidth - totalBubbleWidth;