diff options
| author | 2024-02-22 16:50:38 +0900 | |
|---|---|---|
| committer | 2024-02-29 19:09:29 +0900 | |
| commit | 0e0aed43232b98fc49fa69e551c0340c57c274b6 (patch) | |
| tree | 750f280dcbde502380fcd26b9e422fe019bada7b | |
| parent | 31e0f961839161a12f2bc0892c6b4261697d5781 (diff) | |
Use window metrics to estimate visible display frame
When the view is not attached to a view tree, we used the display
getRealSize to get an estimated result. This will be affected by the
Configuration hidden fields. It will not always have the stable result
with changes in the configuration.
Use the window metrics instead to estimate the result when the View has
access to the WindowManager to make the result better matches the
description of the public API.
Test: CTS ViewTest
Bug: 321143205
Change-Id: I823acadb0a50272b74288cfcefea2843c07a26c5
| -rw-r--r-- | core/java/android/view/View.java | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index cd6d79c81b98..986ed0e33e24 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -16716,10 +16716,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback, mAttachInfo.mViewRootImpl.getWindowVisibleDisplayFrame(outRect); 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); + // TODO (b/327559224): Refine the behavior to better reflect the window environment with API + // doc updates. + final WindowManager windowManager = mContext.getSystemService(WindowManager.class); + final WindowMetrics metrics = windowManager.getMaximumWindowMetrics(); + final Insets insets = metrics.getWindowInsets().getInsets( + WindowInsets.Type.navigationBars() | WindowInsets.Type.displayCutout()); + outRect.set(metrics.getBounds()); + outRect.inset(insets); + outRect.offsetTo(0, 0); } /** |