hello i need to detect finger swipe to right left down and up. Is it possible with b4i ?
Ty
Sub Process_Globals
'These global variables will be declared once when the application starts.
'....
Dim startx As Float
Dim starty As Float
End Sub
'......
Sub Panel1_Touch(Action As Int, X As Float, Y As Float)
Select Action
Case Panel1.ACTION_DOWN
startx = X
starty = Y
Case Panel1.ACTION_MOVE
Log("moving")
Case Panel1.ACTION_UP
If Abs(Y - starty) > 20%y Then Return
If X - startx > 30%x Then 'right
Msgbox("Moved to the right","")
Else If startx - X > 30%x Then ' left
Msgbox("Moved to the left","")
End If
End Select
End Sub
try this ( i have not checked it out, it may work)
B4X:Sub Process_Globals 'These global variables will be declared once when the application starts. '.... Dim startx As Float Dim starty As Float End Sub '...... Sub Panel1_Touch(Action As Int, X As Float, Y As Float) Select Action Case Panel1.ACTION_DOWN startx = X starty = Y Case Panel1.ACTION_MOVE Log("moving") Case Panel1.ACTION_UP If Abs(Y - starty) > 20%y Then Return If X - startx > 30%x Then 'right Msgbox("Moved to the right","") Else If startx - X > 30%x Then ' left Msgbox("Moved to the left","") End If End Select End Sub
try this ( i have not checked it out, it may work)
B4X:Sub Process_Globals 'These global variables will be declared once when the application starts. '.... Dim startx As Float Dim starty As Float End Sub '...... Sub Panel1_Touch(Action As Int, X As Float, Y As Float) Select Action Case Panel1.ACTION_DOWN startx = X starty = Y Case Panel1.ACTION_MOVE Log("moving") Case Panel1.ACTION_UP If Abs(Y - starty) > 20%y Then Return If X - startx > 30%x Then 'right Msgbox("Moved to the right","") Else If startx - X > 30%x Then ' left Msgbox("Moved to the left","") End If End Select End Sub
maybe it works like this?
B4X:If x>startx and X - startx > 30%x Then 'right Msgbox("Moved to the right","") Else If x<startx and startx - X > 30%x Then ' left Msgbox("Moved to the left","") End If
I tried ilans' code.
The principle is OK but sometimes it doesn't wotk properly, it seems that the Msgbox method introduces some trouble.
Replace the MsgBox lines by Log and it works properly.
You might perhaps reduce the 30%x value.
The principle is OK
If x>startx Then 'right
Msgbox("Moved to the right","")
Else If x<startx Then ' left
Msgbox("Moved to the left","")
End If
I tried ilans' code.
The principle is OK but sometimes it doesn't wotk properly, it seems that the Msgbox method introduces some trouble.
Replace the MsgBox lines by Log and it works properly.
You might perhaps reduce the 30%x value.
Private Sub pnlPage1_Touch(Action As Int, X As Float, Y As Float)
Select Action
Case pnlPage1.ACTION_DOWN
startx = X
starty = Y
Case pnlPage1.ACTION_MOVE
' Log("moving")
Case pnlPage1.ACTION_UP
If Abs(Y - starty) > 20%y Then Return
If X - startx > 20%x Then 'right
Log("Moved to the right")
Else If startx - X > 20%x Then ' left
Log("Moved to the left")
End If
End Select
End Sub
try this
B4X:'.... If X - startx > 20%x Then Msgbox("Moved to the right","") 'right If startx - X > 20%x Then Msgbox("Moved to the left","") ' left '...
try the code I added in my previous post
maybe it works like this?
B4X:If x>startx and X - startx > 30%x Then 'right Msgbox("Moved to the right","") Else If x<startx and startx - X > 30%x Then ' left Msgbox("Moved to the left","") End If
If you look carefully at the code you'll see that once it is:
X - startx
and in the second it is:
startx - X
X - startx is positive for a right swipe and negative for a left swipe
startx - X is positive for a left swipe and negative for a right swipe
This code works, I tested it before posting !
B4X:Private Sub pnlPage1_Touch(Action As Int, X As Float, Y As Float) Select Action Case pnlPage1.ACTION_DOWN startx = X starty = Y Case pnlPage1.ACTION_MOVE ' Log("moving") Case pnlPage1.ACTION_UP If Abs(Y - starty) > 20%y Then Return If X - startx > 20%x Then 'right Log("Moved to the right") Else If startx - X > 20%x Then ' left Log("Moved to the left") End If End Select End Sub
Logs:
Application_Start
Application_Active
Moved to the right
Moved to the left
Moved to the right
Moved to the left
Moved to the right
If you look carefully at the code you'll see that once it is:
X - startx
and in the second it is:
startx - X
X - startx is positive for a right swipe and negative for a left swipe
startx - X is positive for a left swipe and negative for a right swipe
This code works, I tested it before posting !
B4X:Private Sub pnlPage1_Touch(Action As Int, X As Float, Y As Float) Select Action Case pnlPage1.ACTION_DOWN startx = X starty = Y Case pnlPage1.ACTION_MOVE ' Log("moving") Case pnlPage1.ACTION_UP If Abs(Y - starty) > 20%y Then Return If X - startx > 20%x Then 'right Log("Moved to the right") Else If startx - X > 20%x Then ' left Log("Moved to the left") End If End Select End Sub
Logs:
Application_Start
Application_Active
Moved to the right
Moved to the left
Moved to the right
Moved to the left
Moved to the right
this workd fine now thank you. I was using dim startx and starty in panel panel touch event , when i moved it to globals it is fixed . Thank you all for the help !
maybe it works like this?
B4X:If x>startx and X - startx > 30%x Then 'right Msgbox("Moved to the right","") Else If x<startx and startx - X > 30%x Then ' left Msgbox("Moved to the left","") End If
X - startx is positive for a right swipe and negative for a left swipe
startx - X is positive for a left swipe and negative for a right swipe