Detect movement of swipe

fatman

Active Member
Licensed User
Longtime User
Hi Folks,

i spent hours searching the forum trying out Agrahams gestures library but failed.:BangHead:
My problem is:
I have a panel and all i want to know is if the user moved the finger on this panel from the left to the right and vice versa.
I dont need coordinates etc i just need the information at the end of the swipe in what direction the movement was done.

Maybe someone else encountered the same problem.

Thanks

Fatman
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here:
B4X:
Sub Process_Globals
   Dim MOVEMENT_THRESHOLD As Int
   MOVEMENT_THRESHOLD = 100dip
End Sub

Sub Globals
   Dim Panel1 As Panel
   Dim StartX As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Panel1.Initialize("Panel1")
   Activity.AddView(Panel1, 0, 0, 100%x, 100%y)
End Sub

Sub Panel1_Touch (Action As Int, X As Float, Y As Float) As Boolean 'Return True to consume the event
   Select Action
      Case Activity.ACTION_DOWN
         StartX = X
      Case Activity.ACTION_UP
         If Abs(X - StartX) > MOVEMENT_THRESHOLD Then
            Swipe(X < StartX)
         End If
   End Select
   Return True      
End Sub

Sub Swipe(Left As Boolean)
   If Left Then Msgbox("Left", "") Else Msgbox("Right", "")
End Sub
 
Upvote 0

dbryan

Member
Licensed User
Longtime User
I know this is old but how about doing it at the activity level and determine what was touched?
 
Upvote 0

enginet

Member
Licensed User
Longtime User
What do you mean with: "what was touched"?

You can add the panel over the whole activity.

If i add the panel over the whole activity, i can't access the underground layer.
For example, if i have a webview and i put a panel over it, i can't click any link on the webpage cause the panel is blocking all the touch.
 
Upvote 0
Top