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 |
|---|
@ExperimentalProjectedApiThe PresentationMode represents how an app is currently able to present content to the user on a projected device. |
@ExperimentalProjectedApiThe PresentationModeFlags represents a collection of PresentationMode values that are currently active. |
Public methods |
|
|---|---|
final void |
@ExperimentalProjectedApiConvenience function to set the flag bits as as per the |
final void |
@ExperimentalProjectedApiAdds a callback to listen for updates to the PresentationModeFlags. |
void |
close()Disconnects from the service providing features for Projected devices. |
static final @NonNull ProjectedDisplayController |
@RequiresApi(value = 34)Connects to the service providing features for Projected devices and returns the |
final void |
@ExperimentalProjectedApiConvenience function to remove the flag bits as as per the |
final void |
@ExperimentalProjectedApiRemove a listener to stop consuming |
Public methods
addLayoutParamsFlags
@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:
-
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
@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
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.
| Throws | |
|---|---|
IllegalStateException |
if the projected service is not found or binding is not permitted |
IllegalArgumentException |
if provided Activity is not running on a Projected device. |
removeLayoutParamsFlags
@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
@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.