Class TouchGestureRecognizer
- All Implemented Interfaces:
AutoCloseable
High level events are subclasses of IInputEvent such as TouchTapEvent. Sequences of low level events are used to create those high level events.
For example, a touch press + movement of the touch point (possibly multiple times) sequence is recognized as a touch drag gesture. A touch press + a touch release sequence is recognized as a touch tap gesture. This class is useful when adding integration with a platform that does not provide these more high-level events.
A typical use of such a class is to wire it to a UI framework specific class (such as Qt , see QQuickMapObject in the sample code) and make the controller react to the high level event instead of every low level event the framework can fire.
The use of the TouchGestureRecognizer is optional. A controller implementation can use custom conversion code if needed, for example if you want to manage the low level events yourself and create other high level IInputEvent instances.
The events passed to this class are expected to be defined in device independent pixels.
-
Constructor Summary
ConstructorsConstructorDescriptionTouchGestureRecognizer(IInputEventCallback callback, ITaskScheduler taskScheduler) Creates aTouchGestureRecognizerThe generated high levelIInputEvents are passed to the given callback on the UI thread. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()booleanprotected voidfinalize()doubleReturns the display scale factor.doublegetDpi()Returns the display pixel density in dots per inch.Returns the screen distance that is used as threshold to detect if a drag is performed.longReturns the threshold to reach (in milliseconds) before a long press event is sent.longReturns the interval (in milliseconds) used to detect multiple taps.Returns the screen distance threshold used to detect multiple taps.inthashCode()voidonTouchEvent(TouchPointEvent touchPointEvent) Entry point for the touch events of the gesture recognizer.voidsetDisplayScale(double scale) Sets the display scale factor.voidsetDpi(double dpi) Sets the display pixel density in dots per inch.voidsetDragThreshold(ScreenDistance threshold) Sets the screen distance that is used as threshold to detect if a drag is performed.voidsetLongPressThreshold(long longPressThreshold) Sets the threshold to reach (in milliseconds) before a long press event is sent.voidsetMultiTapInterval(long interval) Sets the interval (in milliseconds) used to detect multiple taps.voidsetMultiTapThreshold(ScreenDistance threshold) Sets the screen distance threshold used to detect multiple taps.
-
Constructor Details
-
TouchGestureRecognizer
public TouchGestureRecognizer(@NotNull IInputEventCallback callback, @Nullable ITaskScheduler taskScheduler) throws NullPointerException Creates aTouchGestureRecognizerThe generated high levelIInputEvents are passed to the given callback on the UI thread.For certain events, like for example a long press, an internal timer is used to determine when an
IInputEventneeds to be sent. Due to the use of a timer, it is possible that some work is done on a different thread than the UI thread. The task scheduler can be used to apply the result of the timer on the UI thread.- Parameters:
callback- the callback that receive generatedIInputEvents. Can not benull.taskScheduler- a scheduler allowing the caller to receive someIInputEvents on another thread and resolve them on the UI thread. Can benull. Ifnull, some events won't be emitted.- Throws:
NullPointerException- If callback isnull.
-
-
Method Details
-
finalize
protected void finalize() -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
onTouchEvent
Entry point for the touch events of the gesture recognizer.- Parameters:
touchPointEvent- theTouchPointEventobject containing a collection ofTouchPoints.
-
setMultiTapInterval
public void setMultiTapInterval(long interval) Sets the interval (in milliseconds) used to detect multiple taps.The default is 400 ms.
If the interval is set to 0, no multiple taps will be detected.
- Parameters:
interval- the interval (in milliseconds) used to detect multiple taps.
-
getMultiTapInterval
public long getMultiTapInterval()Returns the interval (in milliseconds) used to detect multiple taps.- Returns:
- the interval (in milliseconds) used to detect multiple taps.
-
setDragThreshold
Sets the screen distance that is used as threshold to detect if a drag is performed.It means that the input has to move at least that distance before it can be detected as a drag gesture.
The default drag threshold is a screen distance of 5 mm.
- Parameters:
threshold- the screen distance threshold
-
getDragThreshold
Returns the screen distance that is used as threshold to detect if a drag is performed.- Returns:
- the screen distance that is used as threshold to detect if a drag is performed.
-
setMultiTapThreshold
Sets the screen distance threshold used to detect multiple taps.It means that consecutive taps need to be as close as that distance in order to generate an event for a multiple tap.
- Parameters:
threshold- the distance threshold
-
getMultiTapThreshold
Returns the screen distance threshold used to detect multiple taps.- Returns:
- the screen distance threshold used to detect multiple taps.
-
setLongPressThreshold
public void setLongPressThreshold(long longPressThreshold) Sets the threshold to reach (in milliseconds) before a long press event is sent.The default is 700 ms.
- Parameters:
longPressThreshold- the threshold in milliseconds.
-
getLongPressThreshold
public long getLongPressThreshold()Returns the threshold to reach (in milliseconds) before a long press event is sent.- Returns:
- the threshold to reach (in milliseconds) before a long press event is sent.
-
setDpi
public void setDpi(double dpi) Sets the display pixel density in dots per inch.If no value is provided, the platform standard pixel density is assumed.
- Parameters:
dpi- the pixel density in dots per inch
-
getDpi
public double getDpi()Returns the display pixel density in dots per inch.- Returns:
- the display pixel density in dots per inch.
-
setDisplayScale
public void setDisplayScale(double scale) Sets the display scale factor.If no value is provided, a scale factor of 1.0 is assumed.
- Parameters:
scale- the display scale factor
-
getDisplayScale
public double getDisplayScale()Returns the display scale factor.- Returns:
- the display scale factor.
-
hashCode
public int hashCode() -
equals
-