Android Question Does B4X have any native function to detect touch swiping motion?

rtek1000

Active Member
Licensed User
Longtime User
I made use of Gestures (multi-touch), but if B4X has something native, I would like to try it.

B4X:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region

'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip

Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private Panel1 As Panel
    Dim G As Gestures
    Dim G_X As Int
    Dim G_Y As Int
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
  
    G.SetOnTouchListener(Panel1, "Gestures_Touch")
End Sub

Private Sub Gestures_Touch(View As Object, PointerID As Int, Action As Int, X As Float, Y As Float) As Boolean
    'Log("X: " & X & " Y: " & Y & " Action: " & Action)
  
    If Action = g.ACTION_DOWN Or Action = g.ACTION_POINTER_DOWN Then
        Log("ACTION_DOWN")
        G_X = X
        G_Y = Y
    Else If Action = g.ACTION_UP Or Action = g.ACTION_POINTER_UP Then
        Dim no_slide As Boolean = False
      
        If X > (G_X + 25%x) Then
            Log("SLIDE_LEFT_RIGHT")
        Else If X < (G_X - 25%x) Then
            Log("SLIDE_RIGHT_LEFT")
        Else
            no_slide = True
        End If
      
        If Y > (G_Y + 25%x) Then
            Log("SLIDE_UP_DOWN")
        Else If Y < (G_Y - 25%x) Then
            Log("SLIDE_DOWN_UP")
        Else
            no_slide = True
        End If
      
        If no_slide = True Then
            Select Action
                Case g.ACTION_MOVE
                    Log("ACTION_MOVE")
                Case g.ACTION_POINTER_DOWN
                    Log("ACTION_POINTER_DOWN")
                Case g.ACTION_POINTER_UP
                    Log("ACTION_POINTER_UP")
                Case g.ACTION_UP
                    Log("ACTION_UP")
            End Select
        End If
    End If

    Return True
End Sub
 
Last edited:
Top