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,029
  • Java source - GestureDetector.zip
    5.5 KB · Views: 1,163
Last edited:

Informatix

Expert
Licensed User
Longtime User
I am new to b4a but have a working app for our company. I have not worked on getting Gestures or Gesture_Detector working yet, would it take care of the issue of swiping over a label? We used a label on the activity to display text from a file. Swipe works on the edge (outside the label area) but not over the top of the label (text) itself.
This kind of thing cannot happen with GestureDetector because it is bound to a specific view so if you bind it to your label, you will detect gestures only when they are initiated from the label. As a label is sometimes a bit too small for a good gesture detection, the usual trick is to size it much bigger than needed for display (or to place it in a bigger panel if it has a colored background and detect gestures at the panel level, with no events for the label).
 

herryj

Member
Licensed User
Longtime User
Hi, Informatics
I've tried one of the demo attached in this post "gesture_Rotate_Image.zip" and its awesome, though the image only rotates using two fingers and what I'm searching for is rotate image using one finger.

Is there any Handler on SetOnGestureListener that can rotate image using one finger?

Your response would really help a lot.

And many thanks in advance.

I really really appreciate this library of yours.
 

Informatix

Expert
Licensed User
Longtime User
Hi, Informatics
I've tried one of the demo attached in this post "gesture_Rotate_Image.zip" and its awesome, though the image only rotates using two fingers and what I'm searching for is rotate image using one finger.

Is there any Handler on SetOnGestureListener that can rotate image using one finger?

Your response would really help a lot.

And many thanks in advance.

I really really appreciate this library of yours.
Did you look at this tutorial? It includes some code for rotary knobs.
 

Malky

Active Member
Licensed User
Longtime User
Hi, I am trying to use the swipe (fling) functionality with LibGDX but do not get any response whatsoever with any screen contact? Is there a short demo or something available that I can go through?

Thanks
 

Malky

Active Member
Licensed User
Longtime User
Hi informatix, I tried the suggested function in your libGDX tutorial and got no response which is how I ended up here?
B4X:
Sub GD_Fling(VelocityX As Float, VelocityY As Float) As Boolean
Return False
End Sub
I tried to log the velocity and it appears that this function is not doing anything?
 

Informatix

Expert
Licensed User
Longtime User
Hi informatix, I tried the suggested function in your libGDX tutorial and got no response which is how I ended up here?
B4X:
Sub GD_Fling(VelocityX As Float, VelocityY As Float) As Boolean
Return False
End Sub
I tried to log the velocity and it appears that this function is not doing anything?
You should post in the corresponding thread.
If you open the template "_TemplateInputGD.b4a" and add Log(VelocityX) to the fling event, you will see that you get a value every time you do a fling gesture on the screen.
 

Malky

Active Member
Licensed User
Longtime User
Cheers Informatix, I'll try it tonight when I get home. Apologies for posting here as well.

Malk
 

dune3000

Member
Licensed User
Longtime User
Hi informatix, Can I change the keep touch screen duration for LongPress? I want to make it shorter.
 

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
Is there any simple way to detect when the user swipe its finger from left to right and viceversa?
Thanks
 

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
Thanks Informatix, but this is a very big library and I only need to detect a fling in a CustomListView, any other idea?
 

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
No no I mean the other that is suggested, the one for games.
Iasked for a way to detect a fling, you answer I have to look at the trhead answers and the olnly thing I found is the suggest of a game lib that is too big.
 
Top