0

My application runs in a phone & uses the Presentation Display to render a scene.

The phone is a Samsung Galaxy S4 around 480dpi's.

I connect a 40" tv with a MHL/HDMI adapter. As seen in LogCat those are its metrics:

{"HDMI Screen": 1920 x 1080, 60.000004 fps, density 320, 320.0 x 320.0 dpi, touch EXTERNAL, rotation 0, type HDMI, FLAG_SECURE, FLAG_SUPPORTS_PROTECTED_BUFFERS, FLAG_PRESENTATION}

My problem is, the dpi's of that secondary display are obviously wrong! The density is much, much lower than 320dpi. I wonder where this value comes from, and if it is adjustable. I'd like to use a value in the mdpi land so the font is rendered smaller.

rupps
  • 9,712
  • 4
  • 55
  • 95
  • 1
    Bear in mind that while the *physical* density is a lot lower, the *apparent* density may be around the stated value. You sit a lot further away from a TV than you do a phone, so while it is a 40" TV, the apparent screen size will be a fraction of that. – CommonsWare Aug 17 '14 at 19:10
  • I mean that the field in DisplayMetrics is not used anywhere in the AOSP. SO if its wrong, it won't cause any bugs in smoke tests. – Gabe Sechan Aug 17 '14 at 19:11
  • @CommonsWare that's what I suspected, however, has the developer any control about this? In my app the font sizes are absurdly big rendering at 320dpi, if I was able to lower the dpi's to around 200 everything would look much much better. BTW I'm using your cwac-presentation library, love it ! – rupps Aug 17 '14 at 19:14
  • 1
    "however, has the developer any control about this?" -- not directly AFAIK. I have not tested whether the `Context` for an external display honors the `-television` resource set qualifier. If it does, you could use dimension resources for your font sizes, and override them for television scenarios with tweaked values. Failing that, set up separate dimension resource values (e.g., `@dimen/font_size` and `@dimen/font_size_tv`) and use the `_tv` one for layouts you load into the `Presentation`. The latter approach would be a pain if you're trying to use the same layouts in both cases, though. – CommonsWare Aug 17 '14 at 19:21
  • @CommonsWare as I totally control the render process I can easily include a factor to downscale the fonts, will take that path, however, I think Android should include this capability. I have made additional tests and found that in a much smaller TV -22"- , the reported DPI's are the same, so for that screen size it makes sense. I suppose it's only on huge TV's where the value is maybe too high. thx for your answer! – rupps Aug 17 '14 at 19:25

1 Answers1

1

If you're looking at the DPI in the DisplayMatrics class- it isn't accurate. It depends on a field being set by the OEM when they build Android, but the field isn't set it causes no bugs as it isn't used anywhere. So you can't trust it even for the native screen the device is built with. Trusting it for an outside screen is even less likely to be right.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • I'm not looking to trust it, just a way to change it. Android rendering at 320dpi looks ridiculous on a 50" screen, the fonts are really huge. – rupps Aug 17 '14 at 19:12
  • See also: https://groups.google.com/forum/#!topic/android-developers/g56jV0Hora0 https://code.google.com/p/android/issues/detail?id=61092 – Gabe Sechan Aug 17 '14 at 19:13
  • thanks for the links, however it's not really related to my problem, I am talking about an external display. Also, mind that a lot of -slightly advanced- apps effectively use that DisplayMetrics field to adjust coordinates, multiply font sizes, etc... So it would certainly cause a lot of bugs if a device reports strange values! – rupps Aug 17 '14 at 19:21
  • Wait what? Using DisplayMetrics to scale text? Moving things based on density? That is a seriously bad idea and there is invariably a much better way to use the density independent tools available to you to do the same thing. – ianhanniballake Aug 17 '14 at 19:24
  • A seriously bad idea? Don't think so! Android totally relies on the densityFactor and fontScaledDensity factor, don't see why it's a bad idea to rely on it as well -on specific situations-. Thanks to those values I am able to scale my custom widgets to a thousand different devices without any problem until today ! I wonder how else could you translate dp's to px's without the displaymetrics values .... – rupps Aug 17 '14 at 19:29
  • @rupps Because its frequently wrong. There's dozens of posts about this on stackoverflow and other sites. Do some research. – Gabe Sechan Aug 17 '14 at 19:41
  • I think we're not talking about the same thing. The fact that x&y density values are not accurate is not related to the fact that the rest of measures in DisplayMetrics are in fact accurate and needed, specially to do lowlevel graphics that render seamlessly across different screens -what I do-. Not talking about scaling a TextView! – rupps Aug 17 '14 at 23:10