Android Question Gesture Detector : allow Drag after LongPress without having to release touch ?

Blueforcer

Well-Known Member
Licensed User
Longtime User
This is how i have done this.
Just set a variable if you longpress and ignore the touchevent if false



B4X:
Sub view_onLongPress(X As Float, Y As Float, MotionEvent As Object)
    If Not(Ready2Move) Then
        ShakeView(mBase,50)
        Ready2Move=True
        dragPanel.Visible=True
        mBase.BringToFront
   End If
End Sub

Sub view_onTouch(Action As Int, X As Float, Y As Float, MotionEvent As Object)
    If Ready2Move=False Then Return
    Select Action
        Case 0 ' DOWN
            ' We memorize the starting position
            StartX = X
            StartY = Y
        Case 2 ' MOVE
            mBase.Left = Max(MarginStillVisible - mBase.Width, _
                                        Min(mBase.Left + X - StartX, 100%x - MarginStillVisible))
            mBase.Top = Max(MarginStillVisible - mBase.Height, _
                                        Min(mBase.Top + Y - StartY, 100%y - MarginStillVisible))
    End Select
End Sub

Private Sub ExitDrag_Click
    Ready2Move=False
    dragPanel.Visible=False
    ShakeView2(mBase,500)
End Sub

Sub ShakeView (View As B4XView, Duration As Int)
    For i = 1 To 5
        View.SetRotationAnimated(Duration,2)
        Sleep(Duration)
        View.SetRotationAnimated(Duration,-2)
        Sleep(Duration)
    Next
    View.SetRotationAnimated(Duration,0)
End Sub

Sub ShakeView2 (View As B4XView, Duration As Int)
    Dim Left As Int = View.Left
    Dim Delta As Int = 10dip
    For i = 1 To 4
        View.SetLayoutAnimated(Duration / 5, Left + Delta, View.Top, View.Width, View.Height)
        Delta = -Delta
        Sleep(Duration / 5)
    Next
    View.SetLayoutAnimated(Duration/5, Left, View.Top, View.Width, View.Height)
End Sub
 
Last edited:
Upvote 0
Top