WindowInfoTracker
interface WindowInfoTracker
WindowInfoTrackerCallbackAdapter |
This class is deprecated. This adapter is no longer necessary. |
An interface to provide all the relevant info about a android.view.Window.
| See also | |
|---|---|
getOrCreate |
to get an instance. |
Summary
Public companion functions |
|
|---|---|
WindowInfoTracker |
getOrCreate(context: Context)Provide an instance of |
Public properties |
|
|---|---|
open List<SupportedPosture> |
@RequiresWindowSdkExtension(version = 6)Returns the |
Public companion functions
getOrCreate
fun getOrCreate(context: Context): WindowInfoTracker
Provide an instance of WindowInfoTracker that is associated to the given Context. The instance created should be safe to retain globally. The actual data is provided by WindowInfoTracker.windowLayoutInfo and requires an Activity.
| See also | |
|---|---|
windowLayoutInfo |
Public functions
getCurrentWindowLayoutInfo
@RequiresWindowSdkExtension(version = 9)
open fun getCurrentWindowLayoutInfo(context: @UiContext Context): WindowLayoutInfo
Returns the current WindowLayoutInfo for the given context.
This API provides a convenient way to access the current WindowLayoutInfo. It can be used after the context associated window has been created, such as Activity.onCreate. Calling it before that will return an empty info.
For apps that need to update layout UI based on the WindowLayoutInfo, it should also listen to windowLayoutInfo for any changes later.
| Parameters | |
|---|---|
context: @UiContext Context |
a |
| Returns | |
|---|---|
WindowLayoutInfo |
the current |
| Throws | |
|---|---|
UnsupportedOperationException |
if |
IllegalArgumentException |
|
NotImplementedError |
when this method has no supporting implementation. |
registerWindowEngagementInfoListener
open fun registerWindowEngagementInfoListener(
context: @UiContext Context,
executor: Executor,
listener: Consumer<WindowEngagementInfo>
): Unit
Registers a UiContext listener to consume WindowEngagementInfo values. If the same listener is registered twice then this method is a no-op.
This method can be long-running as it performs an initial check of all input devices. It is recommended to provide a background Executor and call this method from a background coroutine context.
| Parameters | |
|---|---|
context: @UiContext Context |
|
executor: Executor |
that the listener will invoke on. |
listener: Consumer<WindowEngagementInfo> |
for |
| See also | |
|---|---|
windowEngagementInfo |
registerWindowLayoutInfoListener
open fun registerWindowLayoutInfoListener(
context: @UiContext Context,
executor: Executor,
listener: Consumer<WindowLayoutInfo>
): Unit
Registers a UiContext listener to consume WindowLayoutInfo values. If the same listener is registered twice then this method is a no-op.
| Parameters | |
|---|---|
context: @UiContext Context |
|
executor: Executor |
that the listener will invoke on. |
listener: Consumer<WindowLayoutInfo> |
for |
| See also | |
|---|---|
windowLayoutInfo |
unregisterWindowEngagementInfoListener
open fun unregisterWindowEngagementInfoListener(
listener: Consumer<WindowEngagementInfo>
): Unit
Unregister a listener to stop consuming WindowEngagementInfo values. If the listener has already been removed then this is a no-op.
| See also | |
|---|---|
windowEngagementInfo |
unregisterWindowLayoutInfoListener
open fun unregisterWindowLayoutInfoListener(
listener: Consumer<WindowLayoutInfo>
): Unit
Unregister a listener to stop consuming WindowLayoutInfo values. If the listener has already been removed then this is a no-op.
| See also | |
|---|---|
windowLayoutInfo |
windowEngagementInfo
open fun windowEngagementInfo(context: @UiContext Context): Flow<WindowEngagementInfo>
A Flow of WindowEngagementInfo that contains the current engagement modes.
This method can be long-running as it performs an initial check of all input devices. It is recommended to collect this Flow on a background dispatcher.
| See also | |
|---|---|
WindowEngagementInfo |
windowLayoutInfo
fun windowLayoutInfo(activity: Activity): Flow<WindowLayoutInfo>
A Flow of WindowLayoutInfo that contains all the available features. A WindowLayoutInfo contains a List of DisplayFeature that intersect the associated android.view.Window.
The first WindowLayoutInfo will not be emitted until Activity.onStart has been called. which values you receive and when is device dependent.
It is recommended to test the following scenarios since behaviors may differ between hardware implementations:
-
Values are emitted immediately after subscribing to this function.
-
There is a long delay between subscribing and receiving the first value.
-
Never receiving a value after subscription.
Since the information is associated to the Activity you should not retain the Flow across Activity recreations. Doing so can result in unpredictable behavior such as a memory leak or incorrect values for WindowLayoutInfo.
| See also | |
|---|---|
WindowLayoutInfo |
|
DisplayFeature |
windowLayoutInfo
open fun windowLayoutInfo(context: @UiContext Context): Flow<WindowLayoutInfo>
A Flow of WindowLayoutInfo that contains all the available features. A WindowLayoutInfo contains a List of DisplayFeature that intersect the associated android.view.Window.
This method exports the same content as the windowLayoutInfo method that accepts an Activity as a parameter, but also supports non-Activity windows to receive WindowLayoutInfo updates. A WindowLayoutInfo value should be published when DisplayFeature have changed, but the behavior is ultimately decided by the hardware implementation. It is recommended to test the following scenarios:
-
Values are emitted immediately after subscribing to this function.
-
There is a long delay between subscribing and receiving the first value.
-
Never receiving a value after subscription.
A derived class may throw NotImplementedError if this method is not overridden. Obtaining a WindowInfoTracker through WindowInfoTracker.getOrCreate guarantees having a default implementation for this method.
If the passed context is not an Activity and WindowSdkExtensions.extensionVersion is less than 2, the flow will return empty WindowLayoutInfo list flow.
| Parameters | |
|---|---|
context: @UiContext Context |
a |
| Throws | |
|---|---|
IllegalArgumentException |
|
NotImplementedError |
when this method has no supporting implementation. |
| See also | |
|---|---|
WindowLayoutInfo |
|
DisplayFeature |
Public properties
supportedPostures
@RequiresWindowSdkExtension(version = 6)
open val supportedPostures: List<SupportedPosture>
Returns the List of SupportedPosture values. This value will not change during runtime. These values are for determining if the device supports the given SupportedPosture but does not mean the device is in the given SupportedPosture. Use windowLayoutInfo to determine the current state of the DisplayFeature's on the device.
| Throws | |
|---|---|
UnsupportedOperationException |
if |
NotImplementedError |
if a derived test class does not override this method. |
| See also | |
|---|---|
windowLayoutInfo |
Extension functions
WindowInfoTracker.windowLayoutInfoFlowable
fun WindowInfoTracker.windowLayoutInfoFlowable(activity: Activity): Flowable<WindowLayoutInfo>
Return a Flowable stream of WindowLayoutInfo.
| See also | |
|---|---|
windowLayoutInfo |
WindowInfoTracker.windowLayoutInfoFlowable
fun WindowInfoTracker.windowLayoutInfoFlowable(activity: Activity): Flowable<WindowLayoutInfo>
Return a Flowable stream of WindowLayoutInfo.
| See also | |
|---|---|
windowLayoutInfo |
WindowInfoTracker.windowLayoutInfoFlowable
fun WindowInfoTracker.windowLayoutInfoFlowable(context: @UiContext Context): Flowable<WindowLayoutInfo>
Return a Flowable stream of WindowLayoutInfo.
| See also | |
|---|---|
windowLayoutInfo |
WindowInfoTracker.windowLayoutInfoFlowable
fun WindowInfoTracker.windowLayoutInfoFlowable(context: @UiContext Context): Flowable<WindowLayoutInfo>
Return a Flowable stream of WindowLayoutInfo.
| See also | |
|---|---|
windowLayoutInfo |
WindowInfoTracker.windowLayoutInfoObservable
fun WindowInfoTracker.windowLayoutInfoObservable(activity: Activity): Observable<WindowLayoutInfo>
Return an Observable stream of WindowLayoutInfo.
| See also | |
|---|---|
windowLayoutInfo |
WindowInfoTracker.windowLayoutInfoObservable
fun WindowInfoTracker.windowLayoutInfoObservable(activity: Activity): Observable<WindowLayoutInfo>
Return an Observable stream of WindowLayoutInfo.
| See also | |
|---|---|
windowLayoutInfo |
WindowInfoTracker.windowLayoutInfoObservable
fun WindowInfoTracker.windowLayoutInfoObservable(
context: @UiContext Context
): Observable<WindowLayoutInfo>
Return an Observable stream of WindowLayoutInfo.
| See also | |
|---|---|
windowLayoutInfo |
WindowInfoTracker.windowLayoutInfoObservable
fun WindowInfoTracker.windowLayoutInfoObservable(
context: @UiContext Context
): Observable<WindowLayoutInfo>
Return an Observable stream of WindowLayoutInfo.
| See also | |
|---|---|
windowLayoutInfo |