Hi all,
I use canvas to drawtext on a imageview in my widget. The problem is, if I set the text to draw as a fixed one, e.g "A", it works. But if I set the text to draw as a variable, when I add the widget to homescreen, I may or may not display the text. Below is the code and screenshoot. The screenshoot is when I continuously add 4 widgets. 2 of them show the text and 2 doesn't.
I use canvas to drawtext on a imageview in my widget. The problem is, if I set the text to draw as a fixed one, e.g "A", it works. But if I set the text to draw as a variable, when I add the widget to homescreen, I may or may not display the text. Below is the code and screenshoot. The screenshoot is when I continuously add 4 widgets. 2 of them show the text and 2 doesn't.
B4X:
Sub rv_RequestUpdate
DateTime.DateFormat = "dd.MM.yyyy"
Dim header As String = DateTime.date(DateTime.Now)
Dim day As Int= DateTime.GetDayOfWeek(DateTime.Now)
If day = 1 Then header = "Sun, " & header
If day = 2 Then header = "Mon, " & header
If day = 3 Then header = "Tue, " & header
If day = 4 Then header = "Wed, " & header
If day = 5 Then header = "Thu, " & header
If day = 6 Then header = "Fri, " & header
If day = 7 Then header = "Sat, " & header
rv.SetImage("Header",CommonCode.DrawFont(header,"Header"))
rv.UpdateWidget
End Sub
B4X:
Sub DrawFont(MyText As String, Target As String) As Bitmap
Dim Font As Typeface
Dim Canvas As Canvas
Dim imgCC As Bitmap
If Target = "Header" Then
Font = Typeface.LoadFromAssets("CORSIVA.ttf")
imgCC.InitializeMutable(146dip,30dip) 'sample size
Canvas.Initialize2(imgCC)
Canvas.DrawText(MyText, 73dip, 28dip, Font, 20, Colors.White, "CENTER")
End If
Return Canvas.Bitmap
End Sub