ProjectedDisplayController


public final class ProjectedDisplayController implements 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 methods

final void

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

final void

Adds a callback to listen for updates to the PresentationModeFlags.

void

Disconnects from the service providing features for Projected devices.

static final @NonNull ProjectedDisplayController

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

final void

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

final void

Remove a listener to stop consuming PresentationModeFlags values.

Public methods

addLayoutParamsFlags

Added in 1.0.0-alpha03
@ExperimentalProjectedApi
public final void addLayoutParamsFlags(int flags)

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)
public final void addPresentationModeChangedListener(
    @NonNull Executor executor,
    @NonNull Consumer<@NonNull ProjectedDisplayController.PresentationModeFlags> listener
)

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
public void close()

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.

create

@RequiresApi(value = 34)
@ExperimentalProjectedApi
public static final @NonNull ProjectedDisplayController create(@NonNull Activity activity)

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

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

removeLayoutParamsFlags

Added in 1.0.0-alpha03
@ExperimentalProjectedApi
public final void removeLayoutParamsFlags(int flags)

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
public final void removePresentationModeChangedListener(
    @NonNull Consumer<@NonNull ProjectedDisplayController.PresentationModeFlags> listener
)

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