Display problems on high res devices

Status
Not open for further replies.

hackhack

Active Member
Licensed User
Longtime User
I asked about this elsewhere, but since erel didn't know the answer I'm opening this thread more as a research thread - perhaps someone has an idea.

Originally I asked about Sense 4 (the skin on HTC's new devices), but since resolutions keep going up perhaps this shows up on other devices as well (has anyone tried?)

In the HTC display setups there is a setting called "Font Size", it has 4 choices "Small","Medium","Large","Extra Large". Setting this will then rescale the sense interface and HTC apps - which is handy since resolutions keep going up.

However many, if not most, apps just ignore this setting (and since many don't allow the user to set font size I now need a magnifying glass)

But the B4A apps are also affected by this setting (unless I'm doing something very stupid, in which case please tell me gently :) )

So I tried a test, 4 labels on a panel, with this in Activity_Create

B4X:
   Activity.LoadLayout("default")
   Label1.TextSize=30
   Label2.TextSize=30
   Label3.TextSize=30
   Label4.TextSize=30

And this in Activity_Resume

B4X:
   Label1.Text=Label1.TextSize & "(" & Activity.Width & ")"
   Label1.Typeface=Typeface.DEFAULT

   Label2.Text=Label2.TextSize & "(" & Activity.Height & ")"
   Label2.Typeface=Typeface.SANS_SERIF

   Label3.Text=Label3.TextSize & "(" & Label3.Height & ")"
   Label3.Typeface=Typeface.SERIF

   Label4.Text=Label4.TextSize & "(" & Label3.Width & ")"
   Label4.Typeface=Typeface.MONOSPACE

Sense supports screen capture, so I took a screen cap at each of the 4 settings. This is the same apk just run 4 times.


If someone has suggestions I'm sure I'm not the only one who'd like to hear it :)
 

Attachments

  • 1.small.png
    1.small.png
    29.1 KB · Views: 328
  • 2.medium.png
    2.medium.png
    31.8 KB · Views: 315
  • 3. large.png
    3. large.png
    34.3 KB · Views: 297
  • 4. extra large.png
    4. extra large.png
    34 KB · Views: 284
Last edited:

Inman

Well-Known Member
Licensed User
Longtime User
After assigning text to labels, you can use StringUtils.MeasureMultilineTextHeight to find the minimum height required to show the text on the label without getting cutoff. Canvas object also has something similar, along with MeasureStringWidth but I am not sure if it works with labels as I haven't used it yet.

Another thing you could try is to enable SetEllipsize property of the label, using Reflection library, so that when the text is too wide to fit in a label, it gets truncated with a "..." in the end.
 
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
After assigning text to labels, you can use StringUtils.MeasureMultilineTextHeight to find the minimum height required to show the text on the label without getting cutoff.

Ok, that does return different values, so we are not quite in the dark here.
Though its not very efficient if we are going to have to test each font size until finding one that will display correctly. (Does 20 fit? No, ok does 21 fit? No, ok does 22 fit? No, ok does..... 50 fit? No, ok does 51 fit..)


Canvas object also has something similar


Would be a real bummer if everything now has to be drawn on canvases, sort of makes the visual layout irrelevant.

, along with MeasureStringWidth but I am not sure if it works with labels as I haven't used it yet.

What is that in? (Yes, I tried to search, but you can't search documentation only so get a ton of guff from the forums)

Another thing you could try is to enable SetEllipsize property of the label, using Reflection library, so that when the text is too wide to fit in a label, it gets truncated with a "..." in the end.

Haven't tried that yet, but will now - just to test - its not really acceptable that text is not displayed when it needs to be.

Oh thanks for your ideas :)
 
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
Yes, SetEllipsize works.

Now would be handy if one could get a return value indicating if it was needed or not, so you could run through font sizes to a useable value. (Or indeed a way to overrule the font scaling)
 
Upvote 0

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Canvas object is just used to get the measurements, it is not needed for drawing the text. Might be a way to override it by some type of formula- Something like getting the DPI ratio and figuring with a monospaced/fixed width char and figuring how many pixels it takes and if not the same use the difference as a ratio applied to your text sizes. The new classes would probably help in making a class that you call to create your labels the way you want. I'm doing something similar for Edit Text views right now...might expand it to other controls soon as needed for things such as this and other missing functionality. I'll post the Class later when I finish tweaking, testing, and debugging.

P.S. The Yay smiley drives me nuts too...
 
Upvote 0

WizardOz

Member
Licensed User
Longtime User
Roger: I would also love to have a look on that Class! :sign0098:

+1 on the Yay's btw ;)
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You can get the user font scale using this code which requires the reflection library.

B4X:
Dim R As Reflector
Dim S As Float
      
R.Target = R.GetContext
R.Target = R.RunMethod("getResources")
R.Target=R.RunMethod("getConfiguration")
S= R.GetField("fontScale")

It returns 1 on my phone, but I cant find an option to change it. It may let you know if the user has changed the size at least.

Documentation is here if it helps.
 
Last edited:
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
You can get the user font scale using this code which requires the reflection library.

B4X:
 snip

It returns 1 on my phone, but I cant find an option to change it. It may let you know if the user has changed the size at least.

Aha, now this produces something. On the HTC One S (may be different on One X/V):

On small fontscale is 0.8500000238418579
On medium fontscale is 1
On Large fontscale is 1.149999976158142
On Extra Large fontscale is 1.2999999523162842

I guess now something can be calculated
 
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
Found an App called Big Font which allowed me to change this. Didn't require root, so must be possible somehow. I'll have to use this somehow in my calculations now since it also enlarges EditText Fonts.

I just looked at that - its nice as a preference, but in general I don't think an app should mess with the users global font settings :)
 
Upvote 0

Roger Garstang

Well-Known Member
Licensed User
Longtime User
It was mostly so I could test. I got the same values as you did above when I changed font size with it. It also sets some kind of an ignore list...if that is standard it would be nice to know how to use that to set an app to be ignored and not have fonts adjust instead of having to apply a ratio to everything using text. My Galaxy Note has Accessibility options to change font size, but they don't do anything.
 
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
Ok, i think this is a function of ICS and not Sense as i originally though.

The Asus Transformer has the same 4 settings, but they use different names ("Small","Normal","Large","Huge")

But the scaling values provided by the "fontScale" method are the same as on the One S (Even though they have different resolutions)
 
Last edited:
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
So basing it on the above, doing this:

Label1.TextSize=<MyTextSize>/fontScale

Will make the text remain at the same size, regardless of what the user set in ICS display options (of course if that makes the text unreadable to the user they are not going to love you much). Under ICS at least. Not sure what happens in older versions.
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
From the documentation, fontscale has been available from API level 1 so it should be the same on all devices.

I agree it's probably not a good idea to change the scaling if the user has changed it. But if it's an issue for you, you can check if the font size requested will cause a problem with your display and maybe change the text displayed.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Thinking about the problem, you could tell the user that fontscaling has been detected and that some text may be lost and that a long press on the field will display the text as it should be, use the SetEllipsize to show when this happens and write a sub that will display the full text for the field in a toast (or other) message when the field is long pressed. Assuming you are not using the long press for anything else of course.

It wouldn't be a lot of extra programming.

Or alternatively, set a shortname to use when fontscaling is detected that will corrupt your messages.
 
Last edited:
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
From the documentation, fontscale has been available from API level 1 so it should be the same on all devices.

I tried on a HTC Desire with 2.2 and the value returned was 1 - and you can't chance global font size there, so 1 is "normal" i guess.

I agree it's probably not a good idea to change the scaling if the user has changed it. But if it's an issue for you, you can check if the font size requested will cause a problem with your display and maybe change the text displayed.

Depends on who your target is, if you plan to put it on the market and have everyone download it then its something to take into account.

Also, I don't know if Erel is reading along, but it might be handy to be able to read these settings straight from B4A (without using the reflection library) - perhaps activity.fontscale ?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Also, I don't know if Erel is reading along, but it might be handy to be able to read these settings straight from B4A (without using the reflection library) - perhaps activity.fontscale ?
I think that in most cases developers will prefer not to do anything with this value so the Reflection solution should be fine:
B4X:
Sub GetUserFontScale As Float
   Dim R As Reflector
   R.Target = R.GetContext
   R.Target = R.RunMethod("getResources")
   R.Target=R.RunMethod("getConfiguration")
   Return R.GetField("fontScale")
End Sub
 
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
I think that in most cases developers will prefer not to do anything with this value so the Reflection solution should be fine:

You think in most cases developers won't give a crap about their app looking like shit under Android 4.0 and up?

Well I hope you are wrong. And would spend the 5 minutes to add this as a standard value. But not my program of course.
 
Last edited:
Upvote 0

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Also, I don't know if Erel is reading along, but it might be handy to be able to read these settings straight from B4A (without using the reflection library) - perhaps activity.fontscale ?


I don't think I'd really need the value as I don't want to use it every time I set a text size...a class that does it would improve on it, but it is still more work. I'd much rather have an Activity.FontUnit where we can toggle it between dp and sp. If I pick the sp unit then I know I need to adjust my view size to the size needed. It would be nice for some options to dynamically size too where you could tell B4A how many lines you want to show and it adjusts the height of the view to fit that. Width size may be more difficult though as it would need to have a Max Chars and B4A would have to calculate what the widest char is and make the width MaxChars * WidestCharWidth unless the view is resized every time the text changes.

All this sizing could put views on top of each other too, so would need some type of layout management, wrapping, control padding, etc. I may end up turning my class mentioned above into doing this. And, for WizardOz, part of the class is in a bug report thread just recently created to where I'm trying to figure out an issue with IME. I like your HAL Avatar too...I use the same thing for Google which looks nice in Google+ and was going to use it here but noticed you had it. (A little Trivia- HAL is a Caesar Cipher of IBM)
 
Upvote 0
Status
Not open for further replies.
Top