WindowAreaControllerCallbackAdapter


class WindowAreaControllerCallbackAdapter


An adapter for WindowAreaController to provide callback APIs.

Summary

Public constructors

Public functions

Unit
addWindowAreasListener(
    executor: Executor,
    listener: Consumer<List<WindowArea>>
)

Registers a listener that is interested in the current list of WindowArea available to be interacted with.

WindowAreaSessionPresenter?

Returns the current active WindowAreaSessionPresenter if one is currently active in the WindowArea identified by the provided WindowAreaToken.

Unit
@ExperimentalWindowApi
presentContentOnWindowArea(
    windowAreaToken: WindowAreaToken,
    activity: Activity,
    executor: Executor,
    windowAreaPresentationSessionCallback: WindowAreaPresentationSessionCallback
)

Starts a presentation session on the WindowArea identified by the windowAreaToken and sends updates through the WindowAreaPresentationSessionCallback.

Unit

Removes a listener of available WindowArea records.

Unit
transferToWindowArea(
    windowAreaToken: WindowAreaToken?,
    activity: Activity
)

Moves the calling Activity and the global state of the device to the WindowArea provided.

Public constructors

WindowAreaControllerCallbackAdapter

Added in 1.2.0
WindowAreaControllerCallbackAdapter(controller: WindowAreaController)

Public functions

addWindowAreasListener

Added in 1.6.0-alpha03
fun addWindowAreasListener(
    executor: Executor,
    listener: Consumer<List<WindowArea>>
): Unit

Registers a listener that is interested in the current list of WindowArea available to be interacted with.

The listener will receive an initial value on registration, as soon as it becomes available.

Parameters
executor: Executor

to handle sending listener updates.

listener: Consumer<List<WindowArea>>

to receive updates to the list of WindowArea.

getActivePresentationSession

Added in 1.6.0-alpha03
@ExperimentalWindowApi
fun getActivePresentationSession(windowAreaToken: WindowAreaToken): WindowAreaSessionPresenter?

Returns the current active WindowAreaSessionPresenter if one is currently active in the WindowArea identified by the provided WindowAreaToken. Returns null if there is no active presentation session for the provided windowAreaToken.

presentContentOnWindowArea

Added in 1.6.0-alpha03
@ExperimentalWindowApi
fun presentContentOnWindowArea(
    windowAreaToken: WindowAreaToken,
    activity: Activity,
    executor: Executor,
    windowAreaPresentationSessionCallback: WindowAreaPresentationSessionCallback
): Unit

Starts a presentation session on the WindowArea identified by the windowAreaToken and sends updates through the WindowAreaPresentationSessionCallback.

If a presentation session is attempted to be started without it being available, WindowAreaPresentationSessionCallback.onSessionEnded will be called immediately with an IllegalStateException.

Only the top visible application can request to start a presentation session.

The presentation session will stay active until the presentation provided through WindowAreaPresentationSessionCallback.onSessionStarted is closed. The WindowArea.Type may provide different triggers to close the session such as if the calling application is no longer in the foreground, or there is a device state change that makes the window area unavailable. One example scenario is if a TYPE_REAR_FACING window area is being presented to on a foldable device that is open and has 2 screens. If the device is closed and the internal display is turned off, the session would be ended and WindowAreaPresentationSessionCallback.onSessionEnded is called to notify that the session has been ended. The session may end prematurely if the device gets to a critical thermal level, or if power saver mode is enabled.

Parameters
windowAreaToken: WindowAreaToken

identifier for which WindowArea is to be presented on

activity: Activity

An Activity that will present content on the Rear Display.

executor: Executor

Executor used to provide updates to windowAreaPresentationSessionCallback.

windowAreaPresentationSessionCallback: WindowAreaPresentationSessionCallback

to be notified of updates to the lifecycle of the currently enabled rear display presentation.

removeWindowAreasListener

Added in 1.6.0-alpha03
fun removeWindowAreasListener(listener: Consumer<List<WindowArea>>): Unit

Removes a listener of available WindowArea records. If the listener is not present then this method is a no-op.

Parameters
listener: Consumer<List<WindowArea>>

to remove from receiving status updates.

transferToWindowArea

Added in 1.6.0-alpha03
fun transferToWindowArea(
    windowAreaToken: WindowAreaToken?,
    activity: Activity
): Unit

Moves the calling Activity and the global state of the device to the WindowArea provided. This is a long-lasting and sticky operation that will outlive the application that requests this operation. Status updates can be received by registering a listener through addWindowAreasListener and then querying for the OPERATION_TRANSFER_TO_AREA operation.

Attempting to move the device to a window area when the WindowArea does not return WINDOW_AREA_STATUS_AVAILABLE will result in an IllegalStateException.

Only the top visible application can request the device to move to a WindowArea. If this operation is requested when the application is not the top level process, a SecurityException will be thrown.

Passing a null WindowAreaToken returns back to the default window area (usually going to be the android.view.Display.DEFAULT_DISPLAY). Depending on the WindowArea.Type there may be other triggers that end the session, such as if a device state change makes the window area =unavailable. One example of this is if the device is currently moved to the TYPE_REAR_FACING window area of a foldable device, the device will be moved back to the default window area, and the status of the operation will no longer be androidx.window.area.WindowAreaCapability.Status.WINDOW_AREA_STATUS_ACTIVE.

Parameters
windowAreaToken: WindowAreaToken?

WindowAreaToken window area token that identifies the WindowArea to move to.

activity: Activity

Base Activity to transfer to the transferToWindowArea.

Throws
IllegalStateException

if this method is called when the provided WindowArea does not have a WINDOW_AREA_STATUS_AVAILABLE status for OPERATION_TRANSFER_TO_AREA.

SecurityException

if this method is called from a process that is not the top-level process.

IllegalArgumentException

if this method is called for an unrecognized WindowArea.Type