#Region Project Attributes
#ApplicationLabel: DrawLine_Ex
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
Dim tmr As Timer
Dim blnColourInvert, blnRefresh As Boolean
Dim intStart, intLineWidth As Int
End Sub
Sub Globals
Dim btnStart As Button
Dim btnRefresh As Button
Dim img As ImageView
Dim c As Canvas
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("DrawLine_Ex")
tmr.Initialize("tmr", 250)
c.Initialize(img)
If FirstTime Then blnRefresh = True
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnStart_Click()
c.DrawColor(Colors.Black)
intStart = 0dip
intLineWidth = 5%x
tmr.Enabled = True
End Sub
Sub btnRefresh_Click()
' When set will invalidate the img every tick
blnRefresh = Not(blnRefresh)
End Sub
Sub tmr_Tick()
' Set line colour, alternates between blue and green each tick
Dim intColour As Int
blnColourInvert = Not(blnColourInvert)
If blnColourInvert Then
intColour = Colors.Blue
Else
intColour = Colors.Green
End If
' Draw a vertical line at position intStart
c.DrawLine(intStart,0Dip,intStart,100%y,intColour,intLineWidth)
' Increment start position ready for next Tick
intStart = intStart + intLineWidth
' Check whether to invalidate every tick or when all lines have been drawn
If intStart > img.Width Then
tmr.Enabled = False
img.Invalidate
Else If blnRefresh Then
img.Invalidate
End If
End Sub