The following code draws a "selection" window when you move the finger:
sx and sy saves the box origin.
Each time the user moves his finger we first erase the previous box and then draw the new one.
Eventually we call Activity.Invalidate to make the activity redraw itself.
B4X:
Sub Globals
Dim Canvas1 As Canvas
Dim Rect1 As Rect
Dim sx, sy As Int
End Sub
Sub Activity_Create(FirstTime As Boolean)
Canvas1.Initialize(Activity)
Rect1.Initialize(0, 0, 0, 0)
End Sub
Sub Activity_Touch (Action As Int, X As Float, Y As Float)
If Action = Activity.ACTION_DOWN Then
sx = X
sy = Y
Else
'Erase previous rectangle
Canvas1.DrawRect(Rect1, Colors.Black, False, 5dip)
If Action = Activity.ACTION_MOVE Then
'Draw the new rectangle
Rect1.Left = Min(sx, X)
Rect1.Right = Max(sx, X)
Rect1.Top = Min(sy, Y)
Rect1.Bottom = Max(sy, Y)
Canvas1.DrawRect(Rect1, Colors.White, False, 5dip)
End If
Activity.Invalidate
End If
End Sub
Each time the user moves his finger we first erase the previous box and then draw the new one.
Eventually we call Activity.Invalidate to make the activity redraw itself.