Added in API level 30

SurfaceControlViewHost


open class SurfaceControlViewHost
kotlin.Any
   ↳ android.view.SurfaceControlViewHost

Utility class for adding a View hierarchy to a SurfaceControl. The View hierarchy will render in to a root SurfaceControl, and receive input based on the SurfaceControl's placement on-screen. The primary usage of this class is to embed a View hierarchy from one process in to another. After the SurfaceControlViewHost has been set up in the embedded content provider, we can send the SurfaceControlViewHost.SurfacePackage to the host process. The host process can then attach the hierarchy to a SurfaceView within its own by calling SurfaceView.setChildSurfacePackage.

Summary

Nested classes

Package encapsulating a Surface hierarchy which contains interactive view elements.

Public constructors
SurfaceControlViewHost(context: Context, display: Display, hostToken: IBinder?)

Construct a new SurfaceControlViewHost.

SurfaceControlViewHost(context: Context, display: Display, hostInputTransferToken: InputTransferToken?)

Construct a new SurfaceControlViewHost.

Public methods
open SurfaceControlViewHost.SurfacePackage?

Return a SurfacePackage for the root SurfaceControl of the embedded hierarchy.

open View?

open Unit
relayout(width: Int, height: Int)

Modify the size of the root view.

open Unit

Trigger the tear down of the embedded view hierarchy and release the SurfaceControl.

open Unit
setView(view: View, width: Int, height: Int)

Set the root view of the SurfaceControlViewHost.

open Boolean

Transfer the currently in progress touch gesture to the parent (if any) of this SurfaceControlViewHost.

Public constructors

SurfaceControlViewHost

Added in API level 30
SurfaceControlViewHost(
    context: Context,
    display: Display,
    hostToken: IBinder?)

Construct a new SurfaceControlViewHost. The root Surface will be allocated internally and is accessible via getSurfacePackage(). The {@param hostToken} parameter, primarily used for ANR reporting, must be obtained from whomever will be hosting the embedded hierarchy. It's accessible from SurfaceView.getHostToken.

Parameters
context Context: The Context object for your activity or application. This value cannot be null.
display Display: The Display the hierarchy will be placed on. This value cannot be null.
hostToken IBinder?: The host token, as discussed above. This value may be null.

SurfaceControlViewHost

Added in API level 35
SurfaceControlViewHost(
    context: Context,
    display: Display,
    hostInputTransferToken: InputTransferToken?)

Construct a new SurfaceControlViewHost. The root Surface will be allocated internally and is accessible via getSurfacePackage().

The hostInputTransferToken parameter allows the host and embedded to be associated with each other to allow transferring touch gesture and focus. This is also used for ANR reporting. It's accessible from AttachedSurfaceControl.getInputTransferToken().

Parameters
context Context: The Context object for your activity or application. This value cannot be null.
display Display: The Display the hierarchy will be placed on. This value cannot be null.
hostInputTransferToken InputTransferToken?: The host input transfer token, as discussed above. This value may be null.

Public methods

getSurfacePackage

Added in API level 30
open fun getSurfacePackage(): SurfaceControlViewHost.SurfacePackage?

Return a SurfacePackage for the root SurfaceControl of the embedded hierarchy. Rather than be directly reparented using SurfaceControl.Transaction this SurfacePackage should be passed to SurfaceView.setChildSurfacePackage which will not only reparent the Surface, but ensure the accessibility hierarchies are linked.

Return
SurfaceControlViewHost.SurfacePackage? This value may be null.

getView

Added in API level 30
open fun getView(): View?
Return
View? The view passed to setView, or null if none has been passed.

relayout

Added in API level 30
open fun relayout(
    width: Int,
    height: Int
): Unit

Modify the size of the root view.

Parameters
width Int: Width in pixels
height Int: Height in pixels

release

Added in API level 30
open fun release(): Unit

Trigger the tear down of the embedded view hierarchy and release the SurfaceControl. This will result in onDispatchedFromWindow being dispatched to the embedded view hierarchy and render the object unusable.

setView

Added in API level 30
open fun setView(
    view: View,
    width: Int,
    height: Int
): Unit

Set the root view of the SurfaceControlViewHost. This view will render in to the SurfaceControl, and receive input based on the SurfaceControls positioning on screen. It will be laid as if it were in a window of the passed in width and height.

Parameters
view View: The View to add This value cannot be null.
width Int: The width to layout the View within, in pixels.
height Int: The height to layout the View within, in pixels.

transferTouchGestureToHost

Added in API level 34
Deprecated in API level 35
open fun transferTouchGestureToHost(): Boolean

Deprecated: Use WindowManager.transferTouchGesture(InputTransferToken, instead.

Transfer the currently in progress touch gesture to the parent (if any) of this SurfaceControlViewHost. This requires that the SurfaceControlViewHost was created with an associated host InputTransferToken.

Return
Boolean Whether the touch stream was transferred.