@@ -35,18 +35,19 @@ import androidx.xr.scenecore.scene
3535import kotlinx.coroutines.flow.Flow
3636import kotlinx.coroutines.launch
3737
38- @Suppress(" RestrictedApi" ) // b/416288516 - session.config and session.configure() are incorrectly restricted
3938fun ComponentActivity.configureSession (session : Session ) {
4039 // [START androidxr_arcore_hand_configure]
4140 val newConfig = session.config.copy(
42- handTracking = Config .HandTrackingMode .Enabled
41+ handTracking = Config .HandTrackingMode .BOTH
4342 )
4443 when (val result = session.configure(newConfig)) {
4544 is SessionConfigureConfigurationNotSupported ->
4645 TODO (/* Some combinations of configurations are not valid. Handle this failure case. */ )
4746 is SessionConfigurePermissionsNotGranted ->
4847 TODO (/* The required permissions in result.permissions have not been granted. */ )
4948 is SessionConfigureSuccess -> TODO (/* Success! */ )
49+ else ->
50+ TODO (/* A different unhandled exception was thrown. */ )
5051 }
5152 // [END androidxr_arcore_hand_configure]
5253}
@@ -71,13 +72,14 @@ fun ComponentActivity.collectHands(session: Session) {
7172fun secondaryHandDetection (activity : Activity , session : Session ) {
7273 fun detectGesture (handState : Flow <Hand .State >) {}
7374 // [START androidxr_arcore_hand_handedness]
74- val handedness = Hand .getHandedness (activity.contentResolver)
75- val secondaryHand = if (handedness == Hand .Handedness .LEFT ) Hand .right(session) else Hand .left(session)
75+ val handedness = Hand .getPrimaryHandSide (activity.contentResolver)
76+ val secondaryHand = if (handedness == Hand .HandSide .LEFT ) Hand .right(session) else Hand .left(session)
7677 val handState = secondaryHand?.state ? : return
7778 detectGesture(handState)
7879 // [END androidxr_arcore_hand_handedness]
7980}
8081
82+ @Suppress(" RestrictedApi" ) // b/416066566
8183fun ComponentActivity.renderPlanetAtHandPalm (leftHandState : Hand .State ) {
8284 val session: Session = null !!
8385 val palmEntity: GltfModelEntity = null !!
@@ -86,7 +88,7 @@ fun ComponentActivity.renderPlanetAtHandPalm(leftHandState: Hand.State) {
8688
8789 // the down direction points in the same direction as the palm
8890 val angle = Vector3 .angleBetween(palmPose.rotation * Vector3 .Down , Vector3 .Up )
89- palmEntity.setHidden (angle > Math .toRadians(40.0 ))
91+ palmEntity.setEnabled (angle > Math .toRadians(40.0 ))
9092
9193 val transformedPose =
9294 session.scene.perceptionSpace.transformPoseTo(
@@ -98,6 +100,7 @@ fun ComponentActivity.renderPlanetAtHandPalm(leftHandState: Hand.State) {
98100 // [END androidxr_arcore_hand_entityAtHandPalm]
99101}
100102
103+ @Suppress(" RestrictedApi" ) // b/416066566
101104fun ComponentActivity.renderPlanetAtFingerTip (rightHandState : Hand .State ) {
102105 val session: Session = null !!
103106 val indexFingerEntity: GltfModelEntity = null !!
@@ -107,7 +110,7 @@ fun ComponentActivity.renderPlanetAtFingerTip(rightHandState: Hand.State) {
107110
108111 // the forward direction points towards the finger tip.
109112 val angle = Vector3 .angleBetween(tipPose.rotation * Vector3 .Forward , Vector3 .Up )
110- indexFingerEntity.setHidden (angle > Math .toRadians(40.0 ))
113+ indexFingerEntity.setEnabled (angle > Math .toRadians(40.0 ))
111114
112115 val transformedPose =
113116 session.scene.perceptionSpace.transformPoseTo(
@@ -120,6 +123,7 @@ fun ComponentActivity.renderPlanetAtFingerTip(rightHandState: Hand.State) {
120123 // [END androidxr_arcore_hand_entityAtIndexFingerTip]
121124}
122125
126+ @Suppress(" RestrictedApi" ) // b/416066566
123127private fun detectPinch (session : Session , handState : Hand .State ): Boolean {
124128 // [START androidxr_arcore_hand_pinch_gesture]
125129 val thumbTip = handState.handJoints[HandJointType .THUMB_TIP ] ? : return false
0 commit comments