From 489c39d2db3be43e34c5ac55e09d8c17a5a04688 Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Fri, 24 Jun 2016 13:58:16 -0700 Subject: [PATCH] PopupWindow: Use DISPLAY_CLIP_VERTICAL/HORIZONTAL. When we want the WindowManager to clip our requested width/height to the display frame, we need to pass DISPLAY_CLIP_VERTICAL/HORIZONTAL. It seems this behavior was unintentionally applied without this flag in previous releases. Bug: 29602363 Change-Id: Ib98060e36efde0dbaabb59a758da5374035dbb62 --- core/java/android/widget/PopupWindow.java | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/core/java/android/widget/PopupWindow.java b/core/java/android/widget/PopupWindow.java index 4066ef1bbb9df..6477f079cb7fe 100644 --- a/core/java/android/widget/PopupWindow.java +++ b/core/java/android/widget/PopupWindow.java @@ -1393,6 +1393,14 @@ public class PopupWindow { } } + private int computeGravity() { + int gravity = Gravity.START | Gravity.TOP; + if (mClipToScreen || mClippingEnabled) { + gravity |= Gravity.DISPLAY_CLIP_VERTICAL | Gravity.DISPLAY_CLIP_HORIZONTAL; + } + return gravity; + } + /** *

Generate the layout parameters for the popup window.

* @@ -1407,7 +1415,7 @@ public class PopupWindow { // screen. The view is then positioned to the appropriate location by // setting the x and y offsets to match the anchor's bottom-left // corner. - p.gravity = Gravity.START | Gravity.TOP; + p.gravity = computeGravity(); p.flags = computeFlags(p.flags); p.type = mWindowLayoutType; p.token = token; @@ -1958,6 +1966,12 @@ public class PopupWindow { update = true; } + final int newGravity = computeGravity(); + if (newGravity != p.gravity) { + p.gravity = newGravity; + update = true; + } + if (update) { setLayoutDirectionFromAnchor(); mWindowManager.updateViewLayout(mDecorView, p); @@ -2064,6 +2078,12 @@ public class PopupWindow { update = true; } + final int newGravity = computeGravity(); + if (newGravity != p.gravity) { + p.gravity = newGravity; + update = true; + } + int newAccessibilityIdOfAnchor = (mAnchor != null) ? mAnchor.get().getAccessibilityViewId() : -1; if (newAccessibilityIdOfAnchor != p.accessibilityIdOfAnchor) {