SpatialAnnotation


@ExperimentalSpatialAnnotationsApi
public final class SpatialAnnotation implements Trackable


Base class for all tracked Spatial Annotations (Quads, Points, Masks, etc.).

Summary

Nested types

public final class SpatialAnnotation.State implements Trackable.State

State containing physical properties that update frame-to-frame.

Public methods

final @NonNull SpatialAnnotationId

the caller-defined unique SpatialAnnotationId associated with this annotation

final SpatialAnnotationQuadAlignment

the runtime alignment configuration bound to this SpatialAnnotation, it will only have a value when the spatial tracking mode is set to quad

@NonNull StateFlow<@NonNull SpatialAnnotation.State>

The current reactive state of the SpatialAnnotation

static final void

Starts tracking one or more Spatial Annotations in 3D physical space.

static final void

Stops tracking the provided Spatial Annotations.

static final void

Stops tracking all actively tracked Spatial Annotations in the active session.

static final @NonNull StateFlow<@NonNull List<@NonNull SpatialAnnotation>>

Emits the Spatial Annotations that are currently being tracked in the session.

@NonNull String

Public methods

getId

Added in 1.1.0-alpha01
public final @NonNull SpatialAnnotationId getId()

the caller-defined unique SpatialAnnotationId associated with this annotation

getQuadAlignment

Added in 1.1.0-alpha01
public final SpatialAnnotationQuadAlignment getQuadAlignment()

the runtime alignment configuration bound to this SpatialAnnotation, it will only have a value when the spatial tracking mode is set to quad

getState

public @NonNull StateFlow<@NonNull SpatialAnnotation.State> getState()

The current reactive state of the SpatialAnnotation

startTracking

Added in 1.1.0-alpha01
public static final void startTracking(
    @NonNull Session session,
    @NonNull SpatialAnnotationTrackingOptions options
)

Starts tracking one or more Spatial Annotations in 3D physical space.

The app will not receive tracking updates for these annotations until this method completes. It is recommended to call this method before calling subscribe.

Parameters
@NonNull Session session

the active JXR session

@NonNull SpatialAnnotationTrackingOptions options

configuration generated via SpatialAnnotationTrackingOptions.Builder

Throws
IllegalStateException

if tracking cannot be started or is cancelled by the runtime

IllegalArgumentException

if the provided options are invalid

stopTracking

Added in 1.1.0-alpha01
public static final void stopTracking(
    @NonNull Session session,
    @NonNull List<@NonNull SpatialAnnotationId> ids
)

Stops tracking the provided Spatial Annotations.

Parameters
@NonNull Session session

the Session executing the XR tracking

@NonNull List<@NonNull SpatialAnnotationId> ids

the specific list of SpatialAnnotationIds to cease tracking

Throws
IllegalArgumentException

if the provided list of ids is empty, use stopTrackingAllAnnotations to halt all active tracking

stopTrackingAllAnnotations

Added in 1.1.0-alpha01
public static final void stopTrackingAllAnnotations(@NonNull Session session)

Stops tracking all actively tracked Spatial Annotations in the active session.

Parameters
@NonNull Session session

the Session executing the XR tracking

subscribe

Added in 1.1.0-alpha01
public static final @NonNull StateFlow<@NonNull List<@NonNull SpatialAnnotation>> subscribe(@NonNull Session session)

Emits the Spatial Annotations that are currently being tracked in the session.

Only instances of SpatialAnnotation that are androidx.xr.arcore.TrackingState.TRACKING will be emitted in the Collection. Instances of the same SpatialAnnotation will remain between subsequent emits to the StateFlow as long as they remain tracking.

Parameters
@NonNull Session session

the Session to subscribe to

Returns
@NonNull StateFlow<@NonNull List<@NonNull SpatialAnnotation>>

a StateFlow that emits a collection of tracked annotations

toString

public @NonNull String toString()