WindowAreaController


public abstract class WindowAreaController


An interface to provide the information and behavior around moving windows between displays or display areas on a device.

Summary

Public methods

abstract void

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

abstract WindowAreaSessionPresenter

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

static final @NonNull WindowAreaController

Provides an instance of WindowAreaController.

abstract 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.

abstract void

Removes a listener of available WindowArea records.

abstract void
transferToWindowArea(
    WindowAreaToken windowAreaToken,
    @NonNull Activity activity
)

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

Public methods

addWindowAreasListener

Added in 1.6.0-alpha03
public abstract 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 abstract 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.

getOrCreate

Added in 1.2.0
public static final @NonNull WindowAreaController getOrCreate()

Provides an instance of WindowAreaController.

presentContentOnWindowArea

Added in 1.6.0-alpha03
@ExperimentalWindowApi
public abstract 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 to be presented on. 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 abstract 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 abstract 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 from the value received by registering a listener through addWindowAreasListener and then querying for the WindowAreaCapability.Operation.OPERATION_TRANSFER_TO_AREA operation.

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

Only the top visible application can request the device ot 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 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 making the call to 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 with a WindowArea with a WindowArea.Type that is unrecognized.