Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private su As StringUtils
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private cv As Canvas
Private EditText1 As EditText
Private lineHeight,textHeight As Float
Private padY As Int
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("1")
cv.Initialize(EditText1)
EditText1.Text = $"___
____"$
CallSubDelayed(Me, "CalcLineHeight")
CreateLine
End Sub
Sub CalcLineHeight
Dim b As Bitmap = TakeScreenshot
Dim firstLine, secondLine = 1 As Int
For y = 0 To 100dip
Dim c As Int = b.GetPixel(8dip, y)
If c <> 0 And firstLine = 0 Then
firstLine = y
Else if c = 0 And firstLine <> 0 Then
secondLine = 0
Else if secondLine = 0 And c <> 0 Then
secondLine = y
Exit
End If
Next
lineHeight = secondLine - firstLine
padY = firstLine - lineHeight
Log(lineHeight)
CreateLine
End Sub
Sub TakeScreenshot As Bitmap
Dim Obj1, Obj2 As Reflector
Dim bmp As Bitmap
Dim c As Canvas
Obj1.Target = EditText1
bmp.InitializeMutable(EditText1.Width, EditText1.Height)
c.Initialize2(bmp)
Dim args(1) As Object
Dim types(1) As String
Obj2.Target = c
Obj2.Target = Obj2.GetField("canvas")
args(0) = Obj2.Target
types(0) = "android.graphics.Canvas"
Obj1.RunMethod4("draw", args, types)
Return bmp
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Private Sub CreateLine
Dim i As Float
For i = padY To EditText1.Height Step lineHeight
cv.DrawLine(5dip, lineHeight + i, EditText1.Width - 5dip, lineHeight + i, Colors.Gray, 1dip)
Next
End Sub