Get size of system-font in use

moster67

Expert
Licensed User
Longtime User
The other day I received a report (along with screenshots) from a user saying that certain labels on his Galaxy S3 were truncated or simply did not show up correctly. I found this rather odd since my developer-phone is also a Galaxy S3 and of course I had made sure that everything (my layouts) looked OK, not only on my S3, but also in other resolutions.

First I thought the user might have installed a custom-ROM with different system-fonts but then it struck me the user could have enlarged the system-fonts in the display-settings and indeed he had.

In this specific case, I was able to fix it easily by enlarging the labels but I am wondering if the designer-script and the auto-scale features take into consideration these situations when a user enlarge the system font-size? Any ideas?

If not, is it possible to get the size of the system-font in use? Of course I don't want to override this because if a user has deliberately increased the font-size, there is surely a good reason for it (sight-problems etc) and perhaps we developers should foresee that there can be problems with layouts in these situations and we should adapt our code/design somehow although this might not always be possible (short of screen-space) and in these cases we could launch a messagebox or similar informing the user there might be layout-issues.
 

LucaMs

Expert
Licensed User
Longtime User
This code will take care of Labels, EditText, Buttons, CheckBoxes, RadioBoxes and Spinners:
B4X:
Sub Process_Globals
   Dim access As Accessiblity
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
   ResetUserFontScale(Activity)
End Sub

Sub ResetUserFontScale(p As Panel)
   For Each v As View In p
     If v Is Panel Then
       ResetUserFontScale(v)
     Else If v Is Label Then
       Dim lbl As Label = v
       lbl.TextSize = lbl.TextSize / access.GetUserFontScale
     Else If v Is Spinner Then
       Dim s As Spinner = v
       s.TextSize = s.TextSize / access.GetUserFontScale
     End If
   Next
End Sub


"You" (I mean someone :)) could add the case v is a ListView


P.S. and add a link to this code to the "Code Snippets" forum (many very useful snippets like this are scattered around the site)
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
For ListView you need to do it with
ListView1.SingleLineLayout.Label.TextSize
ListView1.TwoLinesLayout.Label.TextSize
ListView1.TwoLinesLayout.SecondLabel.TextSize
ListView1.TwoLinesAndBitmap.Label.TextSize
ListView1.TwoLinesAndBitmap.SecondLabel.TextSize
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Thanks Klaus and Luca,
Activity.title is still big.
Also I have AHQuickAction menù that is not residez (I know it's obsolete but ..)
 
Last edited:
Upvote 0

leitor79

Active Member
Licensed User
Longtime User
Hello,

Sorry for bumping and old thread, but this is exactly what I'm looking for.

I'm surprised by the sort of agreement with the "fu*k nearsighted people!" solution everyone is talking about. As Erel said, if the user have setted the biggest font, as ugly as everything looks with it, for some major reason he did.

I'm looking for the other solution, the one who adapts the views to the fonts.

I have a sort-of-complex layout; panel at top with subpanels and labels, panel at bottom with subpanels and labels, a customlistview filling the rest of the space with each item having 4 labels. I adjust the size and locations of all the views some at the designer script and some other from the activity code.

Which would be the right approach to adjust the views's sizes according to the defined accesibility?

Regards!
 
Upvote 0

leitor79

Active Member
Licensed User
Longtime User
Hi Erel, Thank you for your answer!

I don't use AddTextItem. I build panels and add them with Add. So, I think I'm stuck with measuring string sizes? Or maybe there are some useful coefficient I could use to increase all labels? ("Label1.Height=Label1.Height*Coefficient", or something like that)

Regards!
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

leitor79

Active Member
Licensed User
Longtime User
Thank you very much, Erel. It was looking at your code where I came with the idea of using a coefficient in the opposite way you've used
access.GetUserFontScale. I'll try it and I'll report.

Regards,
 
Upvote 0

django

Member
Licensed User
Longtime User
I'm looking for the library Accessibility. Can you help me. I have the B4A version 2.22 that does not include this library. Thank you
 
Upvote 0

ginsh

Member
Licensed User
Longtime User
Hi,

I have tried the code but it works fine with Samsung S5 even if I increase the font size on the phone. But when I am testing the same in Samsung S6 it is not working with the normal font size. The text on the buttons are not scaled correctly.

Please anyone help me out.
 

Attachments

  • S5.png
    S5.png
    232.5 KB · Views: 504
  • S6.jpg
    S6.jpg
    23 KB · Views: 499
Upvote 0

texwillerx

Member
Licensed User
Longtime User
Erel, thank you very much for everything you have done.

I just needed such a code, you gave in this thread.

After I used the code, I realized that the code does not work for spinners.

Under debugger, I saw that, the code for panel is executed when the the view is a spinner, and it did nothing since the spinner as a panel does not contain a view.

After I changed the order of the IF statements, the code worked perfectly.

For Each v As View In p
If v Is Spinner Then
Dim sx As Spinner = v
sx.TextSize = sx.TextSize / access.GetUserFontScale​
else If v Is Panel Then
ResetUserFontScale(v)​
Else If v Is Label Then
Dim lbl As Label=v
lbl.TextSize = lbl.TextSize / access.GetUserFontScale​
Else If v Is ListView Then
Dim xx4 As ListView=v
xx4.SingleLineLayout.Label.TextSize = xx4.SingleLineLayout.Label.TextSize / access.GetUserFontScale
xx4.twolinesLayout.Label.TextSize = xx4.twolinesLayout.Label.TextSize / access.GetUserFontScale​
End If
Next

I am not sure if putting the Is panel at the end would be a better solution.
 
Upvote 0

Rody Davis

Member
Licensed User
This code will take care of Labels, EditText, Buttons, CheckBoxes, RadioBoxes and Spinners:
B4X:
Sub Process_Globals
   Dim access As Accessiblity
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
   ResetUserFontScale(Activity)
End Sub

Sub ResetUserFontScale(p As Panel)
   For Each v As View In p
     If v Is Panel Then
       ResetUserFontScale(v)
     Else If v Is Label Then
       Dim lbl As Label = v
       lbl.TextSize = lbl.TextSize / access.GetUserFontScale
     Else If v Is Spinner Then
       Dim s As Spinner = v
       s.TextSize = s.TextSize / access.GetUserFontScale
     End If
   Next
End Sub


This is not working on the Latest B4A. I set the Android Font Size to Maximum and still loads the app with a maximum font size and everything looks bad.
Can you post an updated code set to set the Font Size to Medium?
 
Upvote 0
Top