Skip to content

Commit fa2bce8

Browse files
committed
Add snippet that demonstrates how to detect a secondary hand
1 parent ce81ef6 commit fa2bce8

File tree

1 file changed

+12
-0
lines changed
  • xr/src/main/java/com/example/xr/arcore

1 file changed

+12
-0
lines changed

xr/src/main/java/com/example/xr/arcore/Hands.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.example.xr.arcore
1818

19+
import android.app.Activity
1920
import androidx.activity.ComponentActivity
2021
import androidx.lifecycle.lifecycleScope
2122
import androidx.xr.arcore.Hand
@@ -30,6 +31,7 @@ import androidx.xr.runtime.math.Quaternion
3031
import androidx.xr.runtime.math.Vector3
3132
import androidx.xr.scenecore.GltfModelEntity
3233
import androidx.xr.scenecore.scene
34+
import kotlinx.coroutines.flow.Flow
3335
import kotlinx.coroutines.launch
3436

3537
@Suppress("RestrictedApi") // b/416288516 - session.config and session.configure() are incorrectly restricted
@@ -65,6 +67,16 @@ fun ComponentActivity.collectHands(session: Session) {
6567
}
6668
}
6769

70+
fun secondaryHandDetection(activity: Activity, session: Session) {
71+
fun detectGesture(handState: Flow<Hand.State>) {}
72+
// [START androidxr_arcore_hand_handedness]
73+
val handedness = Hand.getHandedness(activity.contentResolver)
74+
val secondaryHand = if (handedness == Hand.Handedness.LEFT) Hand.right(session) else Hand.left(session)
75+
val handState = secondaryHand?.state ?: return
76+
detectGesture(handState)
77+
// [END androidxr_arcore_hand_handedness]
78+
}
79+
6880
fun ComponentActivity.renderPlanetAtHandPalm(leftHandState: Hand.State) {
6981
val session: Session = null!!
7082
val palmEntity: GltfModelEntity = null!!

0 commit comments

Comments
 (0)