From 085160612d9066e23c96a6cac15eb3a51481fdaf Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Tue, 23 Aug 2016 10:17:54 -0700 Subject: [PATCH] PopupWindow: Gravity fixes. First we restore the M semantics with respect to DISPLAY_CLIP_VERTICAL, which we only applied for drop downs, and omitted in the case of showAtLocation. Further, we fix an error where user specified gravity from showAtLocation is erased when calling update() by storing the gravity and including it in computeGravity(). Bug: 30445010 Bug: 30965176 Change-Id: I28a081e1237a8b41f2444717e0db21ef4181507b --- core/java/android/widget/PopupWindow.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/core/java/android/widget/PopupWindow.java b/core/java/android/widget/PopupWindow.java index 5935c7889e9c4..b12c03ca9c15d 100644 --- a/core/java/android/widget/PopupWindow.java +++ b/core/java/android/widget/PopupWindow.java @@ -193,6 +193,8 @@ public class PopupWindow { private int mAnimationStyle = ANIMATION_STYLE_DEFAULT; + private int mGravity = Gravity.NO_GRAVITY; + private static final int[] ABOVE_ANCHOR_STATE_SET = new int[] { com.android.internal.R.attr.state_above_anchor }; @@ -1141,15 +1143,11 @@ public class PopupWindow { mIsShowing = true; mIsDropdown = false; + mGravity = gravity; final WindowManager.LayoutParams p = createPopupLayoutParams(token); preparePopup(p); - // Only override the default if some gravity was specified. - if (gravity != Gravity.NO_GRAVITY) { - p.gravity = gravity; - } - p.x = x; p.y = y; @@ -1394,8 +1392,8 @@ public class PopupWindow { } private int computeGravity() { - int gravity = Gravity.START | Gravity.TOP; - if (mClipToScreen || mClippingEnabled) { + int gravity = mGravity == Gravity.NO_GRAVITY ? Gravity.START | Gravity.TOP : mGravity; + if (mIsDropdown && (mClipToScreen || mClippingEnabled)) { gravity |= Gravity.DISPLAY_CLIP_VERTICAL; } return gravity;