From 55f0a99076477b77e017454e4356d908c43c2d22 Mon Sep 17 00:00:00 2001 From: Alan Viverette Date: Tue, 19 Apr 2016 10:17:00 -0400 Subject: [PATCH] Use adjusted popup window position when calculating best-fit Bug: 28194522 Bug: 28175404 Change-Id: I5685b397908f64559d0ec5fea5820bdea69f422c --- core/java/android/widget/PopupWindow.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/java/android/widget/PopupWindow.java b/core/java/android/widget/PopupWindow.java index bb883ea883273..bc8863f6208ab 100644 --- a/core/java/android/widget/PopupWindow.java +++ b/core/java/android/widget/PopupWindow.java @@ -1529,7 +1529,6 @@ public class PopupWindow { 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()) @@ -1583,9 +1582,10 @@ public class PopupWindow { private boolean tryFitVertical(@NonNull LayoutParams outParams, int yOffset, int height, int anchorHeight, int drawingLocationY, int screenLocationY, int displayFrameTop, int displayFrameBottom, boolean allowResize) { - final int anchorTopInScreen = screenLocationY + anchorHeight + yOffset; + final int winOffsetY = screenLocationY - drawingLocationY; + final int anchorTopInScreen = outParams.y + winOffsetY; final int spaceBelow = displayFrameBottom - anchorTopInScreen; - if (height <= spaceBelow) { + if (anchorTopInScreen >= 0 && height <= spaceBelow) { return true; } @@ -1644,9 +1644,10 @@ public class PopupWindow { private boolean tryFitHorizontal(@NonNull LayoutParams outParams, int xOffset, int width, int anchorWidth, int drawingLocationX, int screenLocationX, int displayFrameLeft, int displayFrameRight, boolean allowResize) { - final int anchorLeftInScreen = screenLocationX + xOffset; + final int winOffsetX = screenLocationX - drawingLocationX; + final int anchorLeftInScreen = outParams.x + winOffsetX; final int spaceRight = displayFrameRight - anchorLeftInScreen; - if (width <= spaceRight) { + if (anchorLeftInScreen >= 0 && width <= spaceRight) { return true; }