Sub Class_Globals
...
Private DownX, DownY As Double, Dragging As Boolean, DraggingStart As Long
Private GridSize As Int = 5dip
End Sub
#if B4A
Private Sub mRoot_Touch (o As Object, ACTION As Int, x As Float, y As Float, motion As Object) As Boolean
#else
Private Sub mRoot_Touch (Action As Int, X As Float, Y As Float)
#end if
If Action = mRoot.TOUCH_ACTION_DOWN Then
Dragging = True
DraggingStart = DateTime.Now
DownX = X
DownY = Y
Else If Action = mRoot.TOUCH_ACTION_UP Then
Dragging = False
#if B4A
If (DateTime.Now - DraggingStart) > 500 Then
mRoot_LongClick
Else
mRoot_Click
End If
#end if
Else If Dragging And Action = mRoot.TOUCH_ACTION_MOVE Then
mRoot.Left = Max(0, Min(mRoot.Parent.Width - mRoot.Width, ApplyGrid(mRoot.Left + X - DownX)))
mRoot.Top = Max(0, Min(mRoot.Parent.Height - mRoot.Height, ApplyGrid(mRoot.Top + Y - DownY)))
End If
#if B4A
Return True
#end if
End Sub
Private Sub ApplyGrid (x As Int) As Int
If GridSize > 0 Then
Return x - (x Mod GridSize)
End If
Return x
End Sub