From cb8dcec66aa68e576bfd1520d1ad39a961f22c56 Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Mon, 13 Jun 2016 19:12:13 -0700 Subject: [PATCH] PopupWindow: Resolve measure specs before passing to WM. For the setClipToScreen case we need constraint to the available display area, but not to the parent window. If we don't pass FLAG_LAYOUT_NO_LIMITS, we will be constrained to the parent window. However when we do pass it, we will not be constrained to the system insets. So, we can pass FLAG_LAYOUT_NO_LIMITS and constrain ourselves to the insets via getWindowVisibleDisplayFrame. We also need to avoid calling setWidth/Height with these resolved values so we can preserve the indeterminate values in case layout changes (e.g. rotation). Bug: 29166136 Change-Id: I4c7c6204e6bc1cdcf4ad86f7e99e3511d4312ae4 --- core/java/android/widget/PopupWindow.java | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/java/android/widget/PopupWindow.java b/core/java/android/widget/PopupWindow.java index f013454d912be..3f6e625245f3b 100644 --- a/core/java/android/widget/PopupWindow.java +++ b/core/java/android/widget/PopupWindow.java @@ -1451,7 +1451,7 @@ public class PopupWindow { if (mOutsideTouchable) { curFlags |= WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; } - if (!mClippingEnabled) { + if (!mClippingEnabled || mClipToScreen) { curFlags |= WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS; } if (isSplitTouchEnabled()) { @@ -1513,14 +1513,6 @@ public class PopupWindow { outParams.x = drawingLocation[0] + xOffset; outParams.y = drawingLocation[1] + anchorHeight + yOffset; - // Let the window manager know to align the top to y. - outParams.gravity = Gravity.LEFT | Gravity.TOP; - outParams.width = width; - outParams.height = height; - - // If width or height is unspecified. We can leave it to the window manager to match - // to the parent size, but for our local purposes of calculating positioning, we need - // to fill in real width and height values. final Rect displayFrame = new Rect(); anchor.getWindowVisibleDisplayFrame(displayFrame); if (width == MATCH_PARENT) { @@ -1534,6 +1526,11 @@ public class PopupWindow { height = mContentView.getMeasuredHeight(); } + // Let the window manager know to align the top to y. + outParams.gravity = Gravity.LEFT | Gravity.TOP; + outParams.width = width; + outParams.height = height; + // If we need to adjust for gravity RIGHT, align to the bottom-right // corner of the anchor (still accounting for offsets). final int hgrav = Gravity.getAbsoluteGravity(gravity, anchor.getLayoutDirection()) @@ -2143,7 +2140,10 @@ public class PopupWindow { final boolean paramsChanged = oldGravity != p.gravity || oldX != p.x || oldY != p.y || oldWidth != p.width || oldHeight != p.height; - update(p.x, p.y, p.width, p.height, paramsChanged); + // If width and mWidth were both < 0 then we have a MATCH_PARENT/WRAP_CONTENT case. + // findDropDownPosition will have resolved this to absolute values, + // but we don't want to update mWidth/mHeight to these absolute values. + update(p.x, p.y, width < 0 ? width : p.width, height < 0 ? height : p.height, paramsChanged); } /**