Skip to content

Instantly share code, notes, and snippets.

View sarimmehdi's full-sized avatar

Muhammad Sarim Mehdi sarimmehdi

View GitHub Profile
@sarimmehdi
sarimmehdi / GestureDetector.kt
Created February 12, 2022 08:38
Code for the Gesture Detector class
package com.sarim.sceneformgesturestutorial
import android.view.GestureDetector
import android.view.MotionEvent
class GestureDetector : GestureDetector.SimpleOnGestureListener() {
enum class GestureType {
NONE, SINGLE_TAP, DOUBLE_TAP, LONG_PRESS
}
@sarimmehdi
sarimmehdi / MainActivity.kt
Created February 12, 2022 08:39
listen for touch events on ArSceneView
arSceneView.scene.setOnTouchListener {
hitTestResult : HitTestResult?, motionEvent : MotionEvent? ->
gestureDetectorCompat!!.onTouchEvent(motionEvent)
when (gestureDetector.gestureType) {
GestureDetector.GestureType.SINGLE_TAP -> {
Toast.makeText(this, "SINGLE TAP", Toast.LENGTH_SHORT).show()
}
GestureDetector.GestureType.DOUBLE_TAP -> {
Toast.makeText(this, "DOUBLE TAP", Toast.LENGTH_SHORT).show()
}
@sarimmehdi
sarimmehdi / MainActivity.kt
Created February 12, 2022 08:40
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()