Sub Activity_Create(FirstTime As Boolean)
...
'Speedpilot initiallisieren
CallSubDelayed(Me, "InitSpeedpilot")
...
End Sub
'The label "lblSettingSpeed" is initialized in the designer.
Private Sub InitSpeedpilot
mBBL.SetTextSize(lblSettingSpeed, "000.00", 1, True)
End Sub
'Modul mBBL
'Der Parameter "Scale" bei Buttons nicht verwendet!
Sub SetTextSize(obj As View, txt As String, scale As Float, singleline As Boolean)
Dim cv As Canvas
'Log("SetTextSize: txt=" & txt & " :obj=" & obj)
setSingleLine(obj, singleline)
If obj Is Button Then
Dim btn As Button = obj
cv.Initialize(btn)
SetButtonTextSize(btn, txt, cv)
Else
Dim lbl As Label = obj
cv.Initialize(lbl)
SetLabelTextSize(lbl, txt, scale, cv)
End If
End Sub
'Sets the TextView to single line
Public Sub setSingleLine(TextView As View, SingleLine As Boolean)
Dim jo = TextView As JavaObject
jo.RunMethod("setSingleLine", Array As Object(SingleLine))
End Sub
Private Sub SetButtonTextSize(btn As Button, txt As String, cv As Canvas)
Dim stu As StringUtils
Dim dt As Float
Dim h, Height As Int
Dim w, Width As Int
Height = btn.Height - 14dip
Width = btn.Width
btn.Text = txt
btn.TextSize = 6
dt = btn.TextSize
h = stu.MeasureMultilineTextHeight(btn, txt)
w = MeasureStringWidth(btn, dt, cv)
Do While h <= Height
dt = dt + 2
btn.TextSize = dt
h = stu.MeasureMultilineTextHeight(btn, txt)
w = MeasureStringWidth(btn, dt, cv)
If w >= (Width - 10dip) Or h > Height Then
btn.TextSize = dt - 2
Exit
End If
Loop
End Sub
Private Sub SetLabelTextSize(lbl As Label, txt As String, scale As Float, cv As Canvas)
Dim stu As StringUtils
Dim dt As Float
Dim h, Height As Int
Dim w, Width As Int
Height = lbl.Height * scale
Width = lbl.Width
'WICHTIG! Die Width darf nicht weniger als null sein!
If lbl.Width < 0 Then Return
lbl.Text = txt
lbl.TextSize = 6
dt = lbl.TextSize
h = stu.MeasureMultilineTextHeight(lbl, txt)
w = MeasureStringWidth(lbl, dt, cv)
Do While h <= Height
dt = dt + 2
lbl.TextSize = dt
h = stu.MeasureMultilineTextHeight(lbl, txt)
w = MeasureStringWidth(lbl, dt, cv)
If w >= (Width - 10dip) Or h > Height Then
lbl.TextSize = dt - 2
Exit
End If
Loop
End Sub
Private Sub MeasureStringWidth(obj As View, TextSize As Float, cv As Canvas) As Float
If obj Is Button Then
Dim btn As Button = obj
Return cv.MeasureStringWidth(btn.Text, btn.Typeface, TextSize)
Else
Dim lbl As Label = obj
Return cv.MeasureStringWidth(lbl.Text, lbl.Typeface, TextSize)
End If
End Sub