Most visited

Recently visited

AndroidViewTexture

public class AndroidViewTexture
extends Texture

java.lang.Object
   ↳ com.viro.core.Texture
     ↳ com.viro.core.AndroidViewTexture


AndroidViewTexture renders an Android View onto a Viro Texture. This texture can be applied onto any Viro Geometry to be rendered in the Scene. The width and height of AndroidViewTexture define the bounds of the Android view: content outside these bounds will be clipped.

By default, AndroidViewTexture will render Android Views without any hardware acceleration. This ensures maximum compatibility with most Android OS versions while guaranteeing correct view interaction behavior. However, there is a memory size limitation with this approach, resulting in smaller viable width and height sizes for the texture. To check if your desired view size works with software acceleration, use supportsSoftwareSurfaceOfSize(Context, int, int).

If specified, developers can also force the AndroidViewTexture to use hardware acceleration, enabling larger texture sizes. Although most basic Android controls function properly with this mode, it is important to note that some views may have unpredictable behavior, particularly when handling user interaction.

Summary

Public constructors

AndroidViewTexture(ViroView view, int pxWidth, int pxHeight)

Construct a new AndroidViewTexture that will render Android views into the scene with the given pixel width and pixel height.

AndroidViewTexture(ViroView view, int pxWidth, int pxHeight, boolean useHardwareAcceleration)

Construct a new AndroidViewTexture that will render Android views into the scene with the given pixel width and height.

Public methods

void attachView(View view)

Attach the Android View to be rendered with this AndroidViewTexture.

void detachView()

Detaches the Android View that was last attached via attachView(View).

void dispatchClickStateEvent(ClickState state, float pixelX, float pixelY)

Triggers a Viro ClickState event at the given pixel coordinates in the currently attached Android View.

ClickListener getClickListenerWithQuad(Quad quad)

Constructs and returns a ClickListener that maps Viro clicks performed on the given Quad to Android touch events, which will be automatically applied to the underlying attached Android View.

static boolean supportsSoftwareSurfaceOfSize(Context context, int width, int height)

Determines if the current device supports rendering an Android layout in Software Acceleration mode with the given width and height.

Public constructors

AndroidViewTexture

AndroidViewTexture (ViroView view, 
                int pxWidth, 
                int pxHeight)

Construct a new AndroidViewTexture that will render Android views into the scene with the given pixel width and pixel height. By default, the AndroidViewTexture will render Android Views onto its texture without any hardware acceleration.

Once constructed, you can attach the Android View you wish to render by invoking attachView(View).

Parameters
view ViroView: The ViroView containing your 3D scene.

pxWidth int: The width of the texture in pixels.

pxHeight int: The height of the texture in pixels.

AndroidViewTexture

AndroidViewTexture (ViroView view, 
                int pxWidth, 
                int pxHeight, 
                boolean useHardwareAcceleration)

Construct a new AndroidViewTexture that will render Android views into the scene with the given pixel width and height.

Once constructed, you can attach the Android View you wish to render by invoking attachView(View).

Parameters
view ViroView: The ViroView containing your 3D scene.

pxWidth int: The width of the texture in pixels.

pxHeight int: The height of the texture in pixels.

useHardwareAcceleration boolean: True if this view should use hardware acceleration.

Public methods

attachView

void attachView (View view)

Attach the Android View to be rendered with this AndroidViewTexture. This will detach any currently attached View.

Parameters
view View: The Android View to be rendered with this AndroidViewTexture.

detachView

void detachView ()

Detaches the Android View that was last attached via attachView(View).

dispatchClickStateEvent

void dispatchClickStateEvent (ClickState state, 
                float pixelX, 
                float pixelY)

Triggers a Viro ClickState event at the given pixel coordinates in the currently attached Android View. This should only be used for cases where you would like to map ClickState interactivity for non-quad geometric 3D models with an applied AndroidViewTexture.

For quad objects, use getClickListenerWithQuad(Quad) instead.

Parameters
state ClickState: ClickState to be applied onto the view.

pixelX float: The X coordinate in pixels at which to apply the click event.

pixelY float: The Y coordinate in pixels at which to apply the click event.

getClickListenerWithQuad

ClickListener getClickListenerWithQuad (Quad quad)

Constructs and returns a ClickListener that maps Viro clicks performed on the given Quad to Android touch events, which will be automatically applied to the underlying attached Android View. This takes into account the transformations that are applied to the Quad, and as well as the size of the underlying texture.

To use the ClickListener returned by this method, you need to then attach it to the Quad's parent Node, via setClickListener(ClickListener).

Parameters
quad Quad: The Quad from which click positions will originate.

Returns
ClickListener The ClickListener connecting clicks between the underlying Android View and the given Quad.

supportsSoftwareSurfaceOfSize

boolean supportsSoftwareSurfaceOfSize (Context context, 
                int width, 
                int height)

Determines if the current device supports rendering an Android layout in Software Acceleration mode with the given width and height.

Parameters
context Context: The Android Context.

width int: The desired width of your Android layout.

height int: The desired height of your Android layout.

Returns
boolean True if the provided dimensions are supported on the current device.

Hooray!