From 2665604edda9d5cfb6aa6b94a654982951ba20d3 Mon Sep 17 00:00:00 2001 From: Robert Carr Date: Tue, 19 Apr 2016 19:10:44 -0700 Subject: [PATCH] Respect WRAP_CONTENT when resolving drop down position. We recently added the width/height <0 check to prevent passing unresolved widths in to tryFitVertical or tryFitHorizontal and produce strange behaviors. This made more sense than the code before it but still not that much sense. We need to treat MATCH_PARENT and WRAP_CONTENT differently as the documentation suggests. Bug: 28267951 Change-Id: I6f2f248c8d1f63d31bdd75c24f7250c28381c712 --- core/java/android/widget/PopupWindow.java | 26 ++++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/core/java/android/widget/PopupWindow.java b/core/java/android/widget/PopupWindow.java index bb883ea883273..9c44f575b1131 100644 --- a/core/java/android/widget/PopupWindow.java +++ b/core/java/android/widget/PopupWindow.java @@ -54,6 +54,8 @@ import java.lang.ref.WeakReference; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME; import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH; +import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; +import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; /** *

@@ -1305,15 +1307,15 @@ public class PopupWindow { private PopupBackgroundView createBackgroundView(View contentView) { final ViewGroup.LayoutParams layoutParams = mContentView.getLayoutParams(); final int height; - if (layoutParams != null && layoutParams.height == ViewGroup.LayoutParams.WRAP_CONTENT) { - height = ViewGroup.LayoutParams.WRAP_CONTENT; + if (layoutParams != null && layoutParams.height == WRAP_CONTENT) { + height = WRAP_CONTENT; } else { - height = ViewGroup.LayoutParams.MATCH_PARENT; + height = MATCH_PARENT; } final PopupBackgroundView backgroundView = new PopupBackgroundView(mContext); final PopupBackgroundView.LayoutParams listParams = new PopupBackgroundView.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, height); + MATCH_PARENT, height); backgroundView.addView(contentView, listParams); return backgroundView; @@ -1328,14 +1330,14 @@ public class PopupWindow { private PopupDecorView createDecorView(View contentView) { final ViewGroup.LayoutParams layoutParams = mContentView.getLayoutParams(); final int height; - if (layoutParams != null && layoutParams.height == ViewGroup.LayoutParams.WRAP_CONTENT) { - height = ViewGroup.LayoutParams.WRAP_CONTENT; + if (layoutParams != null && layoutParams.height == WRAP_CONTENT) { + height = WRAP_CONTENT; } else { - height = ViewGroup.LayoutParams.MATCH_PARENT; + height = MATCH_PARENT; } final PopupDecorView decorView = new PopupDecorView(mContext); - decorView.addView(contentView, ViewGroup.LayoutParams.MATCH_PARENT, height); + decorView.addView(contentView, MATCH_PARENT, height); decorView.setClipChildren(false); decorView.setClipToPadding(false); @@ -1522,11 +1524,15 @@ public class PopupWindow { // to fill in real width and height values. final Rect displayFrame = new Rect(); anchor.getWindowVisibleDisplayFrame(displayFrame); - if (width < 0) { + if (width == MATCH_PARENT) { width = displayFrame.right - displayFrame.left; + } else if (width == WRAP_CONTENT) { + width = mContentView.getMeasuredWidth(); } - if (height < 0) { + if (height == MATCH_PARENT) { height = displayFrame.bottom - displayFrame.top; + } else if (height == WRAP_CONTENT) { + height = mContentView.getMeasuredHeight(); }