jmpessoa / lazandroidmodulewizard

LAMW: Lazarus Android Module Wizard: Form Designer and Components development model!
246 stars 82 forks source link

Update jForm.java #474

Closed neurocluster closed 2 years ago

neurocluster commented 2 years ago

Added new functions for getting real screen size in inches and real pixel density. Previous functions get only rough approximation of pixel density, which is not suitable for many applications. As for example: Self.GetScreenDpi() for Samsung Galaxy Tab A 10.1 (2016) SM-T580 reports 240 ppi, while actually it is ~224 ppi; Self.GetScreenDpi() for Samsung Galaxy S9 reports 640 ppi, while actually it is ~570 ppi. Source info: https://stackoverflow.com/questions/3166501/getting-the-screen-density-programmatically-in-android Though Android doesn't use a direct pixel mapping, it uses a handful of quantized Density Independent Pixel values then scales to the actual screen size. So the metrics.densityDpi property will be one of the DENSITY_xxx constants (120, 160, 213, 240, 320, 480 or 640 dpi). If you need the actual lcd pixel density (perhaps for an OpenGL app) you can get it from the metrics.xdpi and metrics.ydpi properties for horizontal and vertical density respectively.