class Session


The Session provides the primary interface to SceneCore functionality for the application. Each spatialized Activity must create and hold an instance of Session.

Once created, the application can use the Session interfaces to create spatialized entities, such as Widget panels and geometric models, set the background environment, and anchor content to the real world.

Summary

Public companion functions

Session
create(activity: Activity, platformAdapter: JxrPlatformAdapter?)

Creates a session and pairs it with an Activity and its lifecycle.

Public constructors

Session(
    activity: Activity,
    platformAdapter: JxrPlatformAdapter,
    spatialEnvironment: SpatialEnvironment
)

Public properties

Activity
ActivitySpace

The ActivitySpace is a special entity that represents the space in which the application is launched.

Entity
PanelEntity

A spatialized PanelEntity associated with the "main window" for the Activity.

PerceptionSpace

The PerceptionSpace represents the origin of the space in which the ARCore for XR API provides tracking info.

JxrPlatformAdapter
SpatialEnvironment
SpatialUser

The SpatialUser contains information about the user.

Extension functions

Unit

Adds the given Consumer as a listener to be invoked when this Session's current SpatialCapabilities change.

Unit

Adds the given Consumer as a listener to be invoked when this Session's current SpatialCapabilities change.

List<T>

Returns all Entitys of the given type or its subtypes.

SpatialCapabilities

Returns the current SpatialCapabilities of the Session.

Unit

Releases the given Consumer from receiving updates when the Session's SpatialCapabilities change.

Bundle

Sets the full space mode flag to the given android.os.Bundle.

Bundle

Sets the inherit full space mode environvment flag to the given android.os.Bundle.

Unit
Session.setPreferredAspectRatio(
    activity: Activity,
    preferredRatio: Float
)

Sets a preferred main panel aspect ratio for home space mode.

Public companion functions

create

Added in 1.0.0-alpha02
fun create(activity: Activity, platformAdapter: JxrPlatformAdapter? = null): Session

Creates a session and pairs it with an Activity and its lifecycle. If a session is already paired with an Activity, return that Session instead of creating a new one.

For our Alpha release, we just directly instantiate the Android XR PlatformAdapter.

Public constructors

Session

Added in 1.0.0-alpha02
Session(
    activity: Activity,
    platformAdapter: JxrPlatformAdapter,
    spatialEnvironment: SpatialEnvironment
)

Public properties

activity

Added in 1.0.0-alpha02
val activityActivity

activitySpace

Added in 1.0.0-alpha02
val activitySpaceActivitySpace

The ActivitySpace is a special entity that represents the space in which the application is launched. It is the default parent of all entities in the scene.

The ActivitySpace is created automatically when the Session is created.

activitySpaceRoot

Added in 1.0.0-alpha02
val activitySpaceRootEntity

mainPanelEntity

Added in 1.0.0-alpha02
val mainPanelEntityPanelEntity

A spatialized PanelEntity associated with the "main window" for the Activity. When in HomeSpace mode, this is the application's "main window".

If called multiple times, this will return the same PanelEntity.

perceptionSpace

Added in 1.0.0-alpha02
val perceptionSpacePerceptionSpace

The PerceptionSpace represents the origin of the space in which the ARCore for XR API provides tracking info. The transformations provided by the PerceptionSpace are only valid for the call frame, as the transformation can be changed by the system at any time.

platformAdapter

Added in 1.0.0-alpha02
val platformAdapterJxrPlatformAdapter

spatialEnvironment

Added in 1.0.0-alpha02
val spatialEnvironmentSpatialEnvironment

spatialUser

Added in 1.0.0-alpha02
val spatialUserSpatialUser

The SpatialUser contains information about the user.

Extension functions

addSpatialCapabilitiesChangedListener

fun Session.addSpatialCapabilitiesChangedListener(
    listener: Consumer<SpatialCapabilities>
): Unit

Adds the given Consumer as a listener to be invoked when this Session's current SpatialCapabilities change. Consumer#accept(SpatialCapabilities) will be invoked on the main thread.

addSpatialCapabilitiesChangedListener

fun Session.addSpatialCapabilitiesChangedListener(
    callbackExecutor: Executor,
    listener: Consumer<SpatialCapabilities>
): Unit

Adds the given Consumer as a listener to be invoked when this Session's current SpatialCapabilities change. Consumer#accept(SpatialCapabilities) will be invoked on the given callbackExecutor, or the main thread if the callbackExecutor is null (default).

getEntitiesOfType

fun <T : Entity> Session.getEntitiesOfType(type: Class<T>): List<T>

Returns all Entitys of the given type or its subtypes.

Parameters
type: Class<T>

the type of Entity to return.

Returns
List<T>

a list of all Entitys of the given type.

getSpatialCapabilities

fun Session.getSpatialCapabilities(): SpatialCapabilities

Returns the current SpatialCapabilities of the Session. The set of capabilities can change within a session. The returned object will not update if the capabilities change; this method should be called again to get the latest set of capabilities.

removeSpatialCapabilitiesChangedListener

fun Session.removeSpatialCapabilitiesChangedListener(
    listener: Consumer<SpatialCapabilities>
): Unit

Releases the given Consumer from receiving updates when the Session's SpatialCapabilities change.

setFullSpaceMode

fun Session.setFullSpaceMode(bundle: Bundle): Bundle

Sets the full space mode flag to the given android.os.Bundle.

The android.os.Bundle then could be used to launch an android.app.Activity with requesting to enter full space mode through android.app.Activity.startActivity. If there's a bundle used for customizing how the android.app.Activity should be started by android.app.ActivityOptions.toBundle or androidx.core.app.ActivityOptionsCompat.toBundle, it's suggested to use the bundle to call this method.

The flag will be ignored when no android.content.Intent.FLAG_ACTIVITY_NEW_TASK is set in the bundle, or it is not started from a focused Activity context.

This flag is also ignored when the android.window.PROPERTY_XR_ACTIVITY_START_MODE property is set to a value other than XR_ACTIVITY_START_MODE_UNDEFINED in the AndroidManifest.xml file for the activity being launched.

Parameters
bundle: Bundle

the input bundle to set with the full space mode flag.

Returns
Bundle

the input bundle with the full space mode flag set.

setFullSpaceModeWithEnvironmentInherited

fun Session.setFullSpaceModeWithEnvironmentInherited(bundle: Bundle): Bundle

Sets the inherit full space mode environvment flag to the given android.os.Bundle.

The android.os.Bundle then could be used to launch an android.app.Activity with requesting to enter full space mode while inherit the existing environment through android.app.Activity.startActivity. If there's a bundle used for customizing how the android.app.Activity should be started by android.app.ActivityOptions.toBundle or androidx.core.app.ActivityOptionsCompat.toBundle, it's suggested to use the bundle to call this method.

When launched, the activity will be in full space mode and also inherits the environment from the launching activity. If the inherited environment needs to be animated, the launching activity has to continue updating the environment even after the activity is put into the stopped state.

The flag will be ignored when no android.content.Intent.FLAG_ACTIVITY_NEW_TASK is set in the intent, or it is not started from a focused Activity context.

The flag will also be ignored when there is no environment to inherit or the activity has its own environment set already.

This flag is ignored too when the android.window.PROPERTY_XR_ACTIVITY_START_MODE property is set to a value other than XR_ACTIVITY_START_MODE_UNDEFINED in the AndroidManifest.xml file for the activity being launched.

For security reasons, Z testing for the new activity is disabled, and the activity is always drawn on top of the inherited environment. Because Z testing is disabled, the activity should not spatialize itself.

Parameters
bundle: Bundle

the input bundle to set with the inherit full space mode environment flag.

Returns
Bundle

the input bundle with the inherit full space mode flag set.

setPreferredAspectRatio

fun Session.setPreferredAspectRatio(
    activity: Activity,
    preferredRatio: Float
): Unit

Sets a preferred main panel aspect ratio for home space mode.

The ratio is only applied to the activity. If the activity launches another activity in the same task, the ratio is not applied to the new activity. Also, while the activity is in full space mode, the preference is temporarily removed.

If the activity's current aspect ratio differs from the preferredRatio, the panel is automatically resized. This resizing preserves the panel's area. To avoid runtime resizing, consider specifying the desired aspect ratio in your AndroidManifest.xml. This ensures your activity launches with the preferred aspect ratio from the start.

Parameters
activity: Activity

the activity to set the preference.

preferredRatio: Float

the aspect ratio determined by taking the panel's width over its height. A value <= 0.0f means there are no preferences.