I had a problem when I started developing a simple program using PhoneGap, Ruler. Most of my mobile background is with native Android, so I start with this. I start on javascript and html5, web development in general.
Here you can see my first question related to the problem.
This was my first attempt to calculate how many pixels I had per millimeter. This works great in the Android source code.
public float getYdpi() { return displayMetrics.ydpi; } function getPixelsPerMillimeter(){ return YDpi/25.4f; }
But millimeter markers were wrong. Finally, after some attempts, I replaced the method as follows
function getPixelsPerMillimeter(){ var pixelsPerMms = window.innerHeight/heightInMms; return pixelsPerMms; }
HeightInMms is calculated in the Android source code, the simple mathematical height in pixels divided by the pixel density per inch multiplied by 25.4 how many millimeters you have per inch.
public float getPhoneHeightInMillimeters(){ metrics = gap.getResources().getDisplayMetrics(); return (metrics.heightPixels / metrics.ydpi)*25.4f;
In short, dpi (or pixels per inch, which is my final goal), I get from my own code or using window.outerHeight is different from what I get from window.innerHeight. What for?
Giving real values, I am testing a galaxy s2 device with a height of 800 pixels. window.outerHeight returns 800, like metrics.heightPixels, but window.innerHeight gives me 533. Why?
source share