Search in sources :

Example 1 with DeviceInfoManager

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());
    }
}
Also used : DeviceInfoManager(org.prebid.mobile.rendering.sdk.deviceData.managers.DeviceInfoManager) AdException(org.prebid.mobile.rendering.errors.AdException)

Example 2 with DeviceInfoManager

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 "{}";
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) DeviceInfoManager(org.prebid.mobile.rendering.sdk.deviceData.managers.DeviceInfoManager) SuppressLint(android.annotation.SuppressLint) JavascriptInterface(android.webkit.JavascriptInterface)

Example 3 with DeviceInfoManager

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;
}
Also used : DeviceInfoManager(org.prebid.mobile.rendering.sdk.deviceData.managers.DeviceInfoManager) SuppressLint(android.annotation.SuppressLint)

Example 4 with DeviceInfoManager

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)));
}
Also used : DeviceInfoManager(org.prebid.mobile.rendering.sdk.deviceData.managers.DeviceInfoManager) WindowManager(android.view.WindowManager)

Example 5 with DeviceInfoManager

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 "{}";
}
Also used : JSONObject(org.json.JSONObject) DeviceInfoManager(org.prebid.mobile.rendering.sdk.deviceData.managers.DeviceInfoManager) JSONException(org.json.JSONException) JavascriptInterface(android.webkit.JavascriptInterface)

Aggregations

DeviceInfoManager (org.prebid.mobile.rendering.sdk.deviceData.managers.DeviceInfoManager)9 SuppressLint (android.annotation.SuppressLint)2 JavascriptInterface (android.webkit.JavascriptInterface)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 ConnectionInfoManager (org.prebid.mobile.rendering.sdk.deviceData.managers.ConnectionInfoManager)2 WindowManager (android.view.WindowManager)1 AdSize (org.prebid.mobile.rendering.bidding.data.AdSize)1 AdException (org.prebid.mobile.rendering.errors.AdException)1 Device (org.prebid.mobile.rendering.models.openrtb.bidRequests.Device)1 URLComponents (org.prebid.mobile.rendering.networking.urlBuilder.URLComponents)1 LocationInfoManager (org.prebid.mobile.rendering.sdk.deviceData.managers.LocationInfoManager)1