Search in sources :

Example 1 with AdSize

use of org.prebid.mobile.drprebid.model.AdSize in project prebid-mobile-android by prebid.

the class RealTimeDemandTest method startTest.

public void startTest() {
    GeneralSettings generalSettings = SettingsManager.getInstance(mContext).getGeneralSettings();
    PrebidServerSettings prebidServerSettings = SettingsManager.getInstance(mContext).getPrebidServerSettings();
    AdUnit adUnit = null;
    if (generalSettings.getAdFormat() == AdFormat.BANNER) {
        AdSize adSize = generalSettings.getAdSize();
        adUnit = new BannerAdUnit(prebidServerSettings.getConfigId(), adSize.getWidth(), adSize.getHeight());
    } else if (generalSettings.getAdFormat() == AdFormat.INTERSTITIAL) {
        adUnit = new InterstitialAdUnit(prebidServerSettings.getConfigId());
    }
    List<AdUnit> adUnits = Collections.singletonList(adUnit);
    String hostUrl;
    switch(prebidServerSettings.getPrebidServer()) {
        case APPNEXUS:
            PrebidMobile.setPrebidServerHost(Host.APPNEXUS);
            hostUrl = Constants.EndpointUrls.APPNEXUS_PREBID_SERVER;
            break;
        case RUBICON:
            PrebidMobile.setPrebidServerHost(Host.RUBICON);
            hostUrl = Constants.EndpointUrls.RUBICON_PREBID_SERVER;
            break;
        case CUSTOM:
            PrebidMobile.setPrebidServerHost(Host.CUSTOM);
            hostUrl = buildCustomServerEndpoint(prebidServerSettings.getCustomPrebidServerUrl());
            Host.CUSTOM.setHostUrl(hostUrl);
            break;
        default:
            PrebidMobile.setPrebidServerHost(Host.APPNEXUS);
            hostUrl = Constants.EndpointUrls.APPNEXUS_PREBID_SERVER;
    }
    DemandRequestBuilder builder = new DemandRequestBuilder(mContext, prebidServerSettings.getConfigId(), generalSettings.getAdSize());
    String request = builder.buildRequest(adUnits, prebidServerSettings.getAccountId(), true);
    testResponseCount = 0;
    testResults = new DemandTestResults(request);
    for (int i = 0; i < REQUEST_MAX; i++) {
        runTest(hostUrl, request, requestCompletionListener);
    }
}
Also used : PrebidServerSettings(org.prebid.mobile.drprebid.model.PrebidServerSettings) BannerAdUnit(org.prebid.mobile.BannerAdUnit) AdUnit(org.prebid.mobile.AdUnit) InterstitialAdUnit(org.prebid.mobile.InterstitialAdUnit) AdSize(org.prebid.mobile.drprebid.model.AdSize) DemandTestResults(org.prebid.mobile.drprebid.model.DemandTestResults) GeneralSettings(org.prebid.mobile.drprebid.model.GeneralSettings) BannerAdUnit(org.prebid.mobile.BannerAdUnit) InterstitialAdUnit(org.prebid.mobile.InterstitialAdUnit)

Example 2 with AdSize

use of org.prebid.mobile.drprebid.model.AdSize in project prebid-mobile-android by prebid.

the class DemandRequestBuilder method getOpenRtbImpressions.

private JSONArray getOpenRtbImpressions(List<AdUnit> adUnits, boolean secureParams) throws JSONException {
    JSONArray imps = new JSONArray();
    for (AdUnit adUnit : adUnits) {
        JSONObject imp = new JSONObject();
        imp.put("id", UUID.randomUUID().toString());
        if (secureParams) {
            imp.put("secure", 1);
        }
        JSONArray sizes = new JSONArray();
        for (AdSize size : adSizes) {
            JSONObject sizeObject = new JSONObject();
            sizeObject.put("w", size.getWidth());
            sizeObject.put("h", size.getHeight());
            sizes.put(sizeObject);
        }
        if (adUnit instanceof InterstitialAdUnit) {
            imp.put("instl", 1);
            Display display = ((Activity) context).getWindowManager().getDefaultDisplay();
            Point size = new Point();
            display.getSize(size);
            JSONObject sizeObject = new JSONObject();
            sizeObject.put("w", size.x);
            sizeObject.put("h", size.y);
            sizes.put(sizeObject);
        }
        JSONObject formats = new JSONObject();
        formats.put("format", sizes);
        imp.put("banner", formats);
        JSONObject ext = new JSONObject();
        JSONObject prebid = new JSONObject();
        JSONObject storedRequest = new JSONObject();
        storedRequest.put("id", configId);
        prebid.put("storedrequest", storedRequest);
        ext.put("prebid", prebid);
        imp.put("ext", ext);
        imps.put(imp);
    }
    return imps;
}
Also used : AdUnit(org.prebid.mobile.AdUnit) InterstitialAdUnit(org.prebid.mobile.InterstitialAdUnit) JSONObject(org.json.JSONObject) AdSize(org.prebid.mobile.drprebid.model.AdSize) JSONArray(org.json.JSONArray) Point(android.graphics.Point) InterstitialAdUnit(org.prebid.mobile.InterstitialAdUnit) Display(android.view.Display)

Example 3 with AdSize

use of org.prebid.mobile.drprebid.model.AdSize in project prebid-mobile-android by prebid.

the class SdkTest method setupPrebid.

private void setupPrebid() {
    GeneralSettings generalSettings = SettingsManager.getInstance(mContext).getGeneralSettings();
    PrebidServerSettings prebidServerSettings = SettingsManager.getInstance(mContext).getPrebidServerSettings();
    setPrebidTargetingParams();
    if (generalSettings.getAdFormat() == AdFormat.BANNER) {
        AdSize adSize = generalSettings.getAdSize();
        mAdUnit = new BannerAdUnit(prebidServerSettings.getConfigId(), adSize.getWidth(), adSize.getHeight());
    } else if (generalSettings.getAdFormat() == AdFormat.INTERSTITIAL) {
        mAdUnit = new InterstitialAdUnit(prebidServerSettings.getConfigId());
    }
    PrebidMobile.setPrebidServerAccountId(prebidServerSettings.getAccountId());
    switch(prebidServerSettings.getPrebidServer()) {
        case APPNEXUS:
            PrebidMobile.setPrebidServerHost(Host.APPNEXUS);
            break;
        case RUBICON:
            PrebidMobile.setPrebidServerHost(Host.RUBICON);
            break;
        case CUSTOM:
            PrebidMobile.setPrebidServerHost(Host.CUSTOM);
            Host.CUSTOM.setHostUrl(buildCustomServerEndpoint(prebidServerSettings.getCustomPrebidServerUrl()));
            break;
    }
    if (mListener != null) {
        mListener.onAdUnitRegistered();
    }
}
Also used : PrebidServerSettings(org.prebid.mobile.drprebid.model.PrebidServerSettings) AdSize(org.prebid.mobile.drprebid.model.AdSize) GeneralSettings(org.prebid.mobile.drprebid.model.GeneralSettings) BannerAdUnit(org.prebid.mobile.BannerAdUnit) InterstitialAdUnit(org.prebid.mobile.InterstitialAdUnit)

Example 4 with AdSize

use of org.prebid.mobile.drprebid.model.AdSize in project prebid-mobile-android by prebid.

the class SdkTest method startTest.

public void startTest() {
    GeneralSettings generalSettings = SettingsManager.getInstance(mContext).getGeneralSettings();
    AdServerSettings adServerSettings = SettingsManager.getInstance(mContext).getAdServerSettings();
    if (adServerSettings.getAdServer() == AdServer.MOPUB) {
        if (generalSettings.getAdFormat() == AdFormat.BANNER) {
            AdSize adSize = generalSettings.getAdSize();
            FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(DimenUtil.convertPxToDp(mContext, adSize.getWidth()), DimenUtil.convertPxToDp(mContext, adSize.getHeight()));
            mMoPubBanner = new MoPubView(mContext);
            mMoPubBanner.setLayoutParams(layoutParams);
            mMoPubBanner.setAutorefreshEnabled(false);
            mMoPubBanner.setBannerAdListener(this);
            mMoPubBanner.setAdUnitId(adServerSettings.getAdUnitId());
            if (mAdUnit != null) {
                Networking.getRequestQueue(mContext).addRequestFinishedListener(mMoPubRequestFinishedListener);
                mAdUnit.fetchDemand(mMoPubBanner, resultCode -> {
                    checkPrebidLog();
                    mMoPubBanner.loadAd();
                });
                if (mListener != null) {
                    mListener.requestToPrebidServerSent(true);
                }
            }
        } else if (generalSettings.getAdFormat() == AdFormat.INTERSTITIAL) {
            mMoPubInterstitial = new MoPubInterstitial(mContext, adServerSettings.getAdUnitId());
            mMoPubInterstitial.setInterstitialAdListener(this);
            if (mAdUnit != null) {
                Networking.getRequestQueue(mContext).addRequestFinishedListener(mMoPubRequestFinishedListener);
                mAdUnit.fetchDemand(mMoPubInterstitial, resultCode -> {
                    checkPrebidLog();
                    mMoPubInterstitial.load();
                });
                if (mListener != null) {
                    mListener.requestToPrebidServerSent(true);
                }
            }
        }
    } else if (adServerSettings.getAdServer() == AdServer.GOOGLE_AD_MANAGER) {
        if (generalSettings.getAdFormat() == AdFormat.BANNER) {
            mGoogleBanner = new PublisherAdView(mContext);
            AdSize adSize = generalSettings.getAdSize();
            mGoogleBanner.setAdSizes(new com.google.android.gms.ads.AdSize(adSize.getWidth(), adSize.getHeight()));
            mGoogleBanner.setAdUnitId(adServerSettings.getAdUnitId());
            mGoogleBanner.setAdListener(mGoogleBannerListener);
        } else if (generalSettings.getAdFormat() == AdFormat.INTERSTITIAL) {
            mGoogleInterstitial = new PublisherInterstitialAd(mContext);
            mGoogleInterstitial.setAdUnitId(adServerSettings.getAdUnitId());
            mGoogleInterstitial.setAdListener(mGoogleInterstitialListener);
        }
        if (mAdUnit != null) {
            final Map<String, String> keywordsMap = new HashMap<>();
            mAdUnit.fetchDemand(keywordsMap, resultCode -> {
                boolean responseSuccess = false;
                if (resultCode == SUCCESS) {
                    responseSuccess = true;
                }
                boolean topBid = false;
                if (keywordsMap.containsKey("hb_cache_id")) {
                    topBid = true;
                }
                PublisherAdRequest.Builder adRequestBuilder = new PublisherAdRequest.Builder();
                for (Map.Entry<String, String> entry : keywordsMap.entrySet()) {
                    adRequestBuilder.addCustomTargeting(entry.getKey(), entry.getValue());
                }
                if (generalSettings.getAdFormat() == AdFormat.BANNER) {
                    mGoogleBanner.loadAd(adRequestBuilder.build());
                } else if (generalSettings.getAdFormat() == AdFormat.INTERSTITIAL) {
                    mGoogleInterstitial.loadAd(adRequestBuilder.build());
                }
                if (mListener != null) {
                    mListener.responseFromPrebidServerReceived(responseSuccess);
                    mListener.bidReceivedAndCached(topBid);
                    mListener.requestSentToAdServer("", "");
                }
            });
            if (mListener != null) {
                mListener.requestToPrebidServerSent(true);
            }
        }
    }
}
Also used : Networking(com.mopub.network.Networking) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) AdListener(com.google.android.gms.ads.AdListener) BannerAdUnit(org.prebid.mobile.BannerAdUnit) HashMap(java.util.HashMap) RequestBody(okhttp3.RequestBody) AdUnit(org.prebid.mobile.AdUnit) InterstitialAdUnit(org.prebid.mobile.InterstitialAdUnit) BidLog(org.prebid.mobile.BidLog) TargetingParams(org.prebid.mobile.TargetingParams) ByteArrayInputStream(java.io.ByteArrayInputStream) PublisherAdRequest(com.google.android.gms.ads.doubleclick.PublisherAdRequest) GeneralSettings(org.prebid.mobile.drprebid.model.GeneralSettings) Map(java.util.Map) AdServer(org.prebid.mobile.drprebid.model.AdServer) Response(okhttp3.Response) MoPubView(com.mopub.mobileads.MoPubView) Call(okhttp3.Call) Callback(okhttp3.Callback) IOUtil(org.prebid.mobile.drprebid.util.IOUtil) MoPubRequestQueue(com.mopub.network.MoPubRequestQueue) AdServerSettings(org.prebid.mobile.drprebid.model.AdServerSettings) Log(android.util.Log) DimenUtil(org.prebid.mobile.drprebid.util.DimenUtil) MediaType(okhttp3.MediaType) PublisherInterstitialAd(com.google.android.gms.ads.doubleclick.PublisherInterstitialAd) PublisherAdView(com.google.android.gms.ads.doubleclick.PublisherAdView) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) SettingsManager(org.prebid.mobile.drprebid.managers.SettingsManager) PrebidServerSettings(org.prebid.mobile.drprebid.model.PrebidServerSettings) SUCCESS(org.prebid.mobile.ResultCode.SUCCESS) TextUtils(android.text.TextUtils) IOException(java.io.IOException) AdSize(org.prebid.mobile.drprebid.model.AdSize) RequestQueue(com.mopub.volley.RequestQueue) Nullable(androidx.annotation.Nullable) OkHttpClient(okhttp3.OkHttpClient) AdFormat(org.prebid.mobile.drprebid.model.AdFormat) MoPubErrorCode(com.mopub.mobileads.MoPubErrorCode) MoPubInterstitial(com.mopub.mobileads.MoPubInterstitial) Activity(android.app.Activity) Host(org.prebid.mobile.Host) Request(com.mopub.volley.Request) PrebidMobile(org.prebid.mobile.PrebidMobile) InputStream(java.io.InputStream) MoPubInterstitial(com.mopub.mobileads.MoPubInterstitial) AdServerSettings(org.prebid.mobile.drprebid.model.AdServerSettings) GeneralSettings(org.prebid.mobile.drprebid.model.GeneralSettings) PublisherAdView(com.google.android.gms.ads.doubleclick.PublisherAdView) AdSize(org.prebid.mobile.drprebid.model.AdSize) FrameLayout(android.widget.FrameLayout) PublisherAdRequest(com.google.android.gms.ads.doubleclick.PublisherAdRequest) PublisherInterstitialAd(com.google.android.gms.ads.doubleclick.PublisherInterstitialAd) HashMap(java.util.HashMap) Map(java.util.Map) MoPubView(com.mopub.mobileads.MoPubView)

Example 5 with AdSize

use of org.prebid.mobile.drprebid.model.AdSize in project prebid-mobile-android by prebid.

the class AdServerTest method startTest.

public void startTest() {
    GeneralSettings generalSettings = SettingsManager.getInstance(mContext).getGeneralSettings();
    AdServerSettings adServerSettings = SettingsManager.getInstance(mContext).getAdServerSettings();
    PrebidServerSettings prebidServerSettings = SettingsManager.getInstance(mContext).getPrebidServerSettings();
    switch(generalSettings.getAdSize()) {
        case BANNER_300x250:
            break;
        case BANNER_300x600:
            break;
        case BANNER_320x50:
            break;
        case BANNER_320x100:
            break;
        case BANNER_320x480:
            break;
        case BANNER_728x90:
            break;
    }
    mKeywords = createMapKeywords(adServerSettings.getBidPrice(), generalSettings.getAdSize(), generalSettings.getAdFormat(), prebidServerSettings.getPrebidServer());
    if (adServerSettings.getAdServer() == AdServer.MOPUB) {
        String keywords = createStringKeywords();
        if (generalSettings.getAdFormat() == AdFormat.BANNER) {
            AdSize adSize = generalSettings.getAdSize();
            FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(DimenUtil.convertPxToDp(mContext, adSize.getWidth()), DimenUtil.convertPxToDp(mContext, adSize.getHeight()));
            mMoPubAd = new MoPubView(mContext);
            mMoPubAd.setLayoutParams(layoutParams);
            mMoPubAd.setAdUnitId(adServerSettings.getAdUnitId());
            mMoPubAd.setAutorefreshEnabled(false);
            mMoPubAd.setBannerAdListener(this);
            mMoPubAd.setKeywords(keywords);
            Networking.getRequestQueue(mContext).addRequestFinishedListener(mMoPubRequestFinishedListener);
            mMoPubAd.loadAd();
        } else if (generalSettings.getAdFormat() == AdFormat.INTERSTITIAL) {
            mMoPubInterstitial = new MoPubInterstitial(mContext, adServerSettings.getAdUnitId());
            mMoPubInterstitial.setInterstitialAdListener(this);
            mMoPubInterstitial.setKeywords(keywords);
            Networking.getRequestQueue(mContext).addRequestFinishedListener(mMoPubRequestFinishedListener);
            mMoPubInterstitial.load();
        }
    } else if (adServerSettings.getAdServer() == AdServer.GOOGLE_AD_MANAGER) {
        PublisherAdRequest adRequest = null;
        if (generalSettings.getAdFormat() == AdFormat.BANNER) {
            mGoogleAd = new PublisherAdView(mContext);
            AdSize adSize = generalSettings.getAdSize();
            mGoogleAd.setAdSizes(new com.google.android.gms.ads.AdSize(adSize.getWidth(), adSize.getHeight()));
            mGoogleAd.setAdUnitId(adServerSettings.getAdUnitId());
            mGoogleAd.setAdListener(mGoogleBannerListener);
        } else if (generalSettings.getAdFormat() == AdFormat.INTERSTITIAL) {
            mGoogleInterstitial = new PublisherInterstitialAd(mContext);
            mGoogleInterstitial.setAdUnitId(adServerSettings.getAdUnitId());
            mGoogleInterstitial.setAdListener(mGoogleInterstitialListener);
        }
        PublisherAdRequest.Builder adRequestBuilder = new PublisherAdRequest.Builder();
        for (String key : mKeywords.keySet()) {
            if (mKeywords.containsKey(key)) {
                adRequestBuilder.addCustomTargeting(key, mKeywords.get(key));
            }
        }
        adRequest = adRequestBuilder.build();
        if (generalSettings.getAdFormat() == AdFormat.BANNER) {
            mGoogleAd.loadAd(adRequest);
        } else if (generalSettings.getAdFormat() == AdFormat.INTERSTITIAL) {
            mGoogleInterstitial.loadAd(adRequest);
        }
        checkRequestForKeywordsAM(adRequest);
    }
}
Also used : PrebidServerSettings(org.prebid.mobile.drprebid.model.PrebidServerSettings) MoPubInterstitial(com.mopub.mobileads.MoPubInterstitial) AdServerSettings(org.prebid.mobile.drprebid.model.AdServerSettings) GeneralSettings(org.prebid.mobile.drprebid.model.GeneralSettings) PublisherAdView(com.google.android.gms.ads.doubleclick.PublisherAdView) AdSize(org.prebid.mobile.drprebid.model.AdSize) FrameLayout(android.widget.FrameLayout) PublisherAdRequest(com.google.android.gms.ads.doubleclick.PublisherAdRequest) PublisherInterstitialAd(com.google.android.gms.ads.doubleclick.PublisherInterstitialAd) MoPubView(com.mopub.mobileads.MoPubView)

Aggregations

AdSize (org.prebid.mobile.drprebid.model.AdSize)5 InterstitialAdUnit (org.prebid.mobile.InterstitialAdUnit)4 GeneralSettings (org.prebid.mobile.drprebid.model.GeneralSettings)4 PrebidServerSettings (org.prebid.mobile.drprebid.model.PrebidServerSettings)4 AdUnit (org.prebid.mobile.AdUnit)3 BannerAdUnit (org.prebid.mobile.BannerAdUnit)3 FrameLayout (android.widget.FrameLayout)2 PublisherAdRequest (com.google.android.gms.ads.doubleclick.PublisherAdRequest)2 PublisherAdView (com.google.android.gms.ads.doubleclick.PublisherAdView)2 PublisherInterstitialAd (com.google.android.gms.ads.doubleclick.PublisherInterstitialAd)2 MoPubInterstitial (com.mopub.mobileads.MoPubInterstitial)2 MoPubView (com.mopub.mobileads.MoPubView)2 Activity (android.app.Activity)1 Point (android.graphics.Point)1 Uri (android.net.Uri)1 TextUtils (android.text.TextUtils)1 Log (android.util.Log)1 Display (android.view.Display)1 Nullable (androidx.annotation.Nullable)1 AdListener (com.google.android.gms.ads.AdListener)1