WindowMetricsCalculator
interface WindowMetricsCalculator
An interface to calculate the WindowMetrics for an Activity or a UiContext.
Summary
Public companion functions |
|
|---|---|
WindowMetricsCalculator |
Public functions |
|
|---|---|
WindowMetrics |
computeCurrentWindowMetrics(activity: Activity)Computes the size and position of the area the window would occupy with |
open WindowMetrics |
computeCurrentWindowMetrics(context: @UiContext Context)Computes the size and position of the area the window would occupy with |
open WindowMetrics? |
computeCurrentWindowMetricsOrNull(context: @UiContext Context)Returns the current |
WindowMetrics |
computeMaximumWindowMetrics(activity: Activity)Computes the maximum size and position of the area the window can expect with |
open WindowMetrics |
computeMaximumWindowMetrics(context: @UiContext Context)Computes the maximum size and position of the area the window can expect with |
open WindowMetrics? |
computeMaximumWindowMetricsOrNull(context: @UiContext Context)Returns the maximum |
Public companion functions
Public functions
computeCurrentWindowMetrics
fun computeCurrentWindowMetrics(activity: Activity): WindowMetrics
Computes the size and position of the area the window would occupy with MATCH_PARENT width and height and any combination of flags that would allow the window to extend behind display cutouts.
For example, android.view.WindowManager.LayoutParams.layoutInDisplayCutoutMode set to android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS or the android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS flag set.
The value returned from this method may be different from platform API(s) used to determine the size and position of the visible area a given context occupies. For example:
-
Display.getSizecan be used to determine the size of the visible area a window occupies, but may be subtracted to exclude certain system decorations that always appear on screen, notably the navigation bar. -
The decor view's android.view.View#getWidth and android.view.View@getHeight can be used to determine the size of the top level view in the view hierarchy, but this size is determined through a combination of
android.view.WindowManager.LayoutParamsflags and may not represent the true window size. For example, a window that does not indicate it can be displayed behind a display cutout will have the size of the decor view offset to exclude this region unless this region overlaps with the status bar, while the value returned from this method will include this region.
The value returned from this method is guaranteed to be correct on platforms Q and above. For older platforms the value may be invalid if the activity is in multi-window mode or if the navigation bar offset can not be accounted for, though a best effort is made to ensure the returned value is as close as possible to the true value. See .computeWindowBoundsP and .computeWindowBoundsN.
Note: The value of this is based on the last windowing state reported to the client.
| See also | |
|---|---|
getCurrentWindowMetrics |
|
getBounds |
computeCurrentWindowMetrics
open fun computeCurrentWindowMetrics(context: @UiContext Context): WindowMetrics
Computes the size and position of the area the window would occupy with MATCH_PARENT width and height and any combination of flags that would allow the window to extend behind display cutouts. The Context must either be a UiContext or an Application Context. We recommend using a UiContext as it will give the most accurate WindowMetrics. Using the Application Context may exclude some decorations or can provide some unexpected behaviors for multi instance apps in a desktop like environment.
| Throws | |
|---|---|
NotImplementedError |
if not implemented. The default implementation from |
IllegalArgumentException |
| See also | |
|---|---|
computeCurrentWindowMetrics |
computeCurrentWindowMetricsOrNull
open fun computeCurrentWindowMetricsOrNull(context: @UiContext Context): WindowMetrics?
Returns the current WindowMetrics or null if computeCurrentWindowMetrics fails.
| See also | |
|---|---|
computeCurrentWindowMetrics |
computeMaximumWindowMetrics
fun computeMaximumWindowMetrics(activity: Activity): WindowMetrics
Computes the maximum size and position of the area the window can expect with MATCH_PARENT width and height and any combination of flags that would allow the window to extend behind display cutouts.
The value returned from this method will always match Display.getRealSize on Android 10 and below.
| See also | |
|---|---|
getMaximumWindowMetrics |
computeMaximumWindowMetrics
open fun computeMaximumWindowMetrics(context: @UiContext Context): WindowMetrics
Computes the maximum size and position of the area the window can expect with MATCH_PARENT width and height and any combination of flags that would allow the window to extend behind display cutouts.
The value returned from this method will always match Display.getRealSize on Android 10 and below.
The Context must either be a UiContext or an Application Context. We recommend using a UiContext as it will give the most accurate WindowMetrics. Using the Application Context may exclude some decorations or can provide some unexpected behaviors for multi instance apps in a desktop like environment.
| Throws | |
|---|---|
NotImplementedError |
if not implemented. The default implementation from |
IllegalArgumentException |
| See also | |
|---|---|
computeMaximumWindowMetrics |
computeMaximumWindowMetricsOrNull
open fun computeMaximumWindowMetricsOrNull(context: @UiContext Context): WindowMetrics?
Returns the maximum WindowMetrics or null if computeMaximumWindowMetrics fails.
| See also | |
|---|---|
computeMaximumWindowMetrics |