The Google Glass Explorer Edition SDK is deprecated. This documentation is no longer being maintained. If you're interested in developing Glass solutions for enterprise clients, visit the Google Glass Enterprise Edition developer documentation.

GestureDetector

Added in API level XE12

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

  1. Implement any desired listener interfaces and set them on the GestureDetector.
  2. Override input event callbacks such as onGenericMotionEvent(MotionEvent) or dispatchGenericFocusedEvent(MotionEvent) and pass the MotionEvent to the gesture detector's onMotionEvent(MotionEvent) method to process the event.
  3. Handle the event appropriately in your gesture detector listeners.

    Note: When implementing the onXXX methods for listeners, set the return value to true only if you do not want to dispatch the MotionEvent 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
Public Methods
static boolean
isForward(Gesture gesture)
static boolean
isForward(float deltaX)
boolean
GestureDetector
setAlwaysConsumeEvents(boolean enabled)
GestureDetector
GestureDetector
GestureDetector
GestureDetector
GestureDetector
Inherited Methods

Public Constructors

Added in API level XE12

public GestureDetector (Context context)

Public Methods

Added in API level XE16

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.

Added in API level XE16

public static boolean isForward (float deltaX)

Returns true if the given displacement corresponds to forward motion on the touchpad.

Added in API level XE12

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
Added in API level XE12

public GestureDetector setAlwaysConsumeEvents (boolean enabled)

Sets if the gesture detector should consume events passed to onMotionEvent(MotionEvent), regardless of whether they were actually handled.

Added in API level XE12

public GestureDetector setBaseListener (GestureDetector.BaseListener listener)

Sets the basic gesture listener.

Added in API level XE12

public GestureDetector setFingerListener (GestureDetector.FingerListener listener)

Sets the finger listener.

Added in API level XE21

public GestureDetector setOneFingerScrollListener (GestureDetector.OneFingerScrollListener listener)

Sets the listener that detects horizontal and one finger scrolling.

Added in API level XE12

public GestureDetector setScrollListener (GestureDetector.ScrollListener listener)

Sets the listener that detects horizontal scrolling independent of the finger count.

Added in API level XE12

public GestureDetector setTwoFingerScrollListener (GestureDetector.TwoFingerScrollListener listener)

Sets the listener that detects horizontal and two finger scrolling.