Skip to content

Instantly share code, notes, and snippets.

@sarimmehdi
Created February 12, 2022 08:40
Show Gist options
  • Save sarimmehdi/5c111e34b09649af406891c3cb35d031 to your computer and use it in GitHub Desktop.
Save sarimmehdi/5c111e34b09649af406891c3cb35d031 to your computer and use it in GitHub Desktop.
Updated code for touch event listener
arSceneView.scene.setOnTouchListener {
hitTestResult : HitTestResult?, motionEvent : MotionEvent? ->
gestureDetectorCompat!!.onTouchEvent(motionEvent)
when (gestureDetector.gestureType) {
GestureDetector.GestureType.SINGLE_TAP -> {
if (hitTestResult!!.node == null) {
Toast.makeText(this, "SINGLE TAP performed", Toast.LENGTH_SHORT).show()
}
else {
Toast.makeText(this, "SINGLE TAP performed on a node", Toast.LENGTH_SHORT).show()
}
}
GestureDetector.GestureType.DOUBLE_TAP -> {
if (hitTestResult!!.node == null) {
Toast.makeText(this, "DOUBLE TAP performed", Toast.LENGTH_SHORT).show()
}
else {
Toast.makeText(this, "DOUBLE TAP performed on a node", Toast.LENGTH_SHORT).show()
}
}
GestureDetector.GestureType.LONG_PRESS -> {
if (hitTestResult!!.node == null) {
Toast.makeText(this, "LONG PRESS performed", Toast.LENGTH_SHORT).show()
}
else {
Toast.makeText(this, "LONG PRESS performed on a node", Toast.LENGTH_SHORT).show()
}
}
else -> { }
}
gestureDetector.resetGestureType()
true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment