B4A Library [Lib] Gesture Detector

This library adds the detection of standard gestures (press, single-tap, double-tap, long tap, drag, scroll, fling, pinch, rotation) to B4A. Instead of using the Touch events to figure out what the user really did, now you just set 15 different listeners with one line of code and you get the gestures as events with all the useful values (scrolling distance, fling velocity, pinch variation, rotation angle...).
With this library, you can also know easily the pressure or the size of a touch event.

It works with any view.

Note: you have to create an instance of GestureDetector (with Dim) for each view you want to bind to the detector with SetOnGestureListener.

v2.2:
- Freeware.

v2.3:
- I fixed an issue with the boolean value returned by the OnTouch event with some views (e.g. ListView or ScrollView);
- I added a new demo (GD_SwipeLV);
- The OnDown event is now raised before OnDoubleTap.

v2.4:
- I fixed an issue when a view is dragged after one of the pointer is up (delta values were computed according to the pointer 0, not to the remaining pointer).

Incompatible with Android versions < 2.
 

Attachments

  • GestureDetector v2.4.zip
    35.3 KB · Views: 3,316
  • Java source - GestureDetector.zip
    5.5 KB · Views: 1,355
Last edited:

Informatix

Expert
Licensed User
Longtime User
v2.01 does the demo project work with this version of the library?
mine is crashing.

What's your Android version?
Could you send the content of your log?

Usually, all I do is tested with the following Android versions: 2.3.6, 3.2, 4.0.3 and 4.1. I never released and will never release something untested.

The only reason I see for a crash is an incompatible Android version (API < 7).
 
Last edited:

vb1992

Well-Known Member
Licensed User
Longtime User
It's working on my home computer, I think my work computer had the new library with the old demo project.

Check the demo gesture_drag with this setting:

Activity.AddView(pnlGreen, 30dip, 30dip, 30dip, 30dip)

is that always detecting the fling/drag on your devices?
 

vb1992

Well-Known Member
Licensed User
Longtime User
Gesture Rotate Image

Simple Gesture Rotate an Image demo
(2 finger rotate)

Needs Library 2 from first post to work..
 

Attachments

  • Gesture_Rotate_Image.zip
    34.4 KB · Views: 448
Last edited:

vb1992

Well-Known Member
Licensed User
Longtime User
Here is a demo to start a vinyl record music track with two fingers rotate (or fling)

someone else can add a DJ scratch sound if they want
 
Last edited:

vb1992

Well-Known Member
Licensed User
Longtime User
"You can add now an event with the Tab shortcut in the IDE."

cool, is that something special you had to add to make that happen?
or does it do this by default when we make a library
I haven't checked myself
 

Informatix

Expert
Licensed User
Longtime User
"You can add now an event with the Tab shortcut in the IDE."

cool, is that something special you had to add to make that happen?
or does it do this by default when we make a library
I haven't checked myself

You declare the events in the library with @Events. Example:
@Events(values = {
"onTouch(Action As Int, X As Float, Y As Float, MotionEvent As Object)",
"onPointerDown(ptrIndex As Int, PID As Int, MotionEvent As Object)",
"onPointerUp(ptrIndex As Int, PID As Int, MotionEvent As Object)"
})
 

Mrposull

New Member
Licensed User
Longtime User
onUp event

Hi, I'm new to the library and just playing around with it. So far it looks really good but I can't seem to find an 'onUp' event. What am I missing?

Cheers
 

Mrposull

New Member
Licensed User
Longtime User
OK. I have a related question.

After a single-finger touch and release I get the 'onDown' and 'onSingleTapUp' events just fine.

Now if I place a first-finger touch I get an 'onDown' event, a second-finger touch gives an 'onPointerDown' event. Lift the second-finger and I get an 'onPointerUp' event but lifting the first-finger only triggers a 'onTouch' event.

So my question is if I want to know when the first-finger has been lifted I need to use and decode the 'onTouch' event. Is this correct?

Thanks again.
 

FJS

Active Member
Licensed User
Longtime User
Using library in service module

Hello,
Is it possible to use the listener in a service module?
I'm trying to use it in a live wallpaper and Writting
GD.SetOnGestureListener(Service, "Gesture") gives me a compilation error.
Thanks,
FJS
 
Top