public class DoubleTapScrollGesture extends Object implements GestureHandler
MouseEvent
s
while producing MouseEvent.EVENT_MOUSE_WHEEL_MOVED
events if gesture is completed.
Criteria related to parameters:
- doubleTapSlop (scaled in pixels): - Max 2 finger distance to start 'scroll' mode - Max. distance diff of current 2-pointer middle and initiated 2-pointer middle. - touchSlop (scaled in pixels): - Min. movement w/ 2 pointer within ScaledDoubleTapSlop starting 'scroll' mode - Avoid computation if not within gesture, especially for MOVE/DRAG - Only allow gesture to start with PRESS - Leave gesture completely with RELEASE of both/all fingers, or dist-diff exceeds doubleTapSlop - Tolerate temporary lift 1 of 2 pointer - Always validate pointer-idImplementation uses a n-state to get detect gesture:
from | to | action |
---|---|---|
NONE | 1PRESS | 1-pointer-pressed |
1PRESS | 2PRESS_T | 2-pointer-pressed within doubleTapSlope |
2PRESS_T | SCROLL | 2-pointer dragged, dist-diff within doubleTapSlop and scrollLen >= scrollSlop |
2PRESS_C | SCROLL | 2-pointer dragged, dist-diff within doubleTapSlop |
SCROLL | SCROLL | 2-pointer dragged, dist-diff within doubleTapSlop |
isWithinGesture()
returns gestureState >= 2PRESS_C
GestureHandler.GestureEvent, GestureHandler.GestureListener
Modifier and Type | Field and Description |
---|---|
static float |
DOUBLE_TAP_SLOP_MM
Two pointer 'double tap' slop in millimeter, defaults to 20 mm.
|
static int |
DOUBLE_TAP_SLOP_PIXEL
Two pointer 'double tap' slop in pixels (fallback), defaults to 104 pixels.
|
static float |
SCROLL_SLOP_MM
Scroll threshold in millimeter, defaults to 3 mm.
|
static int |
SCROLL_SLOP_PIXEL
Scroll threshold in pixels (fallback), defaults to 16 pixels.
|
DEBUG
Constructor and Description |
---|
DoubleTapScrollGesture(int scaledScrollSlop,
int scaledDoubleTapSlop)
scaledScrollSlop < scaledDoubleTapSlop
|
Modifier and Type | Method and Description |
---|---|
void |
clear(boolean clearStarted)
Clears state of handler, i.e.
|
InputEvent |
getGestureEvent()
Returns the corresponding
InputEvent for the gesture as detected by
a previous GestureHandler.process(InputEvent) , which has not been cleared . |
float[] |
getScrollDistanceXY() |
boolean |
hasGesture()
Returns true if a previous
GestureHandler.process(InputEvent) command produced a gesture,
which has not been cleared . |
boolean |
isWithinGesture()
Returns true if within a gesture as detected by a previous
GestureHandler.process(InputEvent) command,
which has not been cleared . |
boolean |
process(InputEvent in)
Process the given
InputEvent and returns true if it produced the gesture. |
String |
toString() |
public static final int SCROLL_SLOP_PIXEL
newt.event.scroll_slop_pixel
.public static final int DOUBLE_TAP_SLOP_PIXEL
newt.event.double_tap_slop_pixel
.public static final float SCROLL_SLOP_MM
newt.event.scroll_slop_mm
.public static final float DOUBLE_TAP_SLOP_MM
newt.event.double_tap_slop_mm
.public DoubleTapScrollGesture(int scaledScrollSlop, int scaledDoubleTapSlop)
scaledScrollSlop
- Distance a pointer can wander before we think the user is scrolling in pixels.scaledDoubleTapSlop
- Distance in pixels between the first touch and second touch to still be considered a double tap.public void clear(boolean clearStarted)
GestureHandler
clear
in interface GestureHandler
clearStarted
- if true, also clears started
state,
otherwise stay within gesture - if appropriate.
Staying within a gesture allows fluent continuous gesture sequence,
e.g. for scrolling.public boolean isWithinGesture()
GestureHandler
GestureHandler.process(InputEvent)
command,
which has not been cleared
.
Otherwise returns false.isWithinGesture
in interface GestureHandler
public boolean hasGesture()
GestureHandler
GestureHandler.process(InputEvent)
command produced a gesture,
which has not been cleared
.
Otherwise returns false.hasGesture
in interface GestureHandler
public InputEvent getGestureEvent()
GestureHandler
InputEvent
for the gesture as detected by
a previous GestureHandler.process(InputEvent)
, which has not been cleared
.
Otherwise returns null.
Only implemented for gestures mapping to InputEvent
s.
getGestureEvent
in interface GestureHandler
public final float[] getScrollDistanceXY()
public boolean process(InputEvent in)
GestureHandler
InputEvent
and returns true if it produced the gesture.
Otherwise returns false.
If a gesture was already detected previously and has not been cleared, method does not process the event and returns true.
Besides validation of the event's details,
the handler may also validate the InputEvent.InputClass
and/or InputEvent.InputType
.
process
in interface GestureHandler
Copyright 2010 JogAmp Community.