OverlayControllerCallbackAdapter


public final class OverlayControllerCallbackAdapter


An adapted interface for OverlayController that provides callback shaped APIs to report the latest OverlayInfo.

It should only be used if OverlayController.overlayInfo is not available. For example, an app is written in Java and cannot use Flow APIs.

Summary

Public constructors

creates a callback adapter of OverlayController.overlayInfo flow API.

Public methods

final void
@RequiresWindowSdkExtension(version = 5)
addOverlayInfoListener(
    @NonNull String overlayTag,
    @NonNull Executor executor,
    @NonNull Consumer<@NonNull OverlayInfo> consumer
)

Registers a listener for updates of OverlayInfo that overlayTag is associated with.

final void

Unregisters a listener that was previously registered via addOverlayInfoListener.

Public constructors

OverlayControllerCallbackAdapter

Added in 1.4.0-alpha05
public OverlayControllerCallbackAdapter(@NonNull OverlayController controller)

creates a callback adapter of OverlayController.overlayInfo flow API.

Parameters
@NonNull OverlayController controller

an OverlayController that can be obtained by OverlayController.getInstance.

Public methods

addOverlayInfoListener

Added in 1.4.0-alpha05
@RequiresWindowSdkExtension(version = 5)
public final void addOverlayInfoListener(
    @NonNull String overlayTag,
    @NonNull Executor executor,
    @NonNull Consumer<@NonNull OverlayInfo> consumer
)

Registers a listener for updates of OverlayInfo that overlayTag is associated with.

If there is no active overlay ActivityStack, the reported OverlayInfo.activityStack and OverlayInfo.currentOverlayAttributes will be null.

Note that launching an overlay ActivityStack only supports on the device with WindowSdkExtensions.extensionVersion equal to or larger than 5. If WindowSdkExtensions.extensionVersion is less than 5, this flow will always report OverlayInfo without associated OverlayInfo.activityStack.

Parameters
@NonNull String overlayTag

the overlay ActivityStack's tag which is set through OverlayCreateParams

@NonNull Executor executor

the Executor to dispatch the OverlayInfo change

@NonNull Consumer<@NonNull OverlayInfo> consumer

the Consumer that will be invoked on the executor when there is an update to OverlayInfo.

removeOverlayInfoListener

Added in 1.4.0-alpha05
@RequiresWindowSdkExtension(version = 5)
public final void removeOverlayInfoListener(
    @NonNull Consumer<@NonNull OverlayInfo> consumer
)

Unregisters a listener that was previously registered via addOverlayInfoListener.

Parameters
@NonNull Consumer<@NonNull OverlayInfo> consumer

the previously registered Consumer to unregister.