use of com.mopub.mobileads.MoPubView in project prebid-mobile-android by prebid.
the class ExtraTests method testRubiconDemand.
@Test
public void testRubiconDemand() throws Exception {
PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
PrebidMobile.setPrebidServerAccountId("1001");
PrebidMobile.setPrebidServerHost(Host.RUBICON);
PrebidMobile.setShareGeoLocation(true);
final OnCompleteListener[] listener = new OnCompleteListener[1];
mHandler.post(new Runnable() {
@Override
public void run() {
final MoPubView adObject = new MoPubView(m.getActivity());
adObject.setAdUnitId(Constants.MOPUB_BANNER_ADUNIT_ID_300x250_APPNEXUS);
adObject.setMinimumHeight(250);
adObject.setMinimumWidth(300);
BannerAdUnit adUnit = new BannerAdUnit("1001-2", 300, 250);
OnCompleteListener l = new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
FrameLayout adFrame = m.getActivity().findViewById(R.id.adFrame);
adFrame.addView(adObject);
adObject.loadAd();
}
};
listener[0] = spy(l);
adUnit.fetchDemand(adObject, listener[0]);
}
});
Thread.sleep(10000);
verify(listener[0], times(1)).onComplete(ResultCode.SUCCESS);
onView(withId(R.id.adFrame)).check(matches(isDisplayed()));
onWebView().check(webMatches(getCurrentUrl(), containsString("ads.mopub.com")));
onWebView().check(webContent(containingTextInBody("ucTag.renderAd")));
}
use of com.mopub.mobileads.MoPubView in project prebid-mobile-android by prebid.
the class ExtraTests method testAppNexusKeyValueTargeting2.
@Test
public void testAppNexusKeyValueTargeting2() throws Exception {
PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
PrebidMobile.setPrebidServerAccountId("bfa84af2-bd16-4d35-96ad-31c6bb888df0");
PrebidMobile.setPrebidServerHost(Host.APPNEXUS);
PrebidMobile.setShareGeoLocation(true);
final OnCompleteListener[] listener = new OnCompleteListener[1];
mHandler.post(new Runnable() {
@Override
public void run() {
final MoPubView adObject = new MoPubView(m.getActivity());
adObject.setAdUnitId(Constants.MOPUB_BANNER_ADUNIT_ID_300x250_APPNEXUS);
adObject.setMinimumHeight(250);
adObject.setMinimumWidth(300);
BannerAdUnit adUnit = new BannerAdUnit("67bac530-9832-4f78-8c94-fbf88ac7bd14", 300, 250);
OnCompleteListener l = new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
FrameLayout adFrame = m.getActivity().findViewById(R.id.adFrame);
adFrame.addView(adObject);
adObject.loadAd();
}
};
listener[0] = spy(l);
adUnit.fetchDemand(adObject, listener[0]);
}
});
Thread.sleep(10000);
verify(listener[0], times(1)).onComplete(ResultCode.NO_BIDS);
onView(withId(R.id.adFrame)).check(matches(isDisplayed()));
onWebView().check(webMatches(getCurrentUrl(), containsString("ads.mopub.com")));
onWebView().check(webContent(containingTextInBody("Hello, I'm not a Prebid ad.")));
}
use of com.mopub.mobileads.MoPubView in project prebid-mobile-android by prebid.
the class RubiconBannerMoPubDemoActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_demo);
PrebidMobile.setPrebidServerHost(Host.RUBICON);
PrebidMobile.setPrebidServerAccountId(Constants.PBS_ACCOUNT_ID_RUBICON);
PrebidMobile.setStoredAuctionResponse(Constants.PBS_STORED_RESPONSE_300x250_RUBICON);
String adSizeName = getIntent().getStringExtra(Constants.AD_SIZE_NAME);
int width = 0;
int height = 0;
String[] wAndH = adSizeName.split("x");
width = Integer.valueOf(wAndH[0]);
height = Integer.valueOf(wAndH[1]);
adUnit = new BannerAdUnit(Constants.PBS_CONFIG_ID_300x250_RUBICON, width, height);
BannerBaseAdUnit.Parameters parameters = new BannerBaseAdUnit.Parameters();
parameters.setApi(Arrays.asList(Signals.Api.MRAID_2));
adUnit.setParameters(parameters);
FrameLayout adFrame = findViewById(R.id.adFrame);
adFrame.removeAllViews();
final MoPubView adView = new MoPubView(this);
adView.setAdUnitId(Constants.MOPUB_BANNER_ADUNIT_ID_300x250_RUBICON);
adView.setMinimumWidth(width);
adView.setMinimumHeight(height);
adFrame.addView(adView);
adUnit.setAutoRefreshPeriodMillis(getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0));
adUnit.fetchDemand(adView, new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
adView.loadAd();
refreshCount++;
RubiconBannerMoPubDemoActivity.this.resultCode = resultCode;
}
});
}
use of com.mopub.mobileads.MoPubView in project prebid-mobile-android by prebid.
the class XandrBannerMoPubDemoActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_demo);
PrebidMobile.setPrebidServerHost(Host.APPNEXUS);
PrebidMobile.setPrebidServerAccountId(Constants.PBS_ACCOUNT_ID_APPNEXUS);
BannerAdUnit adUnit = new BannerAdUnit(Constants.PBS_CONFIG_ID_300x250_APPNEXUS, 300, 250);
BannerBaseAdUnit.Parameters parameters = new BannerBaseAdUnit.Parameters();
parameters.setApi(Arrays.asList(Signals.Api.MRAID_2));
// parameters.setApi(Arrays.asList(new Signals.Api(5)));
adUnit.setParameters(parameters);
this.adUnit = adUnit;
// Util.enableAdditionalFunctionality(this.adUnit);
FrameLayout adFrame = findViewById(R.id.adFrame);
adFrame.removeAllViews();
final MoPubView adView = new MoPubView(this);
adView.setAdUnitId(Constants.MOPUB_BANNER_ADUNIT_ID_300x250_APPNEXUS);
adView.setMinimumWidth(300);
adView.setMinimumHeight(250);
adFrame.addView(adView);
adUnit.setAutoRefreshPeriodMillis(getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0));
adUnit.fetchDemand(adView, new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
adView.loadAd();
}
});
}
use of com.mopub.mobileads.MoPubView 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);
}
}
}
}
Aggregations