raviyadav15aug / ormma

Automatically exported from code.google.com/p/ormma
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Screen size reported incorrectly on hi-res Android device #16

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Install OrmmaTestBed.apk on any Hi-Res (eg 480x800) Android device
2. Run an ormma compliance link from the Test Bed.
3. The Ad does nothing but pops up alert reporting the screen size by calling 
ormma.getScreenSize() when tapping on the ad.

What is the expected output? What do you see instead?
Expecting 480x800 but getting 213x355

What version of the product are you using? On what operating system?
Ormma Release 517 / Android Test Bed / Android emulator running 480x800, 
Android 2.3.3

Please provide any additional information below.
-

Original issue reported on code.google.com by sheau...@gmail.com on 20 Sep 2011 at 7:24

GoogleCodeExporter commented 9 years ago
on 320x480 android device, it is reported correctly.

Original comment by sheau...@gmail.com on 20 Sep 2011 at 7:26

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
What is in fact happening is that the Javascript in WebView is using physical 
pixels (e.g. 800x1280) to give the best experience whereas the ORMMA code seems 
to expect it is using the logical pixels internally. It's not the same 
coordinate system in this case. So basically the Android ORMMA sizing code in 
Java's getScreenSize function in ORMMADisplayController.java is horked (plus 
other functions like the dimensions() function) for anything where 
mWindowManager.getDefaultDisplay().getMetrics returns something other than a 
density of 1 (on my Nexus 7, it's 1.33). I'm guessing the earlier test devices 
had a density of 1, so the issue with the newer devices weren't seen. This is a 
Java issue, not Javascript. However, Ormma.js, which is inserted dynamically by 
ORMMA (not in the ad itself) is doing validation on what Java sens back. For 
instance, ORMMADisplayControler.java's getScreenSize method was returning 
approximately 600x900 for my Nexus 7, when it should have been returning 
800x1280.

The changes need to go into OrmmaDisplayController.java. I've already fixed the 
expand issue by modifying getScreenSize() as follows, however it looks like I'm 
also going to need to change the dimensions() method, etc, to fix the initial 
data sent in but haven't gone through that yet to make sure. So consider this 
just an example of the TYPE of change needed (OrmmaDisplayController.java) but 
more changes will be needed for full functionality to be correct. Within 
OrmmaDisplayController.java, I changed from the following:
        public String getScreenSize() {
                DisplayMetrics metrics = new DisplayMetrics();
                mWindowManager.getDefaultDisplay().getMetrics(metrics);
                return "{ width: " + (int) (metrics.widthPixels / metrics.density) + ", " + "height: "
                                + (int) (metrics.heightPixels / metrics.density) + "}";
        }

To following:
    public String getScreenSize() {
        DisplayMetrics metrics = new DisplayMetrics();
        mWindowManager.getDefaultDisplay().getMetrics(metrics);
        // The original ORMMA code was using density, which isn't correct
        // since WebView uses the physical coordinates internally.
        return "{ width: " + (int) (metrics.widthPixels ) + ", " + "height: "
        + (int) (metrics.heightPixels) + "}";
    }

Other than your example, is this issue causes expand to not work, for instance, 
with an ipad ad running on Nexus 7 with the Meta tag added in 
OrmmaAssetController as follows, which is advised by W3c and Google itself be 
done for ads designed for ipads to prevent improper reflow: 
out.write(("<meta name=\"viewport\" content=\"target-densitydpi=device-dpi, 
width=device-width\" />").getBytes());

You'd need to change this if your target wasn't to match an ipad

For guys just using ORMMA in Javascript, and not working in the Android apps 
themselves, I'm sorry to say that you're going to need get the app developers 
using ORMMA to fix the ORMMA issues (you'll only see ORMMA.js called on the 
devices itself). If you're really skilled, you can hack ORMMA.js functionality 
dynamically (which is inserted dynamically by ORMMA) but I don't recommend it 
unless you really know what you're doing. It's best the app developers do the 
fix.

Original comment by bbo...@eyewonder.com on 13 Sep 2012 at 6:59