From 8175846ed686077736c985f0ae4d236b7a4c647c Mon Sep 17 00:00:00 2001 From: Jorim Jaggi Date: Mon, 29 Feb 2016 14:41:09 +0100 Subject: [PATCH] Fix popup window calculation for multi-window If ignoreBottomDecorations=true, the display size was extracted from the resources. However, this didn't work if the parent window was in multi-window, as all the calculations went wrong. Instead, introduce View.getWindowDisplayFrame which returns the "full" frame of the task the window is currently in, without any insets, and use that to calculate the bottom edge. Bug: 26255254 Change-Id: I8b235b335775022ae399ee082d1200aa76cc047c --- core/java/android/view/View.java | 21 +++++++++++++++++++++ core/java/android/widget/PopupWindow.java | 15 ++++++--------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index e7be7af48a7be..9bd3df0c1a1fe 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -10269,6 +10269,27 @@ public class View implements Drawable.Callback, KeyEvent.Callback, d.getRectSize(outRect); } + /** + * Like {@link #getWindowVisibleDisplayFrame}, but returns the "full" display frame this window + * is currently in without any insets. + * + * @hide + */ + public void getWindowDisplayFrame(Rect outRect) { + if (mAttachInfo != null) { + try { + mAttachInfo.mSession.getDisplayFrame(mAttachInfo.mWindow, outRect); + } catch (RemoteException e) { + return; + } + return; + } + // The view is not attached to a display so we don't have a context. + // Make a best guess about the display size. + Display d = DisplayManagerGlobal.getInstance().getRealDisplay(Display.DEFAULT_DISPLAY); + d.getRectSize(outRect); + } + /** * Dispatch a notification about a resource configuration change down * the view hierarchy. diff --git a/core/java/android/widget/PopupWindow.java b/core/java/android/widget/PopupWindow.java index 54b3932dfeb23..df2f575893616 100644 --- a/core/java/android/widget/PopupWindow.java +++ b/core/java/android/widget/PopupWindow.java @@ -23,7 +23,6 @@ import com.android.internal.R; import android.annotation.NonNull; import android.content.Context; -import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.PixelFormat; import android.graphics.Rect; @@ -1587,18 +1586,16 @@ public class PopupWindow { public int getMaxAvailableHeight( @NonNull View anchor, int yOffset, boolean ignoreBottomDecorations) { final Rect displayFrame = new Rect(); - anchor.getWindowVisibleDisplayFrame(displayFrame); + if (ignoreBottomDecorations) { + anchor.getWindowDisplayFrame(displayFrame); + } else { + anchor.getWindowVisibleDisplayFrame(displayFrame); + } final int[] anchorPos = mDrawingLocation; anchor.getLocationOnScreen(anchorPos); - final int bottomEdge; - if (ignoreBottomDecorations) { - final Resources res = anchor.getContext().getResources(); - bottomEdge = res.getDisplayMetrics().heightPixels; - } else { - bottomEdge = displayFrame.bottom; - } + final int bottomEdge = displayFrame.bottom; final int distanceToBottom; if (mOverlapAnchor) {