WindowAreaController
abstract class WindowAreaController
An interface to provide the information and behavior around moving windows between displays or display areas on a device.
Summary
Public companion functions |
|
|---|---|
WindowAreaController |
Provides an instance of |
Public functions |
|
|---|---|
abstract Unit |
addWindowAreasListener(Registers a listener that is interested in the current list of |
abstract WindowAreaSessionPresenter? |
@ExperimentalWindowApiReturns the current active |
abstract Unit |
@ExperimentalWindowApiStarts a presentation session on the |
abstract Unit |
removeWindowAreasListener(listener: Consumer<List<WindowArea>>)Removes a listener of available |
abstract Unit |
transferToWindowArea(Moves the calling |
Public companion functions
getOrCreate
fun getOrCreate(): WindowAreaController
Provides an instance of WindowAreaController.
Public functions
addWindowAreasListener
abstract 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 |
getActivePresentationSession
@ExperimentalWindowApi
abstract 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
@ExperimentalWindowApi
abstract 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 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 | |
|---|---|
windowAreaToken: WindowAreaToken |
identifier for which |
activity: Activity |
An |
executor: Executor |
Executor used to provide updates to |
windowAreaPresentationSessionCallback: WindowAreaPresentationSessionCallback |
to be notified of updates to the lifecycle of the currently enabled rear display presentation. |
| See also | |
|---|---|
addWindowAreasListener |
removeWindowAreasListener
abstract 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
abstract 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 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? |
|
activity: Activity |
Base Activity making the call to |
| Throws | |
|---|---|
IllegalStateException |
if this method is called when the provided |
SecurityException |
if this method is called from a process that is not the top-level process. |
IllegalArgumentException |
if this method is called with a |
| See also | |
|---|---|
addWindowAreasListener |