WindowInfoTracker


public interface WindowInfoTracker

Known direct subclasses
WindowInfoTrackerCallbackAdapter

An adapted interface for WindowInfoTracker that allows listening for events via a callback shaped API.


An interface to provide all the relevant info about a android.view.Window.

See also
getOrCreate

to get an instance.

Summary

Public methods

default static final @NonNull WindowInfoTracker

Provide an instance of WindowInfoTracker that is associated to the given Context.

default @NonNull List<@NonNull SupportedPosture>

Returns the List of SupportedPosture values.

abstract @NonNull Flow<@NonNull WindowLayoutInfo>

A Flow of WindowLayoutInfo that contains all the available features.

default @NonNull Flow<@NonNull WindowLayoutInfo>

A Flow of WindowLayoutInfo that contains all the available features.

Extension functions

default final @NonNull Flowable<@NonNull WindowLayoutInfo>

Return a Flowable stream of WindowLayoutInfo.

default final @NonNull Flowable<@NonNull WindowLayoutInfo>

Return a Flowable stream of WindowLayoutInfo.

default final @NonNull Flowable<@NonNull WindowLayoutInfo>

Return a Flowable stream of WindowLayoutInfo.

default final @NonNull Flowable<@NonNull WindowLayoutInfo>

Return a Flowable stream of WindowLayoutInfo.

default final @NonNull Observable<@NonNull WindowLayoutInfo>

Return an Observable stream of WindowLayoutInfo.

default final @NonNull Observable<@NonNull WindowLayoutInfo>

Return an Observable stream of WindowLayoutInfo.

default final @NonNull Observable<@NonNull WindowLayoutInfo>

Return an Observable stream of WindowLayoutInfo.

default final @NonNull Observable<@NonNull WindowLayoutInfo>

Return an Observable stream of WindowLayoutInfo.

Public methods

getOrCreate

Added in 1.0.0
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.

Parameters
@NonNull Context context

Any valid Context.

See also
windowLayoutInfo

getSupportedPostures

Added in 1.4.0-alpha05
default @NonNull List<@NonNull SupportedPosturegetSupportedPostures()

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
kotlin.UnsupportedOperationException

if WindowSdkExtensions.extensionVersion is less than 6.

kotlin.NotImplementedError

if a derived test class does not override this method.

See also
windowLayoutInfo

windowLayoutInfo

Added in 1.0.0
abstract @NonNull Flow<@NonNull WindowLayoutInfowindowLayoutInfo(@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.

Parameters
@NonNull Activity activity

an Activity that has not been destroyed.

windowLayoutInfo

Added in 1.1.0
default @NonNull Flow<@NonNull WindowLayoutInfowindowLayoutInfo(@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 WindowLayoutInfo.windowLayoutInfo(activity: Activity), 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 UiContext such as an Activity, an InputMethodService, or an instance created via Context.createWindowContext that listens to configuration changes.

Throws
kotlin.NotImplementedError

when Context is not an UiContext or this method has no supporting implementation.

Extension functions

WindowInfoTrackerRx.windowLayoutInfoFlowable

default final @NonNull Flowable<@NonNull WindowLayoutInfoWindowInfoTrackerRx.windowLayoutInfoFlowable(
    @NonNull WindowInfoTracker receiver,
    @NonNull Activity activity
)

Return a Flowable stream of WindowLayoutInfo.

See also
windowLayoutInfo

WindowInfoTrackerRx.windowLayoutInfoFlowable

default final @NonNull Flowable<@NonNull WindowLayoutInfoWindowInfoTrackerRx.windowLayoutInfoFlowable(
    @NonNull WindowInfoTracker receiver,
    @NonNull Activity activity
)

Return a Flowable stream of WindowLayoutInfo.

See also
windowLayoutInfo

WindowInfoTrackerRx.windowLayoutInfoFlowable

default final @NonNull Flowable<@NonNull WindowLayoutInfoWindowInfoTrackerRx.windowLayoutInfoFlowable(
    @NonNull WindowInfoTracker receiver,
    @UiContext @NonNull Context context
)

Return a Flowable stream of WindowLayoutInfo.

See also
windowLayoutInfo

WindowInfoTrackerRx.windowLayoutInfoFlowable

default final @NonNull Flowable<@NonNull WindowLayoutInfoWindowInfoTrackerRx.windowLayoutInfoFlowable(
    @NonNull WindowInfoTracker receiver,
    @UiContext @NonNull Context context
)

Return a Flowable stream of WindowLayoutInfo.

See also
windowLayoutInfo

WindowInfoTrackerRx.windowLayoutInfoObservable

default final @NonNull Observable<@NonNull WindowLayoutInfoWindowInfoTrackerRx.windowLayoutInfoObservable(
    @NonNull WindowInfoTracker receiver,
    @NonNull Activity activity
)

Return an Observable stream of WindowLayoutInfo.

See also
windowLayoutInfo

WindowInfoTrackerRx.windowLayoutInfoObservable

default final @NonNull Observable<@NonNull WindowLayoutInfoWindowInfoTrackerRx.windowLayoutInfoObservable(
    @NonNull WindowInfoTracker receiver,
    @NonNull Activity activity
)

Return an Observable stream of WindowLayoutInfo.

See also
windowLayoutInfo

WindowInfoTrackerRx.windowLayoutInfoObservable

default final @NonNull Observable<@NonNull WindowLayoutInfoWindowInfoTrackerRx.windowLayoutInfoObservable(
    @NonNull WindowInfoTracker receiver,
    @UiContext @NonNull Context context
)

Return an Observable stream of WindowLayoutInfo.

See also
windowLayoutInfo

WindowInfoTrackerRx.windowLayoutInfoObservable

default final @NonNull Observable<@NonNull WindowLayoutInfoWindowInfoTrackerRx.windowLayoutInfoObservable(
    @NonNull WindowInfoTracker receiver,
    @UiContext @NonNull Context context
)

Return an Observable stream of WindowLayoutInfo.

See also
windowLayoutInfo