Skip to content

Commit 83d291d

Browse files
authored
Add snippet for dec jxr release. (#722)
* Updating snippets for december jxr releases.
1 parent 88e313c commit 83d291d

File tree

10 files changed

+95
-129
lines changed

10 files changed

+95
-129
lines changed

gradle/libs.versions.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ androidx-test-junit = "1.3.0"
2929
androidx-window = "1.5.0"
3030
androidx-window-core = "1.5.0"
3131
androidx-window-java = "1.5.0"
32-
androidx-xr-arcore = "1.0.0-alpha07"
33-
androidx-xr-compose = "1.0.0-alpha08"
34-
androidx-xr-scenecore = "1.0.0-alpha08"
32+
androidx-xr-arcore = "1.0.0-alpha09"
33+
androidx-xr-compose = "1.0.0-alpha09"
34+
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"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.xr.compose
18+
19+
import androidx.compose.runtime.Composable
20+
import androidx.compose.ui.unit.dp
21+
import androidx.xr.compose.platform.LocalSession
22+
import androidx.xr.compose.spatial.Subspace
23+
import androidx.xr.compose.subspace.SceneCoreEntity
24+
import androidx.xr.compose.subspace.SceneCoreEntitySizeAdapter
25+
import androidx.xr.compose.subspace.layout.SubspaceModifier
26+
import androidx.xr.compose.subspace.layout.offset
27+
import androidx.xr.runtime.math.IntSize2d
28+
import androidx.xr.runtime.math.Pose
29+
import androidx.xr.scenecore.SurfaceEntity
30+
31+
@Composable
32+
fun SceneCoreEntityExample() {
33+
val session = LocalSession.current
34+
if (session !== null) {
35+
// [START androidxr_compose_SceneCoreEntity]
36+
Subspace {
37+
SceneCoreEntity(
38+
modifier = SubspaceModifier.offset(x = 50.dp),
39+
factory = {
40+
SurfaceEntity.create(
41+
session = session,
42+
pose = Pose.Identity,
43+
stereoMode = SurfaceEntity.StereoMode.MONO
44+
)
45+
},
46+
update = { entity ->
47+
// compose state changes may be applied to the
48+
// SceneCore entity here.
49+
entity.stereoMode = SurfaceEntity.StereoMode.SIDE_BY_SIDE
50+
},
51+
sizeAdapter =
52+
SceneCoreEntitySizeAdapter({
53+
IntSize2d(it.width, it.height)
54+
}),
55+
) {
56+
// Content here will be children of the SceneCoreEntity
57+
// in the scene graph.
58+
}
59+
}
60+
// [END androidxr_compose_SceneCoreEntity]
61+
}
62+
}

xr/src/main/java/com/example/xr/compose/Subspace.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import androidx.activity.enableEdgeToEdge
2323
import androidx.compose.foundation.layout.Row
2424
import androidx.compose.runtime.Composable
2525
import androidx.xr.compose.platform.LocalSession
26-
import androidx.xr.compose.spatial.ApplicationSubspace
2726
import androidx.xr.compose.spatial.Subspace
2827
import androidx.xr.compose.subspace.SpatialPanel
2928
import androidx.xr.scenecore.scene
@@ -35,7 +34,7 @@ private class SubspaceActivity : ComponentActivity() {
3534
// [START androidxr_compose_SubspaceSetContent]
3635
setContent {
3736
// This is a top-level subspace
38-
ApplicationSubspace {
37+
Subspace {
3938
SpatialPanel {
4039
MyComposable()
4140
}
@@ -59,7 +58,7 @@ private fun PrimaryPane() {
5958
// This is a nested subspace, because PrimaryPane is in a SpatialPanel
6059
// and that SpatialPanel is in a top-level Subspace
6160
Subspace {
62-
ObjectInAVolume(true)
61+
SpatialPanel {}
6362
}
6463
}
6564
// [END androidxr_compose_SubspaceComponents]

xr/src/main/java/com/example/xr/compose/Volume.kt

Lines changed: 0 additions & 91 deletions
This file was deleted.

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(SpatialCapability.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)