public final class TouchGestureRecognizer extends Object implements 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 and Description |
---|
TouchGestureRecognizer(IInputEventCallback callback,
ITaskScheduler taskScheduler)
Creates a
TouchGestureRecognizer The generated high level IInputEvent s are passed to the given callback on the UI thread. |
Modifier and Type | Method and Description |
---|---|
void |
close() |
protected void |
finalize() |
double |
getDisplayScale() |
double |
getDpi() |
ScreenDistance |
getDragThreshold() |
long |
getLongPressThreshold() |
long |
getMultiTapInterval() |
ScreenDistance |
getMultiTapThreshold() |
void |
onTouchEvent(TouchPointEvent touchPointEvent)
Entry point for the touch events of the gesture recognizer.
|
void |
setDisplayScale(double scale)
Set the display scale factor.
|
void |
setDpi(double dpi)
Set the display pixel density in dots per inch.
|
void |
setDragThreshold(ScreenDistance threshold)
Sets the screen distance that is used as threshold to detect if a drag is performed while using touch inputs.
|
void |
setLongPressThreshold(long longPressThreshold)
Set the threshold, in milliseconds, to reach before a long press event is sent.
|
void |
setMultiTapInterval(long interval)
Set the interval used to detect multiple taps (default is 400 ms).
|
void |
setMultiTapThreshold(ScreenDistance threshold)
Set the screen distance threshold to detect multiple taps.
|
public TouchGestureRecognizer(@NotNull IInputEventCallback callback, @Nullable ITaskScheduler taskScheduler) throws NullPointerException
TouchGestureRecognizer
The generated high level IInputEvent
s 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 IInputEvent
needs 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.
callback
- the callback that receive generated IInputEvent
s. Can not be null
.taskScheduler
- a scheduler allowing the caller to receive some IInputEvent
s on another thread and resolve them on the UI thread. Can be null
. If null
, some events won't be emitted.NullPointerException
- If callback is null
.public void close()
close
in interface AutoCloseable
public void onTouchEvent(@NotNull TouchPointEvent touchPointEvent)
touchPointEvent
- the TouchPointEvent
object containing a collection of TouchPoint
s.public void setMultiTapInterval(long interval)
interval
- the maximum time (in milliseconds) between multiple taps. If the interval is set to 0, no multiple taps will be detected.public long getMultiTapInterval()
public void setDragThreshold(@NotNull ScreenDistance threshold)
It means that the input device 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.
threshold
- the screen distance threshold@NotNull public ScreenDistance getDragThreshold()
public void setMultiTapThreshold(@NotNull ScreenDistance threshold)
It means that consecutive taps need to be as close as that distance in order to generate an event for a multiple tap.
threshold
- the distance threshold@NotNull public ScreenDistance getMultiTapThreshold()
public void setLongPressThreshold(long longPressThreshold)
The default is 700 ms.
longPressThreshold
- the threshold in milliseconds.public long getLongPressThreshold()
public void setDpi(double dpi)
If no value is provided, the platform standard pixel density is assumed.
dpi
- the pixel density in dots per inchpublic double getDpi()
public void setDisplayScale(double scale)
If no value is provided, a scale factor of 1.0 is assumed.
scale
- the display scale factor (adimensional scale value)public double getDisplayScale()