B4A Library [Lib] Gesture Detector

jazzzzzzz

Active Member
Licensed User
Longtime User
How can I detect draging up,down,left,right ?

What i need is that, in onDrag example I need to drag the ball up,down,right,left only (like a joystick that goes like a + symbol only) .

How can i achieve it?
 

jazzzzzzz

Active Member
Licensed User
Longtime User
By checking the direction of the move (the sign).
How can i get direction?

B4X:
Sub Gesture_onDrag(deltaX As Float, deltaY As Float, MotionEvent As Object)
    likeBt.Top = Max(25%y+(actionBar.Height/2), Min(likeBt.Top + deltaY, 75%y+(actionBar.Height/2) - likeBt.Height))
End Sub

Sub Gesture_onTouch(Action As Int, X As Float, Y As Float, MotionEvent As Object) As Boolean
    Select Action
        Case Activity.ACTION_DOWN
            'Log("Action Down")
          
        Case Activity.ACTION_UP
            'Log("Action Up")
            If likeBt.Top <> 25%y+(actionBar.Height/2) Or likeBt.Top <> 75%y+(actionBar.Height/2)-likeBt.Height Then
                likeBt.Top = 50%y+(actionBar.Height/2)- 25dip
            End If
          
    End Select
  
    Return True
End Sub

this is my current snippet

this works for vertical direction only
 

Informatix

Expert
Licensed User
Longtime User
Check the sign of DeltaX and DeltaY and the relative value of DeltaX (horizontal) to the value of DeltaY (vertical).
 

LucaMs

Expert
Licensed User
Longtime User
I tried the example Drag. Performing sequential rotation and dragging a couple of times, the rectangle flits wherever it wants .

Why?

Thank you.
 

Attachments

  • GestureDetector_Drag_With_Rotation.zip
    6.6 KB · Views: 325

Inman

Well-Known Member
Licensed User
Longtime User
I am testing OnDrag event and it works great. But at the end of the drag, how can I detect when the user lifts his finger off the screen so that I can "drop" the view back to its initial position? With OnTouch?
 

Informatix

Expert
Licensed User
Longtime User
3 = Cancel. The touch event is cancelled by one of the activity views that catches this event.
 

ELCHARO

Member
Licensed User
Longtime User
Hello.
The lib have a function to pass touch events like
B4X:
GD_Green.PassTouchEventTo(MotionEvent, pnlRed)

are a way to pass event like

B4X:
Gesture_onScroll(distanceX As Float, distanceY As Float, MotionEvent1 As Object, MotionEvent2 As Object)

The idea is intercept vertical swipes and pass de horizontal events.
A problem than i don't know how to resolve.

Regards.
 

ykucuk

Well-Known Member
Licensed User
Longtime User
Hello,

I added imageview into panel and trying resize and rotate image with pinch on runtime.

I have 2 problems

1- Too Slowly. Users wait 1 second after each pinch action.
2-Panel can rotate but Imageview in panel doesnt rotate with panel. How to rotate imageview as panel

Need help.

My code : www.amerikaileticaretyapin.com/pinch.zip
 
Last edited:

Alexander Stolte

Expert
Licensed User
Longtime User
1- Too Slowly. Users wait 1 second after each pinch action.

Test it on Release. On my Samsung S7 Edge i have no delay from 1 second.

2-Panel can rotate but Imageview in panel doesnt rotate with panel. How to rotate imageview as panel

set:
B4X:
pnlTwoFingers.AddView(img, 0, 0, 100%x, 100%x)
 

Alexander Stolte

Expert
Licensed User
Longtime User
are a way to pass event like
Do you mean something like that?

B4X:
Sub Globals
      Private pnl_back As Panel
    Dim GD As GestureDetector    
End Sub

Sub Gesture_onDrag(deltaX As Float, deltaY As Float, MotionEvent As Object)   
    pnl_back.Top = Max(0, Min(pnl_back.Top + deltaY, 100%y - pnl_back.Height))
End Sub

if you press on your view and wish up or down, your view follow your finger.
 

Informatix

Expert
Licensed User
Longtime User
2-Panel can rotate but Imageview in panel doesnt rotate with panel. How to rotate imageview as panel
Your code does not rotate anything except a text drawn on a canvas, so the result is not surprising.
You have to use a library like NineOldAndroids that allows to rotate views.

Are you sure that your need is not already satisfied by an existing library (e.g. TouchImageView or PinchZoomAndMove)?
 

ykucuk

Well-Known Member
Licensed User
Longtime User

Hello,

Im not sure. ı need drag few images on activity and pinch them on runtime. I thought this library best for this.

am i wrong ?
 

ykucuk

Well-Known Member
Licensed User
Longtime User
Test it on Release. On my Samsung S7 Edge i have no delay from 1 second.



set:
B4X:
pnlTwoFingers.AddView(img, 0, 0, 100%x, 100%x)

1-It works great with release mode.
2- it doesnt help.
B4X:
pnlTwoFingers.AddView(img, 0, 0, 100%x, 100%x)

thank you
 

mkh_fx

Member
Licensed User
Longtime User
how to use this library for google map
i want to detect touch actions on the map by this library
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…