use of com.google.android.gms.ads.doubleclick.PublisherAdView 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);
}
}
}
}
use of com.google.android.gms.ads.doubleclick.PublisherAdView in project prebid-mobile-android by prebid.
the class DFPBannerFragment method setupBannerWithoutWait.
private void setupBannerWithoutWait() {
FrameLayout adFrame = (FrameLayout) root.findViewById(R.id.adFrame);
adFrame.removeAllViews();
adView1 = new PublisherAdView(getActivity());
adView1.setAdUnitId(Constants.DFP_BANNER_ADUNIT_ID_320x50);
adView1.setAdSizes(new AdSize(320, 50));
adView1.setAdListener(adListener);
adFrame.addView(adView1);
// region PriceCheckForDFP API usage
PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder();
PublisherAdRequest request = builder.build();
Prebid.attachBids(request, Constants.BANNER_320x50, this.getActivity());
// endregion
adView1.loadAd(request);
}
use of com.google.android.gms.ads.doubleclick.PublisherAdView in project prebid-mobile-android by prebid.
the class DFPBannerFragment method setupBannerWithWait.
private void setupBannerWithWait(final int waitTime) {
FrameLayout adFrame = (FrameLayout) root.findViewById(R.id.adFrame2);
adFrame.removeAllViews();
adView2 = new PublisherAdView(getActivity());
adView2.setAdUnitId(Constants.DFP_BANNER_ADUNIT_ID_300x250);
adView2.setAdSizes(new AdSize(300, 250));
adView2.setAdListener(adListener);
adFrame.addView(adView2);
// region PriceCheckForDFP API usage
PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder();
PublisherAdRequest request = builder.build();
Prebid.attachBidsWhenReady(request, Constants.BANNER_300x250, this, waitTime, this.getActivity());
// endregion
}
use of com.google.android.gms.ads.doubleclick.PublisherAdView 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);
}
}
Aggregations