My goal: to shift my UI controls above the banner ad. Thus I need to calculate the AdBanner height.
Approach 1) read the pixels directly from native View (in Java):
int height = adView.getHeight();
This returns proper value but unfortunately only after the banner reloads for the first time.
It returns 0 after first banner is loaded (why?)
Approach 2) calculate the pixels based on known banner height (50 on phone and 90 on tablet)
This routine works super on iOS:
si.physicalToDesignPoints = function (_p)
{
var csf = cc.director.getOpenGLView().getContentScaleFactor();
var physicalSize = cc.view.getFrameSize();
var designSize = cc.director.getWinSize();
var p = cc.pMult(_p, csf);
p.x = designSize.width * p.x / physicalSize.width;
p.y = designSize.height * p.y / physicalSize.height;
return p;
};
However, this fails on Android. My suspicion for possible trouble is the “Navigation Bar” which is visible;
My device is Asus, Model K013, Display: 1280 x 800;
Here are some details:
Device physical screen size: 1280 x 800
Physical size dedicated for the app (view.getFrameSize): 1280.0, 736.0
Design size=(1363.2, 768.0);
=================================================================
cc.director.getOpenGLView().isRetinaEnabled()=false;
cc.director.getContentScaleFactor()=1;
cc.director.getOpenGLView().getDevicePixelRatio()=1;
cc.view.getFrameSize()=(1280.0, 736.0);
cc.director.getWinSize()=(1363.2, 768.0);
cc.director.getWinSizeInPixels()=(1363.2, 768.0);
cc.director.getVisibleSize()=(1363.2, 768.0);
cc.director.getOpenGLView().getContentTranslateLeftTop()=(NULL);
cc.director.getOpenGLView().getDesignResolutionSize()=(1363.2, 768.0);
cc.director.getOpenGLView().getFrameSize()=(1280.0, 736.0);
cc.director.getOpenGLView().getScaleX()=0.9389671683311462;
cc.director.getOpenGLView().getScaleY()=0.9389671683311462;
cc.director.getOpenGLView().getScissorRect()=(0.0, -7.9, 1363.2, 783.8);
cc.director.getOpenGLView().getViewPortRect()=(1280.0, 721.1);
cc.director.getOpenGLView().getVisibleOrigin()=(0.0, 0.0);
cc.director.getOpenGLView().getVisibleSize()=(1363.2, 768.0);
The si.physicalToDesignPoints function returns 93.91 on tablet (banner height is 90) but the valid value is 119. This is what is returned using approach 1) and what shifts the UI controls to proper distance.
Any idea how should I calculate the AdBanner height in design pixels properly?