Android Code Snippet Get panel touch direction

Discussion in 'Code Snippets' started by Douglas Farias, Dec 9, 2017.

  1. Douglas Farias

    Douglas Farias Expert Licensed User

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

    #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)
    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)
    ToastMessageShow("Right to Left",False)
    End If

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


    Attached Files:

    markin.exe, Beja, icarus and 7 others like this.
  2. jimmyF

    jimmyF Active Member Licensed User

    Using it with a multiline EditText and it is perfect for my needs.
    Beja and Douglas Farias like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice