From 9be3bedc5b2ab364062cdb22a1371ff717975640 Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Wed, 21 Aug 2019 17:26:26 -0700 Subject: [PATCH] Restrict height of expanded view in landscape & fix left / right padding Previously the height & width of expanded view was not updated when switching between landscape & portrait. This CL: * Adjusts max height calculation so it accounts for landscape * Updates the position, height, & left / right padding of the expanded view when the orientation changes, also accounting for notches / navbar * Also accounts display cutout when calculating IME inset for expanded view Test: manual - have multiple bubbles with different heights (small & max) - expand the stack - go to each bubble and rotate to landscape / portrait => in landscape the heights should be restricted & width of the view shouldn't overlap notches (turn them on/off) or navbar (turn gesture nav on/off), in portrait the max height should increase Bug: 135487618 Change-Id: Iaffcef0a070d3eb2d6b21248be3c94a861d77d5d --- .../systemui/bubbles/BubbleExpandedView.java | 11 +++-- .../systemui/bubbles/BubbleStackView.java | 41 ++++++++++++++++--- 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java index be10dc565159b..521ebde7d2f0a 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java @@ -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() diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java index f57f413259378..b68b7627fe8c4 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java @@ -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,6 +341,7 @@ public class BubbleStackView extends FrameLayout { mDisplaySize = new Point(); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); + // 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(() -> { @@ -489,6 +519,7 @@ public class BubbleStackView extends FrameLayout { 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); @@ -1593,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); }