ProjectedDisplayController


class ProjectedDisplayController : AutoCloseable


Controller for the Projected device display.

Use create to create an instance of this class. Use close to clear the instance.

Summary

Nested types

The PresentationMode represents how an app is currently able to present content to the user on a projected device.

The PresentationModeFlags represents a collection of PresentationMode values that are currently active.

Public companion functions

suspend ProjectedDisplayController

Connects to the service providing features for Projected devices and returns the ProjectedDisplayController when the connection is established.

Public functions

Unit

Convenience function to set the flag bits as as per the android.view.WindowManager.LayoutParams flags.

Unit

Adds a callback to listen for updates to the PresentationModeFlags.

open Unit

Disconnects from the service providing features for Projected devices.

Unit

Convenience function to remove the flag bits as as per the android.view.WindowManager.LayoutParams flags.

Unit

Remove a listener to stop consuming PresentationModeFlags values.

Public companion functions

create

@RequiresApi(value = 34)
@ExperimentalProjectedApi
suspend fun create(activity: Activity): ProjectedDisplayController

Connects to the service providing features for Projected devices and returns the ProjectedDisplayController when the connection is established.

Parameters
activity: Activity

The Activity running on a Projected device.

Throws
kotlin.IllegalStateException

if the projected service is not found or binding is not permitted

kotlin.IllegalArgumentException

if provided Activity is not running on a Projected device.

Public functions

addLayoutParamsFlags

Added in 1.0.0-alpha03
@ExperimentalProjectedApi
fun addLayoutParamsFlags(flags: Int): Unit

Convenience function to set the flag bits as as per the android.view.WindowManager.LayoutParams flags. Flags will be cleared automatically after the app stops.

Supported flags:

  • android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON

    • Note: Keeping the device's screen on can drain the battery quickly. Ordinarily, you should let the device turn the screen off if the user is not interacting with it. If you do need to keep the screen on, do so for as short a time as possible.

If an unsupported flag is passed, this method does nothing.

addPresentationModeChangedListener

Added in 1.0.0-alpha03
@ExperimentalProjectedApi
@RequiresApi(value = 24)
fun addPresentationModeChangedListener(
    executor: Executor = Dispatchers.Main.asExecutor(),
    listener: Consumer<ProjectedDisplayController.PresentationModeFlags>
): Unit

Adds a callback to listen for updates to the PresentationModeFlags.

The PresentationMode represents how a content is being presented to a projected application (e.g. are visuals on). The callback will be called with the current state as soon as it is available. A listener cannot be added a second time without first being removed.

close

Added in 1.0.0-alpha03
open fun close(): Unit

Disconnects from the service providing features for Projected devices. Methods from the ProjectedDisplayController shouldn't be called after this.

This method should be called in android.app.Activity.onDestroy.

removeLayoutParamsFlags

Added in 1.0.0-alpha03
@ExperimentalProjectedApi
fun removeLayoutParamsFlags(flags: Int): Unit

Convenience function to remove the flag bits as as per the android.view.WindowManager.LayoutParams flags.

Supported flags:

If an unsupported flag is passed, this method does nothing.

removePresentationModeChangedListener

Added in 1.0.0-alpha03
@ExperimentalProjectedApi
fun removePresentationModeChangedListener(
    listener: Consumer<ProjectedDisplayController.PresentationModeFlags>
): Unit

Remove a listener to stop consuming PresentationModeFlags values. If the listener has already been removed then this is a no-op.