Having a problem with this on a phone that has access.GetUserFontScale (Accessibility) set to a higher value (in this case 1.5).
The measured height is too large and multiplying that by 1 / access.GetUserFontScale makes it smaller but the value is still too high.
This is the code I have to measure the text height of the BBCodeView:
This is the code text I am testing with, with the produced log values.
Any idea what I may be doing wrong?
RBS
The measured height is too large and multiplying that by 1 / access.GetUserFontScale makes it smaller but the value is still too high.
This is the code I have to measure the text height of the BBCodeView:
B4X:
Public Sub MeasureTextHeightBBCodeView(vParent As B4XView, _
strCodeText As String, _
iWidth As Int, _
fTextSize2 As Float, _
arrPadding() As Int) As Int
'Note fTextSize is not used in this Sub
Dim iMaxDialogHeight As Int = vParent.Height - 144dip
Dim TextEngine As BCTextEngine
Dim iContentHeight As Int
Dim rectPadding As B4XRect
Log(strCodeText)
'-----------------------------------------------------------------------------------------
'note that is the same layout that will be used to show the actual final text
'it will be removed first after getting the content height and will then be reloaded later
'-----------------------------------------------------------------------------------------
vParent.LoadLayout("Dialog_bcte")
'bbcvPrompt is private module level variable (in B4XMainPage)
bbcvPrompt.mBase.Width = iWidth
TextEngine.Initialize(vParent)
bbcvPrompt.TextEngine = TextEngine
rectPadding.Initialize(arrPadding(0), arrPadding(1), arrPadding(2), arrPadding(3))
bbcvPrompt.Padding = rectPadding
bbcvPrompt.LazyLoading = True 'but already set so in the designer
bbcvPrompt.Text = strCodeText
If bbcvPrompt.Paragraph.IsInitialized Then
iContentHeight = bbcvPrompt.Paragraph.Height / TextEngine.mScale + bbcvPrompt.Padding.Top + bbcvPrompt.Padding.Bottom' + iDoubleLineBreaks * fTextSize
End If
Log("MeasureTextHeightBBCodeView, bbcvPrompt.Paragraph.Height: " & bbcvPrompt.Paragraph.Height)
Log("MeasureTextHeightBBCodeView, TextEngine.mScale: " & TextEngine.mScale)
Log("MeasureTextHeightBBCodeView, bbcvPrompt.Padding.Top: " & bbcvPrompt.Padding.Top)
Log("MeasureTextHeightBBCodeView, bbcvPrompt.Padding.Bottom: " & bbcvPrompt.Padding.Bottom)
Log("MeasureTextHeightBBCodeView, iContentHeight: " & iContentHeight)
bbcvPrompt.Paragraph.TextLines.Clear '?clear memory
'all these are on the layout dialog_bcte and will need removing
imgIcon.RemoveViewFromParent
bbcvPrompt.mBase.RemoveViewFromParent
lblTitle.RemoveViewFromParent
edtInput.RemoveViewFromParent
Private bbcvPrompt As BBCodeView '?clear memory, not sure what difference there is to declare here with Dim or Private
'Log("MeasureTextHeightBBCodeView, iContentHeight: " & iContentHeight)
If iContentHeight > iMaxDialogHeight Then
iContentHeight = iMaxDialogHeight
End If
Return iContentHeight
End Sub
This is the code text I am testing with, with the produced log values.
B4X:
[Span MinWidth=40%x][color=#000000]Max Memory[/color][/Span][Span MinWidth=59%x][color=#000000]256 Mb[/color][/Span]
[Span MinWidth=40%x][color=#000000]Total Free[/color][/Span][Span MinWidth=59%x][color=#000000]241.7 Mb[/color][/Span]
[Span MinWidth=40%x][color=#000000]Total Memory[/color][/Span][Span MinWidth=59%x][color=#000000]28.5 Mb[/color][/Span]
[Span MinWidth=40%x][color=#000000]Used Memory[/color][/Span][Span MinWidth=59%x][color=#000000]14.3 Mb[/color][/Span]
[Span MinWidth=40%x][color=#000000]Free Memory[/color][/Span][Span MinWidth=59%x][color=#000000]14.2 Mb[/color][/Span]
MeasureTextHeightBBCodeView, bbcvPrompt.Paragraph.Height: 740
MeasureTextHeightBBCodeView, TextEngine.mScale: 1
MeasureTextHeightBBCodeView, bbcvPrompt.Padding.Top: 18
MeasureTextHeightBBCodeView, bbcvPrompt.Padding.Bottom: 18
MeasureTextHeightBBCodeView, iContentHeight: 776
Any idea what I may be doing wrong?
RBS