Skip to content

Commit b5813ad

Browse files
committed
Add snippet for dec jxr release.
1 parent a710fc2 commit b5813ad

File tree

7 files changed

+28
-32
lines changed

7 files changed

+28
-32
lines changed

gradle/libs.versions.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ androidx-xr-compose = "1.0.0-alpha09"
3434
androidx-xr-scenecore = "1.0.0-alpha10"
3535
androidxHiltNavigationCompose = "1.3.0"
3636
appcompat = "1.7.1"
37-
arcorePlayServices = "1.0.0-alpha08"
37+
arcorePlayServices = "1.0.0-alpha09"
3838
coil = "2.7.0"
3939
# @keep
4040
compileSdk = "36"

xr/src/main/java/com/example/xr/scenecore/GltfEntity.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import androidx.activity.ComponentActivity
2323
import androidx.xr.runtime.Session
2424
import androidx.xr.scenecore.GltfModel
2525
import androidx.xr.scenecore.GltfModelEntity
26-
import androidx.xr.scenecore.SpatialCapabilities
26+
import androidx.xr.scenecore.SpatialCapability
2727
import androidx.xr.scenecore.scene
2828
import java.nio.file.Paths
2929

@@ -35,9 +35,7 @@ private suspend fun loadGltfFile(session: Session) {
3535

3636
private fun createModelEntity(session: Session, gltfModel: GltfModel) {
3737
// [START androidxr_scenecore_gltfmodelentity_create]
38-
if (session.scene.spatialCapabilities
39-
.hasCapability(SpatialCapabilities.SPATIAL_CAPABILITY_3D_CONTENT)
40-
) {
38+
if (session.scene.spatialCapabilities.contains(SpatialCapability.SPATIAL_3D_CONTENT)) {
4139
val gltfEntity = GltfModelEntity.create(session, gltfModel)
4240
}
4341
// [END androidxr_scenecore_gltfmodelentity_create]

xr/src/main/java/com/example/xr/scenecore/InteractableComponent.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ private fun interactableComponentExample(session: Session, entity: Entity) {
2727
val executor = Executors.newSingleThreadExecutor()
2828
val interactableComponent = InteractableComponent.create(session, executor) {
2929
// when the user disengages with the entity with their hands
30-
if (it.source == InputEvent.Source.SOURCE_HANDS && it.action == InputEvent.Action.ACTION_UP) {
30+
if (it.source == InputEvent.Source.HANDS && it.action == InputEvent.Action.UP) {
3131
// increase size with right hand and decrease with left
32-
if (it.pointerType == InputEvent.Pointer.POINTER_TYPE_RIGHT) {
32+
if (it.pointerType == InputEvent.Pointer.RIGHT) {
3333
entity.setScale(1.5f)
34-
} else if (it.pointerType == InputEvent.Pointer.POINTER_TYPE_LEFT) {
34+
} else if (it.pointerType == InputEvent.Pointer.LEFT) {
3535
entity.setScale(0.5f)
3636
}
3737
}

xr/src/main/java/com/example/xr/scenecore/ResizableComponent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private fun resizableComponentExample(
3131
) {
3232
// [START androidxr_scenecore_resizableComponentExample]
3333
val resizableComponent = ResizableComponent.create(session) { event ->
34-
if (event.resizeState == ResizeEvent.ResizeState.RESIZE_STATE_END) {
34+
if (event.resizeState == ResizeEvent.ResizeState.END) {
3535
// update the Entity to reflect the new size
3636
surfaceEntity.shape = SurfaceEntity.Shape.Quad(FloatSize2d(event.newSize.width, event.newSize.height))
3737
}

xr/src/main/java/com/example/xr/scenecore/SpatialAudio.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import androidx.xr.runtime.Session
3030
import androidx.xr.scenecore.Entity
3131
import androidx.xr.scenecore.PointSourceParams
3232
import androidx.xr.scenecore.SoundFieldAttributes
33-
import androidx.xr.scenecore.SpatialCapabilities
33+
import androidx.xr.scenecore.SpatialCapability
3434
import androidx.xr.scenecore.SpatialMediaPlayer
3535
import androidx.xr.scenecore.SpatialSoundPool
3636
import androidx.xr.scenecore.SpatializerConstants
@@ -39,8 +39,7 @@ import androidx.xr.scenecore.scene
3939
private fun playSpatialAudioAtEntity(session: Session, appContext: Context, entity: Entity) {
4040
// [START androidxr_scenecore_playSpatialAudio]
4141
// Check spatial capabilities before using spatial audio
42-
if (session.scene.spatialCapabilities
43-
.hasCapability(SpatialCapabilities.SPATIAL_CAPABILITY_SPATIAL_AUDIO)
42+
if (session.scene.spatialCapabilities.contains(SpatialCapability.SPATIAL_AUDIO)
4443
) { // The session has spatial audio capabilities
4544
val maxVolume = 1F
4645
val lowPriority = 0
@@ -85,7 +84,7 @@ private fun playSpatialAudioAtEntity(session: Session, appContext: Context, enti
8584
private fun playSpatialAudioAtEntitySurround(session: Session, appContext: Context) {
8685
// [START androidxr_scenecore_playSpatialAudioSurround]
8786
// Check spatial capabilities before using spatial audio
88-
if (session.scene.spatialCapabilities.hasCapability(SpatialCapabilities.SPATIAL_CAPABILITY_SPATIAL_AUDIO)) {
87+
if (session.scene.spatialCapabilities.contains(SpatialCapability.SPATIAL_AUDIO)) {
8988
// The session has spatial audio capabilities
9089

9190
val pointSourceAttributes = PointSourceParams(session.scene.mainPanelEntity)
@@ -120,11 +119,11 @@ private fun playSpatialAudioAtEntitySurround(session: Session, appContext: Conte
120119
private fun playSpatialAudioAtEntityAmbionics(session: Session, appContext: Context) {
121120
// [START androidxr_scenecore_playSpatialAudioAmbionics]
122121
// Check spatial capabilities before using spatial audio
123-
if (session.scene.spatialCapabilities.hasCapability(SpatialCapabilities.SPATIAL_CAPABILITY_SPATIAL_AUDIO)) {
122+
if (session.scene.spatialCapabilities.contains(SpatialCapability.SPATIAL_AUDIO)) {
124123
// The session has spatial audio capabilities
125124

126125
val soundFieldAttributes =
127-
SoundFieldAttributes(SpatializerConstants.AMBISONICS_ORDER_FIRST_ORDER)
126+
SoundFieldAttributes(SpatializerConstants.AmbisonicsOrder.FIRST_ORDER)
128127

129128
val mediaPlayer = MediaPlayer()
130129

xr/src/main/java/com/example/xr/scenecore/SpatialCapabilities.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,22 @@
1717
package com.example.xr.scenecore
1818

1919
import androidx.xr.runtime.Session
20-
import androidx.xr.scenecore.SpatialCapabilities
20+
import androidx.xr.scenecore.SpatialCapability
21+
import androidx.xr.scenecore.SpatialCapability.Companion.SPATIAL_3D_CONTENT
2122
import androidx.xr.scenecore.scene
2223

2324
fun checkMultipleCapabilities(xrSession: Session) {
2425
// [START androidxr_compose_checkMultipleCapabilities]
2526
// Example 1: check if enabling passthrough mode is allowed
26-
if (xrSession.scene.spatialCapabilities.hasCapability(
27-
SpatialCapabilities.SPATIAL_CAPABILITY_PASSTHROUGH_CONTROL
27+
if (xrSession.scene.spatialCapabilities.contains(
28+
SpatialCapability.PASSTHROUGH_CONTROL
2829
)
2930
) {
3031
xrSession.scene.spatialEnvironment.preferredPassthroughOpacity = 1f
3132
}
3233
// Example 2: multiple capability flags can be checked simultaneously:
33-
if (xrSession.scene.spatialCapabilities.hasCapability(
34-
SpatialCapabilities.SPATIAL_CAPABILITY_PASSTHROUGH_CONTROL and
35-
SpatialCapabilities.SPATIAL_CAPABILITY_3D_CONTENT
36-
)
34+
if (xrSession.scene.spatialCapabilities.contains(SpatialCapability.PASSTHROUGH_CONTROL) &&
35+
xrSession.scene.spatialCapabilities.contains(SPATIAL_3D_CONTENT)
3736
) {
3837
// ...
3938
}

xr/src/main/java/com/example/xr/scenecore/SpatialVideo.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private fun ComponentActivity.surfaceEntityCreate(xrSession: Session) {
3737
// [START androidxr_scenecore_surfaceEntityCreate]
3838
val stereoSurfaceEntity = SurfaceEntity.create(
3939
session = xrSession,
40-
stereoMode = SurfaceEntity.StereoMode.STEREO_MODE_SIDE_BY_SIDE,
40+
stereoMode = SurfaceEntity.StereoMode.SIDE_BY_SIDE,
4141
pose = Pose(Vector3(0.0f, 0.0f, -1.5f)),
4242
shape = SurfaceEntity.Shape.Quad(FloatSize2d(1.0f, 1.0f))
4343
)
@@ -61,7 +61,7 @@ private fun ComponentActivity.surfaceEntityCreateSbs(xrSession: Session) {
6161
val hemisphereStereoSurfaceEntity =
6262
SurfaceEntity.create(
6363
session = xrSession,
64-
stereoMode = SurfaceEntity.StereoMode.STEREO_MODE_SIDE_BY_SIDE,
64+
stereoMode = SurfaceEntity.StereoMode.SIDE_BY_SIDE,
6565
pose = xrSession.scene.spatialUser.head?.transformPoseTo(
6666
Pose.Identity,
6767
xrSession.scene.activitySpace
@@ -78,7 +78,7 @@ private fun ComponentActivity.surfaceEntityCreateTb(xrSession: Session) {
7878
val sphereStereoSurfaceEntity =
7979
SurfaceEntity.create(
8080
session = xrSession,
81-
stereoMode = SurfaceEntity.StereoMode.STEREO_MODE_TOP_BOTTOM,
81+
stereoMode = SurfaceEntity.StereoMode.TOP_BOTTOM,
8282
pose = xrSession.scene.spatialUser.head?.transformPoseTo(
8383
Pose.Identity,
8484
xrSession.scene.activitySpace
@@ -94,7 +94,7 @@ private fun ComponentActivity.surfaceEntityCreateMVHEVC(xrSession: Session) {
9494
// Create the SurfaceEntity with the StereoMode corresponding to the MV-HEVC content
9595
val stereoSurfaceEntity = SurfaceEntity.create(
9696
session = xrSession,
97-
stereoMode = SurfaceEntity.StereoMode.STEREO_MODE_MULTIVIEW_LEFT_PRIMARY,
97+
stereoMode = SurfaceEntity.StereoMode.MULTIVIEW_LEFT_PRIMARY,
9898
pose = Pose(Vector3(0.0f, 0.0f, -1.5f)),
9999
shape = SurfaceEntity.Shape.Quad(FloatSize2d(1.0f, 1.0f))
100100
)
@@ -123,10 +123,10 @@ private fun ComponentActivity.surfaceEntityCreateDRM(xrSession: Session) {
123123
// Create the SurfaceEntity with the PROTECTED content security level.
124124
val protectedSurfaceEntity = SurfaceEntity.create(
125125
session = xrSession,
126-
stereoMode = SurfaceEntity.StereoMode.STEREO_MODE_SIDE_BY_SIDE,
126+
stereoMode = SurfaceEntity.StereoMode.SIDE_BY_SIDE,
127127
pose = Pose(Vector3(0.0f, 0.0f, -1.5f)),
128128
shape = SurfaceEntity.Shape.Quad(FloatSize2d(1.0f, 1.0f)),
129-
surfaceProtection = SurfaceEntity.SurfaceProtection.SURFACE_PROTECTION_PROTECTED
129+
surfaceProtection = SurfaceEntity.SurfaceProtection.PROTECTED
130130
)
131131

132132
// Build a MediaItem with the necessary DRM configuration.
@@ -156,16 +156,16 @@ private fun ComponentActivity.surfaceEntityHDR(xrSession: Session) {
156156
// Define the color properties for your HDR video. These values should be specific
157157
// to your content.
158158
val hdrMetadata = SurfaceEntity.ContentColorMetadata(
159-
colorSpace = SurfaceEntity.ContentColorMetadata.ColorSpace.COLOR_SPACE_BT2020,
160-
colorTransfer = SurfaceEntity.ContentColorMetadata.ColorTransfer.COLOR_TRANSFER_ST2084, // PQ
161-
colorRange = SurfaceEntity.ContentColorMetadata.ColorRange.COLOR_RANGE_LIMITED,
159+
colorSpace = SurfaceEntity.ContentColorMetadata.ColorSpace.BT2020,
160+
colorTransfer = SurfaceEntity.ContentColorMetadata.ColorTransfer.ST2084, // PQ
161+
colorRange = SurfaceEntity.ContentColorMetadata.ColorRange.LIMITED,
162162
maxContentLightLevel = 1000 // Example: 1000 nits
163163
)
164164

165165
// Create a SurfaceEntity, passing the HDR metadata at creation time.
166166
val hdrSurfaceEntity = SurfaceEntity.create(
167167
session = xrSession,
168-
stereoMode = SurfaceEntity.StereoMode.STEREO_MODE_MONO,
168+
stereoMode = SurfaceEntity.StereoMode.MONO,
169169
pose = Pose(Vector3(0.0f, 0.0f, -1.5f)),
170170
shape = SurfaceEntity.Shape.Quad(FloatSize2d(1.0f, 1.0f)),
171171
)

0 commit comments

Comments
 (0)