From 4ebacd3abfff5555c92358b85a1a6fc08707f086 Mon Sep 17 00:00:00 2001 From: "hh83.kim" Date: Wed, 2 Oct 2019 13:11:30 +0900 Subject: Fix PopupWindow's wrong location Sometimes, we have seen cases that Popupwindow is located in the wrong place. So we suggest some modification of logics in tryFitVertical and tryFitHorizontal methods of PopupWindow. In those methods, there exists a statement whether the positions of anchor (anchorTopInScreen and anchorLeftInScreen) are bigger than 0. However, there are some cases that those values become positive even though corresponding popup windows are not visible to user (places out of window area), especially on devices with displaycuout, or apps with multiwindow modes. So we modify to the anchor's top and left position values should be compared with top and left value of displayFrame, respectively, not 0. Test: CtsWidgetTestCases:test android.widget.cts.PopupWindowTest Bug: b/135749682 --- core/java/android/widget/PopupWindow.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/java/android/widget/PopupWindow.java b/core/java/android/widget/PopupWindow.java index bf696f5a7c53..cc3d74477342 100644 --- a/core/java/android/widget/PopupWindow.java +++ b/core/java/android/widget/PopupWindow.java @@ -1818,7 +1818,7 @@ public class PopupWindow { final int winOffsetY = screenLocationY - drawingLocationY; final int anchorTopInScreen = outParams.y + winOffsetY; final int spaceBelow = displayFrameBottom - anchorTopInScreen; - if (anchorTopInScreen >= 0 && height <= spaceBelow) { + if (anchorTopInScreen >= displayFrameTop && height <= spaceBelow) { return true; } @@ -1880,7 +1880,7 @@ public class PopupWindow { final int winOffsetX = screenLocationX - drawingLocationX; final int anchorLeftInScreen = outParams.x + winOffsetX; final int spaceRight = displayFrameRight - anchorLeftInScreen; - if (anchorLeftInScreen >= 0 && width <= spaceRight) { + if (anchorLeftInScreen >= displayFrameLeft && width <= spaceRight) { return true; } -- cgit v1.2.3-59-g8ed1b