A gesture detector optimized to recognize touch gestures for the touchpad.
There are discrete gesture listeners (e.g., GestureDetector.BaseListener
, GestureDetector.FingerListener
)
and continuous gesture listeners, (e.g., GestureDetector.ScrollListener
,
GestureDetector.OneFingerScrollListener
, GestureDetector.TwoFingerScrollListener
).
For more information, see the Touch gestures developer guide.
General usage
- Implement any desired listener interfaces and set them on the
GestureDetector
. - Override input event callbacks such as
onGenericMotionEvent(MotionEvent)
ordispatchGenericFocusedEvent(MotionEvent)
and pass theMotionEvent
to the gesture detector'sonMotionEvent(MotionEvent)
method to process the event. - Handle the event appropriately in your gesture detector listeners.
Note: When implementing the
onXXX
methods for listeners, set the return value totrue
only if you do not want to dispatch theMotionEvent
to any other listening entities in the input dispatch pipeline.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
interface | GestureDetector.BaseListener | Receives detection results. | |||||||||
interface | GestureDetector.FingerListener | This listener reports when the detected finger count changes on the touchpad. | |||||||||
interface | GestureDetector.OneFingerScrollListener | This listener receives continuous one finger horizontal scrolling events. | |||||||||
interface | GestureDetector.ScrollListener | This listener receives continuous horizontal scrolling events independent of the finger count. | |||||||||
interface | GestureDetector.TwoFingerScrollListener | This listener receives continuous two finger horizontal scrolling events. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
GestureDetector(Context context)
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
static boolean | |||||||||||
static boolean |
isForward(float deltaX)
|
||||||||||
boolean |
onMotionEvent(MotionEvent event)
|
||||||||||
GestureDetector |
setAlwaysConsumeEvents(boolean enabled)
|
||||||||||
GestureDetector |
setBaseListener(GestureDetector.BaseListener listener)
|
||||||||||
GestureDetector | |||||||||||
GestureDetector | |||||||||||
GestureDetector | |||||||||||
GestureDetector |
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Constructors
Public Methods
public static boolean isForward (Gesture gesture)
Returns true
if the given gesture corresponds to forward motion on the touchpad.
This method only makes sense for lateral swipes and throws an exception if called on other gestures.
public static boolean isForward (float deltaX)
Returns true
if the given displacement corresponds to forward motion on the touchpad.
public boolean onMotionEvent (MotionEvent event)
Processes a motion event, returning true
if events should always be consumed or if
a gesture was detected.
Returns
- reflects whether touch event is consumed
public GestureDetector setAlwaysConsumeEvents (boolean enabled)
Sets if the gesture detector should consume events passed to
onMotionEvent(MotionEvent)
, regardless of whether they were actually handled.
public GestureDetector setBaseListener (GestureDetector.BaseListener listener)
Sets the basic gesture listener.
public GestureDetector setFingerListener (GestureDetector.FingerListener listener)
Sets the finger listener.
public GestureDetector setOneFingerScrollListener (GestureDetector.OneFingerScrollListener listener)
Sets the listener that detects horizontal and one finger scrolling.
public GestureDetector setScrollListener (GestureDetector.ScrollListener listener)
Sets the listener that detects horizontal scrolling independent of the finger count.
public GestureDetector setTwoFingerScrollListener (GestureDetector.TwoFingerScrollListener listener)
Sets the listener that detects horizontal and two finger scrolling.