B4A Library [Lib] Gesture Detector

zhousongke

Member
Licensed User
.... The onDrag event of GD is not suited for an overlay window so use the method shown in OverlayInfo....
I modified the code of the OverlayWindow class to raise events such as onTouch, onPointerDown, onPointerUp, onDown, onSingleTapUp, onSingleTapConfirmed, onDoubleTap, onShowPress, onLongPress, onDrag, onScroll, onFling, onPinchOpen, onPinchClose, onRotation
, etc. The ScreenX/Y parameter is added to the onTouch and onDrag events. The library, source code, and samples in the attachment.
 

Attachments

Martin D.

Member
Licensed User
How should I transition from a LongPress to "immediately being able to drag" right after the long press ?
The goal is to drag a view towards a new parent after a long press.
 
Last edited:

tufanv

Expert
Licensed User
I have a little problem here. I bind the gesture detector to scrollview. My scrollview has panels like a listview and each have a click eventwhich navigates to another page. I can get swipe msgbox When I swipe scrollview where there is no panel but if there are panels at the area where I swipe, I dont get messages and everytime panel inside the scrollview click event triggers. How can I solve this?
 

frutuopa

Member
Licensed User
Hello ... I've been trying this library and it looks really fantastic .....
I wanted to take advantage of it to create dynamic buttons and be able to drag them over a picture ....

Thanks

Sub Globals
Private pnlFilho2 As Panel
Dim GD As GestureDetector
end sub
Sub Activity_Create(FirstTime As Boolean)

For b=0 To 2

Dim btnDrag As Button
btnDrag.Initialize("btnDrag" & b)

pnlFilho2.AddView(btnDrag,5%x+b*50 , pnlFilho2.Height*0.8, 40dip,40dip)
btnDrag.Text = "B" & (b+1)
btnDrag.TAG = "t" & b
btnDrag.Color=Colors.Yellow
btnDrag.TextColor = Colors.Black

btnDrag.Visible=True
GD.SetOnGestureListener(btnDrag, "Gesture")
Next

end sub

Sub Gesture_onTouch(Action As Int, X As Float, Y As Float, MotionEvent As Object) As Boolean
Log("onTouch action=" & Action & ", x=" & X & ", y=" & Y & ", ev=" & MotionEvent)
Return True
End Sub
Sub Gesture_onDown(X As Float, Y As Float, MotionEvent As Object)
Log(" onDown x = " & X & ", y = " & Y & ", ev = " & MotionEvent)
Log(" pressure = " & GD.getPressure(MotionEvent, 0))
Log(" size = " & GD.getSize(MotionEvent, 0))
End Sub
Sub Gesture_onDrag(deltaX As Float, deltaY As Float, MotionEvent As Object)
Log(" onDrag deltaX = " & deltaX & ", deltaY = " & deltaY & ", ev = " & MotionEvent)
Dim butdrag As Button
butdrag = Sender
Log(butdrag.tag)
butdrag.Left = Max(0, Min(butdrag.Left + deltaX, 100%x - butdrag.Width))
butdrag.Top = Max(0, Min(butdrag.Top + deltaY, 100%y - butdrag.Height))
End Sub
Sub Gesture_onFling(velocityX As Float, velocityY As Float, MotionEvent1 As Object, MotionEvent2 As Object)
Log(" onFling velocityX = " & velocityX & ", velocityY = " & velocityY & ", ev1 = " & MotionEvent1 & ", ev2 = " & MotionEvent2)
End Sub
 

ehsan211

New Member
Hello ... I've been trying this library and it looks really fantastic .....
I wanted to take advantage of it to create dynamic buttons and be able to drag them over a picture ....

Thanks

Sub Globals
Private pnlFilho2 As Panel
Dim GD As GestureDetector
end sub
Sub Activity_Create(FirstTime As Boolean)

For b=0 To 2

Dim btnDrag As Button
btnDrag.Initialize("btnDrag" & b)

pnlFilho2.AddView(btnDrag,5%x+b*50 , pnlFilho2.Height*0.8, 40dip,40dip)
btnDrag.Text = "B" & (b+1)
btnDrag.TAG = "t" & b
btnDrag.Color=Colors.Yellow
btnDrag.TextColor = Colors.Black

btnDrag.Visible=True
GD.SetOnGestureListener(btnDrag, "Gesture")
Next

end sub

Sub Gesture_onTouch(Action As Int, X As Float, Y As Float, MotionEvent As Object) As Boolean
Log("onTouch action=" & Action & ", x=" & X & ", y=" & Y & ", ev=" & MotionEvent)
Return True
End Sub
Sub Gesture_onDown(X As Float, Y As Float, MotionEvent As Object)
Log(" onDown x = " & X & ", y = " & Y & ", ev = " & MotionEvent)
Log(" pressure = " & GD.getPressure(MotionEvent, 0))
Log(" size = " & GD.getSize(MotionEvent, 0))
End Sub
Sub Gesture_onDrag(deltaX As Float, deltaY As Float, MotionEvent As Object)
Log(" onDrag deltaX = " & deltaX & ", deltaY = " & deltaY & ", ev = " & MotionEvent)
Dim butdrag As Button
butdrag = Sender
Log(butdrag.tag)
butdrag.Left = Max(0, Min(butdrag.Left + deltaX, 100%x - butdrag.Width))
butdrag.Top = Max(0, Min(butdrag.Top + deltaY, 100%y - butdrag.Height))
End Sub
Sub Gesture_onFling(velocityX As Float, velocityY As Float, MotionEvent1 As Object, MotionEvent2 As Object)
Log(" onFling velocityX = " & velocityX & ", velocityY = " & velocityY & ", ev1 = " & MotionEvent1 & ", ev2 = " & MotionEvent2)
End Sub
hello . its my question Too . i try different method but cant solve it
 
Top