diff options
| author | 2016-04-14 19:28:41 +0000 | |
|---|---|---|
| committer | 2016-04-14 19:28:42 +0000 | |
| commit | 446b4e727d228caccc635cd69e14fc9faba8ec7f (patch) | |
| tree | 209c8b68a9f324a25f0d1a2bd1939649cb7df940 | |
| parent | 0d723a2a4d83db5f01aa5a21f3cbd9d2b608bced (diff) | |
| parent | f6e801da1a45b2458679e20f5e6061442a434e1b (diff) | |
Merge "PopupWindow. Don't use -1 width/height for calculations." into nyc-dev
| -rw-r--r-- | core/java/android/widget/PopupWindow.java | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/core/java/android/widget/PopupWindow.java b/core/java/android/widget/PopupWindow.java index af4675609079..bb883ea88327 100644 --- a/core/java/android/widget/PopupWindow.java +++ b/core/java/android/widget/PopupWindow.java @@ -1512,6 +1512,24 @@ 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 < 0) { + width = displayFrame.right - displayFrame.left; + } + if (height < 0) { + height = displayFrame.bottom - displayFrame.top; + } + + // 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()) @@ -1520,17 +1538,9 @@ public class PopupWindow { outParams.x -= width - anchorWidth; } - // Let the window manager know to align the top to y. - outParams.gravity = Gravity.LEFT | Gravity.TOP; - outParams.width = width; - outParams.height = height; - final int[] screenLocation = mTmpScreenLocation; anchor.getLocationOnScreen(screenLocation); - final Rect displayFrame = new Rect(); - anchor.getWindowVisibleDisplayFrame(displayFrame); - // First, attempt to fit the popup vertically without resizing. final boolean fitsVertical = tryFitVertical(outParams, yOffset, height, anchorHeight, drawingLocation[1], screenLocation[1], displayFrame.top, @@ -2114,10 +2124,10 @@ public class PopupWindow { // If an explicit width/height has not specified, use the most recent // explicitly specified value (either from setWidth/Height or update). - if (width == -1) { + if (width < 0) { width = mWidth; } - if (height == -1) { + if (height < 0) { height = mHeight; } |