summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Vladislav Kaznacheev <kaznacheev@google.com> 2017-03-06 14:21:10 -0800
committer Vladislav Kaznacheev <kaznacheev@google.com> 2017-03-06 14:21:10 -0800
commit07084924be4ce0dc67f150d77b886f21fcb01aa7 (patch)
tree44ef73ae38a749eb405960fd9d4019130a2ce805
parente20f8fb5b4f39332d7a465f6b096d303ab4fadd9 (diff)
Respect PopupWindow.setOverlapAnchor when above anchor
Currently if a popup menu is shown above the anchor, it is anchored to the anchor's top edge regardless of the value of mOverlapAnchor. Fixing the vertical offset correction and the computation of the vertical space available above the anchor. Bug: 36000552 Test: android.widget.cts.PopupWindowTest#testOverlapAnchor Change-Id: Ifb71ff1fc0aa0df58e4919fd229c2623a2bcbe3d
-rw-r--r--core/java/android/widget/PopupWindow.java25
1 files changed, 20 insertions, 5 deletions
diff --git a/core/java/android/widget/PopupWindow.java b/core/java/android/widget/PopupWindow.java
index d096baf3c943..26b3ae2c42fc 100644
--- a/core/java/android/widget/PopupWindow.java
+++ b/core/java/android/widget/PopupWindow.java
@@ -1620,17 +1620,32 @@ public class PopupWindow {
int anchorHeight, int drawingLocationY, int screenLocationY, int displayFrameTop,
int displayFrameBottom, boolean allowResize) {
final int winOffsetY = screenLocationY - drawingLocationY;
- final int anchorTopInScreen = outParams.y + winOffsetY;
- final int spaceBelow = displayFrameBottom - anchorTopInScreen;
- if (anchorTopInScreen >= 0 && height <= spaceBelow) {
+ final int popupScreenTop = outParams.y + winOffsetY;
+ final int spaceBelow = displayFrameBottom - popupScreenTop;
+ if (popupScreenTop >= 0 && height <= spaceBelow) {
return true;
}
- final int spaceAbove = anchorTopInScreen - anchorHeight - displayFrameTop;
+ final int popupScreenBottom;
+ if (mOverlapAnchor) {
+ // popupScreenTop equals the anchor's top at this point.
+ // When shown above the anchor, an overlapping popup's bottom should be aligned with
+ // the anchor's bottom.
+ popupScreenBottom = popupScreenTop + anchorHeight;
+ } else {
+ // popupScreenTop equals the anchor's bottom at this point.
+ // When shown above the anchor, a non-overlapping popup's bottom is aligned with
+ // the anchor's top.
+ popupScreenBottom = popupScreenTop - anchorHeight;
+ }
+ final int spaceAbove = popupScreenBottom - displayFrameTop;
if (height <= spaceAbove) {
// Move everything up.
if (mOverlapAnchor) {
- yOffset += anchorHeight;
+ // Add one anchorHeight to compensate for the correction made at the start of
+ // findDropDownPosition, and another to account for being aligned to the anchor's
+ // bottom, not top.
+ yOffset += anchorHeight * 2;
}
outParams.y = drawingLocationY - height + yOffset;