SharedUiContainer
@ExperimentalFeatures.SharedUiPresentationApi
public final class SharedUiContainer extends ViewGroup
| java.lang.Object | |||
| ↳ | android.view.View | ||
| ↳ | android.view.ViewGroup | ||
| ↳ | androidx.privacysandbox.ui.client.view.SharedUiContainer |
SharedUiContainer is a ViewGroup that's designed to host 'shared UI', meaning it can handle both client-owned and provider-owned UI (via SandboxedSdkViews). The container also allows to register its child views as assets. Assets can be registered either before or after the session is open.
Children: The container should be used to host a single direct child view. However, it allows adding more than one child view to it. All child views added to SharedUiContainer are placed in the top left corner of the container plus padding.
Session management: The container will maintain a session to communicate with a sandboxed SDK for lifecycle management. To open a session, a SharedUiAdapter must be set using setAdapter, and the container must be attached to a visible window and have non-zero dimensions.
When setAdapter is called, any existing session will be closed and all registered assets will be released.
Provider-owned UI: All registered child SandboxedSdkViews will maintain their own sessions for provider-owned UI presentation. For all SandboxedSdkViews registered with SandboxedUiAdapters, SharedUiContainer will set corresponding adapters when a shared UI session opens. For any SandboxedSdkViews registered when the session is open, adapters will be set immediately. The container will close any open SandboxedSdkView sessions before closing its own session.
Asset registration: Client-owned views and SandboxedSdkViews can be registered as assets using registerSharedUiAsset and unregistered using unregisterSharedUiAsset.
Summary
Public constructors |
|---|
SharedUiContainer(@NonNull Context context, AttributeSet attrs) |
Public methods |
|
|---|---|
final boolean |
registerSharedUiAsset(@NonNull SharedUiAsset sharedUiAsset)Registers a |
final void |
setAdapter(SharedUiAdapter sharedUiAdapter)Sets |
final boolean |
unregisterSharedUiAsset(@NonNull View view)Unregisters a |
Protected methods |
|
|---|---|
void |
|
void |
|
void |
onLayout(boolean changed, int left, int top, int right, int bottom)Lays out the container's children in the top left corner with their measured sizes. |
void |
onMeasure(int widthMeasureSpec, int heightMeasureSpec)Measures the container and its children. |
void |
onWindowVisibilityChanged(int visibility) |
Inherited methods |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Public constructors
SharedUiContainer
public SharedUiContainer(@NonNull Context context, AttributeSet attrs)
Public methods
registerSharedUiAsset
public final boolean registerSharedUiAsset(@NonNull SharedUiAsset sharedUiAsset)
Registers a SharedUiAsset, that represents a native ad asset, on SharedUiContainer. The UI provider will receive information about the asset throughout the lifetime of the shared UI session. Because of this, no user-sensitive information should be stored in sharedUiAsset.
sharedUiAsset must comprise a View and its asset ID. This view must be a child, direct or indirect, of the container. If the view gets detached from window, it will be unregistered from the container.
One View can only be associated with one asset. If there's already another SharedUiAsset registered for the View, sharedUiAsset won't be registered, and the method will return 'false'.
Asset IDs will be used by the UI provider to identify an asset view and should be obtained beforehand from the provider. Within the container, an asset ID doesn't have to be unique - the container doesn't impose any restrictions in this regard, and the exact asset ID structure should be a part of the contract between the UI client and provider.
SharedUiAsset allows to provide a SandboxedUiAdapter for registered SandboxedSdkViews. In this case, the container will handle session management of the view: SandboxedUiAdapter will be set on the view once the container's session is open or, if it's already open, will be set right away. However, the session will be closed by the container before the shared UI session in any case.
| Returns | |
|---|---|
boolean |
'true' if |
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if a |
setAdapter
public final void setAdapter(SharedUiAdapter sharedUiAdapter)
Sets SharedUiAdapter to maintain a session between SharedUiContainer and a sandboxed SDK.
If there's already an adapter set, and it's different from sharedUiAdapter, its shared UI session is closed, assets registered using registerSharedUiAsset are unregistered, and UI sessions for all registered SandboxedSdkView assets are closed.
If sharedUiAdapter is the same as the previously set adapter, nothing happens.
Passing 'null' value for sharedUiAdapter will release all resources and unregister all children, without setting a new adapter.
unregisterSharedUiAsset
public final boolean unregisterSharedUiAsset(@NonNull View view)
Unregisters a SharedUiAsset associated with a given view from the container. If the view is a SandboxedSdkView, its provider-owned UI session is closed.
| Returns | |
|---|---|
boolean |
'true' if the asset was unregistered successfully, 'false' otherwise (if there wasn't a |
Protected methods
onLayout
protected void onLayout(boolean changed, int left, int top, int right, int bottom)
Lays out the container's children in the top left corner with their measured sizes. Takes into account the container's padding settings.
Child views that are View.GONE are ignored and don't take any space.
onMeasure
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
Measures the container and its children. The size of the container is determined by the size of its largest child, container's padding and suggested dimensions, but only if they do not exceed size restrictions imposed by the container's parent view. Child views are measured with respect to the container's padding settings.
View.GONE child views are not used for sizing and are not measured.