use of org.prebid.mobile.OnCompleteListener in project prebid-mobile-android by prebid.
the class XandrBannerGamDemoActivity 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);
final AdManagerAdView amBanner = new AdManagerAdView(this);
amBanner.setAdUnitId(Constants.DFP_BANNER_ADUNIT_ID_ALL_SIZES_APPNEXUS);
amBanner.setAdSizes(new AdSize(300, 250));
FrameLayout adFrame = findViewById(R.id.adFrame);
adFrame.removeAllViews();
adFrame.addView(amBanner);
amBanner.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
AdViewUtils.findPrebidCreativeSize(amBanner, new AdViewUtils.PbFindSizeListener() {
@Override
public void success(int width, int height) {
amBanner.setAdSizes(new AdSize(width, height));
}
@Override
public void failure(@NonNull PbFindSizeError error) {
Log.d("MyTag", "error: " + error);
}
});
}
});
final AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
// region PrebidMobile Mobile API 1.0 usage
int millis = getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0);
adUnit.setAutoRefreshPeriodMillis(millis);
adUnit.fetchDemand(builder, new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
AdManagerAdRequest request = builder.build();
amBanner.loadAd(request);
}
});
}
use of org.prebid.mobile.OnCompleteListener in project prebid-mobile-android by prebid.
the class ExtraTests method testRubiconEmptyInvalidPrebidServerConfigId.
@Test
public void testRubiconEmptyInvalidPrebidServerConfigId() 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_RUBICON);
adObject.setMinimumHeight(250);
adObject.setMinimumWidth(300);
BannerAdUnit adUnit = new BannerAdUnit("", 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(2000);
verify(listener[0], times(1)).onComplete(ResultCode.INVALID_CONFIG_ID);
}
use of org.prebid.mobile.OnCompleteListener in project prebid-mobile-android by prebid.
the class ExtraTests method testRubiconEmptyInvalidPrebidServerAccountId.
@Test
public void testRubiconEmptyInvalidPrebidServerAccountId() throws Exception {
PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
PrebidMobile.setPrebidServerAccountId("");
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_RUBICON);
adObject.setMinimumHeight(250);
adObject.setMinimumWidth(300);
BannerAdUnit adUnit = new BannerAdUnit("1001-1", 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(2000);
verify(listener[0], times(1)).onComplete(ResultCode.INVALID_ACCOUNT_ID);
}
use of org.prebid.mobile.OnCompleteListener in project prebid-mobile-android by prebid.
the class ExtraTests method testAppNexusAgeTargeting1.
// Passing year 1855 is invalid yob, should not send yob and get back a no bid
@Test
public void testAppNexusAgeTargeting1() throws Exception {
boolean errorThrown = false;
try {
TargetingParams.setYearOfBirth(1855);
} catch (Exception e) {
errorThrown = true;
assertEquals(0, TargetingParams.getYearOfBirth());
}
assertTrue(errorThrown);
server.setDispatcher(new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
if (request.getPath().equals("/")) {
String postData = request.getBody().readUtf8();
assertTrue("Post data should not contain yob: " + postData, !postData.contains("yob"));
return getAppNexusDemand(postData);
}
return new MockResponse().setResponseCode(404);
}
});
PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
PrebidMobile.setPrebidServerAccountId("bfa84af2-bd16-4d35-96ad-31c6bb888df0");
Host.CUSTOM.setHostUrl(server.url("/").toString());
PrebidMobile.setPrebidServerHost(Host.CUSTOM);
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("47706260-ee91-4cd7-b656-2185aca89f59", 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 org.prebid.mobile.OnCompleteListener in project prebid-mobile-android by prebid.
the class ExtraTests method testAppNexusInvalidPrebidServerAccountId.
@Test
public void testAppNexusInvalidPrebidServerAccountId() throws Exception {
PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
PrebidMobile.setPrebidServerAccountId("bfa84af2-bd16-4d35-96ad-ffffffffffff");
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("6ace8c7d-88c0-4623-8117-75bc3f0a2e45", 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.INVALID_ACCOUNT_ID);
}
Aggregations