Android Code Snippet Get panel touch direction

Hi All.
here is a very very simple code to get the slide direction on a panel.
(Right, Left, Top, Down)


B4X:
#Region  Project Attributes
    #ApplicationLabel: Slide Direction Example
    #VersionCode: 1
    #VersionName: 1.0
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
End Sub

Sub Globals
    Private pCamera As Panel
    Private distanciaMinima As Int = 150
    Private x1,x2,y1,y2 As Float
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub pCamera_Click
    
End Sub

Sub pCamera_Touch (Action As Int, X As Float, Y As Float)
    Select Action
        
        Case Activity.ACTION_DOWN
            x1 = x
            y1 = y
        Case Activity.ACTION_UP
            x2 = x
            y2 = y
            Private deltaX As Float = x2 - x1
            Private deltaY As Float = y2 - y1
            
            If Abs(deltaX) > distanciaMinima Then
                If x2 > x1 Then
                    ToastMessageShow("Left to Right",False)
                Else
                    ToastMessageShow("Right to Left",False)
                End If

            else If Abs(deltaY) > distanciaMinima Then
                If y2 > y1 Then
                    ToastMessageShow("Top to Down",False)
                Else
                    ToastMessageShow("Down to Top",False)
                End If
            
            End If
            
            
            
            
    End Select
End Sub


thx
 

Attachments

  • position.zip
    39.7 KB · Views: 555

jimmyF

Active Member
Licensed User
Longtime User
Using it with a multiline EditText and it is perfect for my needs.
 
Top