use of org.prebid.mobile.rendering.sdk.deviceData.managers.DeviceInfoManager in project prebid-mobile-android by prebid.
the class AdBaseDialog method applyOrientation.
private void applyOrientation() throws AdException {
DeviceInfoManager deviceManager = ManagersResolver.getInstance().getDeviceManager();
if (mForceOrientation == OrientationManager.ForcedOrientation.none) {
if (mAllowOrientationChange) {
// If screen orientation can be changed, an orientation of NONE means that any
// orientation lock should be removed
unApplyOrientation();
} else {
if (getActivity() == null) {
throw new AdException(AdException.INTERNAL_ERROR, "Unable to set MRAID expand orientation to " + "'none'; expected passed in Activity Context.");
}
// If screen orientation cannot be changed and we can obtain the current
// screen orientation, locking it to the current orientation is a best effort
int orientation = deviceManager.getDeviceOrientation();
lockOrientation(orientation);
}
} else {
// Otherwise, we have a valid, non-NONE orientation. Lock the screen based on this value
lockOrientation(mForceOrientation.getActivityInfoOrientation());
}
}
use of org.prebid.mobile.rendering.sdk.deviceData.managers.DeviceInfoManager in project prebid-mobile-android by prebid.
the class BaseJSInterface method getCurrentAppOrientation.
@Override
@JavascriptInterface
public String getCurrentAppOrientation() {
DeviceInfoManager deviceManager = ManagersResolver.getInstance().getDeviceManager();
int deviceOrientation = deviceManager.getDeviceOrientation();
String orientation = deviceOrientation == Configuration.ORIENTATION_PORTRAIT ? "portrait" : "landscape";
JSONObject deviceOrientationJson = new JSONObject();
try {
deviceOrientationJson.put(DEVICE_ORIENTATION, orientation);
deviceOrientationJson.put(DEVICE_ORIENTATION_LOCKED, deviceManager.isActivityOrientationLocked(mContext));
return deviceOrientationJson.toString();
} catch (JSONException e) {
LogUtil.error(TAG, "MRAID: Error providing deviceOrientationJson: " + Log.getStackTraceString(e));
}
return "{}";
}
use of org.prebid.mobile.rendering.sdk.deviceData.managers.DeviceInfoManager in project prebid-mobile-android by prebid.
the class AdWebView method calculateFactor.
private float calculateFactor(int deviceWidth, int deviceHeight, int creativeWidth) {
float factor = 100.0f;
DeviceInfoManager deviceManager = ManagersResolver.getInstance().getDeviceManager();
int orientation = deviceManager.getDeviceOrientation();
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
if (creativeWidth < deviceHeight) {
factor = factor * deviceWidth / creativeWidth;
} else {
factor = factor * deviceHeight / creativeWidth + 1;
}
} else {
if (creativeWidth < deviceWidth) {
factor = factor * deviceWidth / creativeWidth;
} else {
factor = factor * deviceWidth / creativeWidth + 1;
}
}
if (factor > 100.0f * densityScalingFactor()) {
factor = (float) (100.0f * densityScalingFactor());
}
return factor;
}
use of org.prebid.mobile.rendering.sdk.deviceData.managers.DeviceInfoManager in project prebid-mobile-android by prebid.
the class PrebidWebViewBase method renderPlacement.
private void renderPlacement(WebViewBase webViewBase, int width, int height) {
if (mContext == null) {
LogUtil.warn(TAG, "Context is null");
return;
}
if (webViewBase == null) {
LogUtil.warn(TAG, "WebviewBase is null");
return;
}
int orientation = Configuration.ORIENTATION_UNDEFINED;
WindowManager windowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
int screenWidth = Utils.getScreenWidth(windowManager);
int screenHeight = Utils.getScreenHeight(windowManager);
int deviceWidth = Math.min(screenWidth, screenHeight);
int deviceHeight = Math.max(screenWidth, screenHeight);
DeviceInfoManager deviceManager = ManagersResolver.getInstance().getDeviceManager();
if (deviceManager != null) {
orientation = deviceManager.getDeviceOrientation();
}
float factor = getScaleFactor(webViewBase, orientation, deviceWidth, deviceHeight);
webViewBase.setAdWidth(Math.round((width * factor)));
webViewBase.setAdHeight(Math.round((height * factor)));
}
use of org.prebid.mobile.rendering.sdk.deviceData.managers.DeviceInfoManager in project prebid-mobile-android by prebid.
the class BaseJSInterface method getScreenSize.
@Override
@JavascriptInterface
public String getScreenSize() {
JSONObject position = new JSONObject();
try {
DeviceInfoManager deviceManager = ManagersResolver.getInstance().getDeviceManager();
position.put(JSON_WIDTH, (int) (deviceManager.getScreenWidth() / Utils.DENSITY));
position.put(JSON_HEIGHT, (int) (deviceManager.getScreenHeight() / Utils.DENSITY));
return position.toString();
} catch (Exception e) {
LogUtil.error(TAG, "Failed getScreenSize() for MRAID: " + Log.getStackTraceString(e));
}
return "{}";
}
Aggregations