Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect user's gesture such as swipe

I am using phonegap for build android apps.

I would like to detect user's gesture such as a user's swipe. Is there an event i can call from javascript?

Thanks!

like image 264
Dayzza Avatar asked Feb 07 '11 07:02

Dayzza


People also ask

What are swipe gestures?

One of the most common gestures you will use on your smartphone or tablet is a swipe. That's where you place your finger on the screen and slide it across the surface. In most instances, the item under your finger will move.

What is swipe gesture in Android?

Gesture navigation: At the very bottom of the screen, swipe from left to right. 2-button navigation: To switch between your 2 most recent apps, swipe right on Home . 3-button navigation: Tap Overview . Swipe right until you find the app you want.

How do you get a swipe event?

The swipe event is triggered when the user press down and swipes over an element horizontally by more than 30px (and less than 75px vertically). Tip: You can swipe in both right and left direction. Related events: swipeleft - triggered when the user swipes over an element in the left direction.

What is gesture detector in Android Studio?

android.view.GestureDetector. Detects various gestures and events using the supplied MotionEvent s. The OnGestureListener callback will notify users when a particular motion event has occurred. This class should only be used with MotionEvent s reported via touch (don't use for trackball events).


1 Answers

I use a JavaScript framework called xui (homepage) that has a similar API to jQuery.

You can use this framework coupled with the swipe plugin to get access to easy gesture events. See the swipe/ directory under that repository for the code and example (specifically under index.html). A brief example:

x$('body').swipe(function(e, data) {
    console.log('type:' + data.type + ' deltaX:' + data.deltaX + ' deltaY:' + data.deltaY + ' distance:' + data.distance + ' delay:' + data.delay+' direction:' + data.direction  );
});
like image 128
fil maj Avatar answered Oct 14 '22 03:10

fil maj