WindowInfoTracker


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 companion functions

WindowInfoTracker
getOrCreate(context: Context)

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

Public functions

Flow<WindowLayoutInfo>

A Flow of WindowLayoutInfo that contains all the available features.

open Flow<WindowLayoutInfo>

A Flow of WindowLayoutInfo that contains all the available features.

Public properties

open List<SupportedPosture>

Returns the List of SupportedPosture values.

Public companion functions

getOrCreate

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

Parameters
context: Context

Any valid Context.

See also
windowLayoutInfo

Public functions

windowLayoutInfo

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

Parameters
activity: Activity

an Activity that has not been destroyed.

windowLayoutInfo

Added in 1.1.0
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 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
context: @UiContext 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.

Public properties

supportedPostures

Added in 1.4.0-alpha05
@RequiresWindowSdkExtension(version = 6)
open val supportedPosturesList<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
kotlin.UnsupportedOperationException

if WindowSdkExtensions.extensionVersion is less than 6.

kotlin.NotImplementedError

if a derived test class does not override this method.

See also
windowLayoutInfo

Extension functions