WindowAreaControllerCallbackAdapter


public final class WindowAreaControllerCallbackAdapter


An adapter for WindowAreaController to provide callback APIs.

Summary

Public constructors

Public methods

final void

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

final WindowAreaSessionPresenter

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

final void
@ExperimentalWindowApi
presentContentOnWindowArea(
    @NonNull WindowAreaToken windowAreaToken,
    @NonNull Activity activity,
    @NonNull Executor executor,
    @NonNull WindowAreaPresentationSessionCallback windowAreaPresentationSessionCallback
)

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

final void

Removes a listener of available WindowArea records.

final void
transferToWindowArea(
    WindowAreaToken windowAreaToken,
    @NonNull 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
public WindowAreaControllerCallbackAdapter(
    @NonNull WindowAreaController controller
)

Public methods

addWindowAreasListener

Added in 1.6.0-alpha03
public final void addWindowAreasListener(
    @NonNull Executor executor,
    @NonNull Consumer<@NonNull List<@NonNull WindowArea>> listener
)

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
@NonNull Executor executor

to handle sending listener updates.

@NonNull Consumer<@NonNull List<@NonNull WindowArea>> listener

to receive updates to the list of WindowArea.

getActivePresentationSession

Added in 1.6.0-alpha03
@ExperimentalWindowApi
public final WindowAreaSessionPresenter getActivePresentationSession(@NonNull WindowAreaToken windowAreaToken)

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
public final void presentContentOnWindowArea(
    @NonNull WindowAreaToken windowAreaToken,
    @NonNull Activity activity,
    @NonNull Executor executor,
    @NonNull WindowAreaPresentationSessionCallback windowAreaPresentationSessionCallback
)

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
@NonNull WindowAreaToken windowAreaToken

identifier for which WindowArea is to be presented on

@NonNull Activity activity

An Activity that will present content on the Rear Display.

@NonNull Executor executor

Executor used to provide updates to windowAreaPresentationSessionCallback.

@NonNull WindowAreaPresentationSessionCallback windowAreaPresentationSessionCallback

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

removeWindowAreasListener

Added in 1.6.0-alpha03
public final void removeWindowAreasListener(
    @NonNull Consumer<@NonNull List<@NonNull WindowArea>> listener
)

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

Parameters
@NonNull Consumer<@NonNull List<@NonNull WindowArea>> listener

to remove from receiving status updates.

transferToWindowArea

Added in 1.6.0-alpha03
public final void transferToWindowArea(
    WindowAreaToken windowAreaToken,
    @NonNull Activity activity
)

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.

@NonNull 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