WindowManager
public
final
class
WindowManager
extends Object
java.lang.Object | |
↳ | androidx.window.WindowManager |
Main interaction point with the WindowManager library. An instance of this class allows polling the current state of the device and display, and registering callbacks for changes in the corresponding states.
Summary
Public constructors | |
---|---|
WindowManager(Context context)
Gets an instance of the class initialized with and connected to the provided |
|
WindowManager(Context context, WindowBackend windowBackend)
This constructor is deprecated. WindowBackend will be a required argument in the next implementation. |
Public methods | |
---|---|
WindowMetrics
|
getCurrentWindowMetrics()
Returns the |
DeviceState
|
getDeviceState()
This method is deprecated. will be removed in the next alpha |
WindowMetrics
|
getMaximumWindowMetrics()
Returns the largest |
WindowLayoutInfo
|
getWindowLayoutInfo()
This method is deprecated. will be removed in the next alpha |
void
|
registerDeviceStateChangeCallback(Executor executor, Consumer<DeviceState> callback)
This method is deprecated.
|
void
|
registerLayoutChangeCallback(Executor executor, Consumer<WindowLayoutInfo> callback)
Registers a callback for layout changes of the window of the current visual |
void
|
unregisterDeviceStateChangeCallback(Consumer<DeviceState> callback)
This method is deprecated.
|
void
|
unregisterLayoutChangeCallback(Consumer<WindowLayoutInfo> callback)
Unregisters a callback for window layout changes of the window. |
Inherited methods | |
---|---|
Public constructors
WindowManager
public WindowManager (Context context)
Gets an instance of the class initialized with and connected to the provided Context
.
All methods of this class will return information that is associated with this visual
context.
Parameters | |
---|---|
context |
Context : A visual context, such as an Activity or a ContextWrapper
around one, to use for initialization.
|
WindowManager
public WindowManager (Context context, WindowBackend windowBackend)
This constructor is deprecated.
WindowBackend will be a required argument in the next implementation.
Gets an instance of the class initialized with and connected to the provided Context
.
All methods of this class will return information that is associated with this visual
context.
Parameters | |
---|---|
context |
Context : A visual context, such as an Activity or a
ContextWrapper
around one, to use for initialization. |
windowBackend |
WindowBackend : Backing server class that will provide information for this instance.
Pass a custom WindowBackend implementation for testing. |
Public methods
getCurrentWindowMetrics
public WindowMetrics getCurrentWindowMetrics ()
Returns the WindowMetrics
according to the current system state.
The metrics describe the size 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 value of this is based on the current windowing state of the system. For
example, for activities in multi-window mode, the metrics returned are based on the
current bounds that the user has selected for the Activity
's
window.
Returns | |
---|---|
WindowMetrics |
getDeviceState
public DeviceState getDeviceState ()
This method is deprecated.
will be removed in the next alpha
Returns | |
---|---|
DeviceState |
the current DeviceState if Sidecar is present and an empty info otherwise
|
getMaximumWindowMetrics
public WindowMetrics getMaximumWindowMetrics ()
Returns the largest WindowMetrics
an app may expect in the current system state.
The metrics describe the size of the largest potential area the window might occupy with
MATCH_PARENT
width and height
and any combination of flags that would allow the window to extend behind display cutouts.
The value of this is based on the largest potential windowing state of the system. For example, for activities in multi-window mode the metrics returned are based on what the bounds would be if the user expanded the window to cover the entire screen.
Note that this might still be smaller than the size of the physical display if certain
areas of the display are not available to windows created for the associated Context
.
For example, devices with foldable displays that wrap around the enclosure may split the
physical display into different regions, one for the front and one for the back, each acting
as different logical displays. In this case getMaximumWindowMetrics()
would return
the region describing the side of the device the associated context's
window is placed.
Returns | |
---|---|
WindowMetrics |
getWindowLayoutInfo
public WindowLayoutInfo getWindowLayoutInfo ()
This method is deprecated.
will be removed in the next alpha
Returns | |
---|---|
WindowLayoutInfo |
the current WindowLayoutInfo when Sidecar is present and an empty info
otherwise
|
registerDeviceStateChangeCallback
public void registerDeviceStateChangeCallback (Executor executor, Consumer<DeviceState> callback)
This method is deprecated.
DeviceState
information has been merged into WindowLayoutInfo
Registers a callback for device state changes.
Parameters | |
---|---|
executor |
Executor |
callback |
Consumer |
registerLayoutChangeCallback
public void registerLayoutChangeCallback (Executor executor, Consumer<WindowLayoutInfo> callback)
Registers a callback for layout changes of the window of the current visual Context
.
Must be called only after the it is attached to the window.
Parameters | |
---|---|
executor |
Executor |
callback |
Consumer |
See also:
unregisterDeviceStateChangeCallback
public void unregisterDeviceStateChangeCallback (Consumer<DeviceState> callback)
This method is deprecated.
DeviceState
information has been merged into WindowLayoutInfo
Unregisters a callback for device state changes.
Parameters | |
---|---|
callback |
Consumer |
unregisterLayoutChangeCallback
public void unregisterLayoutChangeCallback (Consumer<WindowLayoutInfo> callback)
Unregisters a callback for window layout changes of the window.
Parameters | |
---|---|
callback |
Consumer |