Package com.google.ar.sceneform
Class TouchEventSystem
- java.lang.Object
-
- com.google.ar.sceneform.TouchEventSystem
-
public class TouchEventSystem extends java.lang.Object
Manages propagation of touch events to node's within a scene.The way that touch events are propagated mirrors the way touches are propagated to Android Views.
When an ACTION_DOWN event occurs, that represents that start of a gesture. ACTION_UP or ACTION_CANCEL represents when a gesture ends. When a gesture starts, the following is done:
- Call
Node.dispatchTouchEvent(HitTestResult, MotionEvent)
on the node that was touched as detected by scene.hitTest. - If
Node.dispatchTouchEvent(HitTestResult, MotionEvent)
returns false, recurse upwards through the node's parents and callNode.dispatchTouchEvent(HitTestResult, MotionEvent)
until one of the node's returns true. - If every node returns false, the gesture is ignored and subsequent events that are part of the gesture will not be passed to any nodes.
- If one of the node's returns true, then that node will receive all future touch events for the gesture.
- Call
-
-
Constructor Summary
Constructors Constructor Description TouchEventSystem()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addOnPeekTouchListener(Scene.OnPeekTouchListener onPeekTouchListener)
Adds a listener that will be called before theScene.OnTouchListener
is invoked.Scene.OnTouchListener
getOnTouchListener()
Get the currently registered callback for touch events.void
onTouchEvent(HitTestResult hitTestResult, android.view.MotionEvent motionEvent)
void
removeOnPeekTouchListener(Scene.OnPeekTouchListener onPeekTouchListener)
Removes a listener that will be called before theScene.OnTouchListener
is invoked.void
setOnTouchListener(Scene.OnTouchListener onTouchListener)
Register a callback to be invoked when the scene is touched.
-
-
-
Method Detail
-
getOnTouchListener
@Nullable public Scene.OnTouchListener getOnTouchListener()
Get the currently registered callback for touch events.- Returns:
- the attached touch listener
- See Also:
setOnTouchListener(Scene.OnTouchListener)
-
setOnTouchListener
public void setOnTouchListener(@Nullable Scene.OnTouchListener onTouchListener)
Register a callback to be invoked when the scene is touched. The callback is invoked before any node receives the event. If the callback handles the event, then the gesture is never received by the nodes.- Parameters:
onTouchListener
- the touch listener to attach
-
addOnPeekTouchListener
public void addOnPeekTouchListener(Scene.OnPeekTouchListener onPeekTouchListener)
Adds a listener that will be called before theScene.OnTouchListener
is invoked. This is invoked even if the gesture was consumed, making it possible to observe all motion events dispatched to the scene. This is called even if the touch is not over a node, in which caseHitTestResult.getNode()
will be null. The listeners will be called in the order in which they were added.- Parameters:
onPeekTouchListener
- the peek touch listener to add
-
removeOnPeekTouchListener
public void removeOnPeekTouchListener(Scene.OnPeekTouchListener onPeekTouchListener)
Removes a listener that will be called before theScene.OnTouchListener
is invoked. This is invoked even if the gesture was consumed, making it possible to observe all motion events dispatched to the scene. This is called even if the touch is not over a node, in which caseHitTestResult.getNode()
will be null.- Parameters:
onPeekTouchListener
- the peek touch listener to remove
-
onTouchEvent
public void onTouchEvent(HitTestResult hitTestResult, android.view.MotionEvent motionEvent)
-
-