WindowInfoTracker
public 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 methods
getCurrentWindowLayoutInfo
@RequiresWindowSdkExtension(version = 9)
default @NonNull WindowLayoutInfo getCurrentWindowLayoutInfo(@UiContext @NonNull Context context)
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 | |
|---|---|
@UiContext @NonNull Context context |
a |
| Returns | |
|---|---|
@NonNull WindowLayoutInfo |
the current |
| Throws | |
|---|---|
UnsupportedOperationException |
if |
IllegalArgumentException |
|
NotImplementedError |
when this method has no supporting implementation. |
getOrCreate
default static final @NonNull WindowInfoTracker getOrCreate(@NonNull Context context)
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 |
getSupportedPostures
@RequiresWindowSdkExtension(version = 6)
default @NonNull List<@NonNull SupportedPosture> getSupportedPostures()
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 |
registerWindowEngagementInfoListener
default void registerWindowEngagementInfoListener(
@UiContext @NonNull Context context,
@NonNull Executor executor,
@NonNull Consumer<@NonNull WindowEngagementInfo> listener
)
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 | |
|---|---|
@UiContext @NonNull Context context |
|
@NonNull Executor executor |
that the listener will invoke on. |
@NonNull Consumer<@NonNull WindowEngagementInfo> listener |
for |
| See also | |
|---|---|
windowEngagementInfo |
registerWindowLayoutInfoListener
default void registerWindowLayoutInfoListener(
@UiContext @NonNull Context context,
@NonNull Executor executor,
@NonNull Consumer<@NonNull WindowLayoutInfo> listener
)
Registers a UiContext listener to consume WindowLayoutInfo values. If the same listener is registered twice then this method is a no-op.
| Parameters | |
|---|---|
@UiContext @NonNull Context context |
|
@NonNull Executor executor |
that the listener will invoke on. |
@NonNull Consumer<@NonNull WindowLayoutInfo> listener |
for |
| See also | |
|---|---|
windowLayoutInfo |
unregisterWindowEngagementInfoListener
default void unregisterWindowEngagementInfoListener(
@NonNull Consumer<@NonNull WindowEngagementInfo> listener
)
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
default void unregisterWindowLayoutInfoListener(
@NonNull Consumer<@NonNull WindowLayoutInfo> listener
)
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
default @NonNull Flow<@NonNull WindowEngagementInfo> windowEngagementInfo(@UiContext @NonNull Context context)
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
abstract @NonNull Flow<@NonNull WindowLayoutInfo> windowLayoutInfo(@NonNull Activity activity)
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
default @NonNull Flow<@NonNull WindowLayoutInfo> windowLayoutInfo(@UiContext @NonNull Context context)
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 | |
|---|---|
@UiContext @NonNull Context context |
a |
| Throws | |
|---|---|
IllegalArgumentException |
|
NotImplementedError |
when this method has no supporting implementation. |
| See also | |
|---|---|
WindowLayoutInfo |
|
DisplayFeature |
Extension functions
WindowInfoTrackerRx.windowLayoutInfoFlowable
default final @NonNull Flowable<@NonNull WindowLayoutInfo> WindowInfoTrackerRx.windowLayoutInfoFlowable(
@NonNull WindowInfoTracker receiver,
@NonNull Activity activity
)
Return a Flowable stream of WindowLayoutInfo.
| See also | |
|---|---|
windowLayoutInfo |
WindowInfoTrackerRx.windowLayoutInfoFlowable
default final @NonNull Flowable<@NonNull WindowLayoutInfo> WindowInfoTrackerRx.windowLayoutInfoFlowable(
@NonNull WindowInfoTracker receiver,
@NonNull Activity activity
)
Return a Flowable stream of WindowLayoutInfo.
| See also | |
|---|---|
windowLayoutInfo |
WindowInfoTrackerRx.windowLayoutInfoFlowable
default final @NonNull Flowable<@NonNull WindowLayoutInfo> WindowInfoTrackerRx.windowLayoutInfoFlowable(
@NonNull WindowInfoTracker receiver,
@UiContext @NonNull Context context
)
Return a Flowable stream of WindowLayoutInfo.
| See also | |
|---|---|
windowLayoutInfo |
WindowInfoTrackerRx.windowLayoutInfoFlowable
default final @NonNull Flowable<@NonNull WindowLayoutInfo> WindowInfoTrackerRx.windowLayoutInfoFlowable(
@NonNull WindowInfoTracker receiver,
@UiContext @NonNull Context context
)
Return a Flowable stream of WindowLayoutInfo.
| See also | |
|---|---|
windowLayoutInfo |
WindowInfoTrackerRx.windowLayoutInfoObservable
default final @NonNull Observable<@NonNull WindowLayoutInfo> WindowInfoTrackerRx.windowLayoutInfoObservable(
@NonNull WindowInfoTracker receiver,
@NonNull Activity activity
)
Return an Observable stream of WindowLayoutInfo.
| See also | |
|---|---|
windowLayoutInfo |
WindowInfoTrackerRx.windowLayoutInfoObservable
default final @NonNull Observable<@NonNull WindowLayoutInfo> WindowInfoTrackerRx.windowLayoutInfoObservable(
@NonNull WindowInfoTracker receiver,
@NonNull Activity activity
)
Return an Observable stream of WindowLayoutInfo.
| See also | |
|---|---|
windowLayoutInfo |
WindowInfoTrackerRx.windowLayoutInfoObservable
default final @NonNull Observable<@NonNull WindowLayoutInfo> WindowInfoTrackerRx.windowLayoutInfoObservable(
@NonNull WindowInfoTracker receiver,
@UiContext @NonNull Context context
)
Return an Observable stream of WindowLayoutInfo.
| See also | |
|---|---|
windowLayoutInfo |
WindowInfoTrackerRx.windowLayoutInfoObservable
default final @NonNull Observable<@NonNull WindowLayoutInfo> WindowInfoTrackerRx.windowLayoutInfoObservable(
@NonNull WindowInfoTracker receiver,
@UiContext @NonNull Context context
)
Return an Observable stream of WindowLayoutInfo.
| See also | |
|---|---|
windowLayoutInfo |