use of org.prebid.mobile.OnCompleteListener in project prebid-mobile-android by prebid.
the class RubiconInterstitialVideoMoPubDemoActivity 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_VAST_RUBICON);
VideoBaseAdUnit.Parameters parameters = new VideoBaseAdUnit.Parameters();
parameters.setMimes(Arrays.asList("video/mp4"));
parameters.setProtocols(Arrays.asList(Signals.Protocols.VAST_2_0));
// parameters.setProtocols(Arrays.asList(new Signals.Protocols(2)));
parameters.setPlaybackMethod(Arrays.asList(Signals.PlaybackMethod.AutoPlaySoundOff));
// parameters.setPlaybackMethod(Arrays.asList(new Signals.PlaybackMethod(2)));
VideoInterstitialAdUnit adUnit = new VideoInterstitialAdUnit("1001-1");
adUnit.setParameters(parameters);
this.adUnit = adUnit;
final MoPubInterstitial mpInterstitial = new MoPubInterstitial(this, Constants.MOPUB_INTERSTITIAL_VIDEO_ADUNIT_ID_RUBICON);
mpInterstitial.setInterstitialAdListener(new MoPubInterstitial.InterstitialAdListener() {
@Override
public void onInterstitialLoaded(MoPubInterstitial interstitial) {
interstitial.show();
}
@Override
public void onInterstitialFailed(MoPubInterstitial interstitial, MoPubErrorCode errorCode) {
AlertDialog.Builder builder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder = new AlertDialog.Builder(RubiconInterstitialVideoMoPubDemoActivity.this, android.R.style.Theme_Material_Dialog_Alert);
} else {
builder = new AlertDialog.Builder(RubiconInterstitialVideoMoPubDemoActivity.this);
}
builder.setTitle("Failed to load MoPub interstitial ad").setMessage("Error code: " + errorCode.toString()).setIcon(android.R.drawable.ic_dialog_alert).show();
}
@Override
public void onInterstitialShown(MoPubInterstitial interstitial) {
}
@Override
public void onInterstitialClicked(MoPubInterstitial interstitial) {
}
@Override
public void onInterstitialDismissed(MoPubInterstitial interstitial) {
}
});
int millis = getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0);
adUnit.setAutoRefreshPeriodMillis(millis);
adUnit.fetchDemand(mpInterstitial, new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
mpInterstitial.load();
}
});
}
use of org.prebid.mobile.OnCompleteListener in project prebid-mobile-android by prebid.
the class AdManagerComplexTest method testFetchDemand.
@Test
public void testFetchDemand() throws Exception {
final AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
fetchDemandHelper(0, new FetchDemandCompleteListener() {
@Override
public void preFetchDemand() {
}
@Override
public void executeFetchDemand(AdUnit adUnit, final List<Map<String, String>> resultList) {
adUnit.fetchDemand(builder, new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
Bundle customTargetingBundle = builder.build().getCustomTargeting();
Map<String, String> map = new HashMap<>(customTargetingBundle.keySet().size());
for (String key : customTargetingBundle.keySet()) {
map.put(key, customTargetingBundle.get(key).toString());
}
resultList.add(map);
}
});
}
@Override
public void postFetchDemand(List<Map<String, String>> resultList) {
}
});
}
use of org.prebid.mobile.OnCompleteListener in project prebid-mobile-android by prebid.
the class AdManagerComplexTest method testFetchDemandAutoRefresh.
@Test
public void testFetchDemandAutoRefresh() throws Exception {
final AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
final IntegerWrapper requestCountWrapper = new IntegerWrapper();
fetchDemandHelper(31_000, new FetchDemandCompleteListener() {
@Override
public void preFetchDemand() {
mockServer.enqueue(new MockResponse().setResponseCode(200).setBody("{\n" + " \"seatbid\": [\n" + " {\n" + " \"bid\": [\n" + " {\n" + " \"ext\": {\n" + " \"prebid\": {\n" + " \"targeting\": {\n" + " \"hb_cache_id\": \"top_bid_1\",\n" + " \"key1\": \"value1\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " ]\n" + " }\n" + " ]\n" + "}"));
}
@Override
public void executeFetchDemand(AdUnit adUnit, final List<Map<String, String>> resultList) {
adUnit.fetchDemand(builder, new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
requestCountWrapper.value++;
AdManagerAdRequest adManagerAdRequest = builder.build();
Bundle customTargetingBundle = adManagerAdRequest.getCustomTargeting();
Map<String, String> map = new HashMap<>(customTargetingBundle.keySet().size());
for (String key : customTargetingBundle.keySet()) {
map.put(key, customTargetingBundle.get(key).toString());
}
resultList.add(map);
}
});
}
@Override
public void postFetchDemand(List<Map<String, String>> resultList) {
Map<String, String> result = resultList.get(1);
assertEquals("top_bid_1", result.get("hb_cache_id"));
assertEquals("value1", result.get("key1"));
}
});
assertEquals(2, requestCountWrapper.value);
}
use of org.prebid.mobile.OnCompleteListener in project prebid-mobile-android by prebid.
the class AdManagerComplexTest method testAdManagerAdRequestBuilderUseCase.
@Test
public void testAdManagerAdRequestBuilderUseCase() throws Exception {
// given
mockServer.enqueue(new MockResponse().setResponseCode(200).setBody("{\n" + " \"seatbid\": [\n" + " {\n" + " \"bid\": [\n" + " {\n" + " \"ext\": {\n" + " \"prebid\": {\n" + " \"targeting\": {\n" + " \"hb_cache_id\": \"top_bid_1\",\n" + " \"key1\": \"value1\"\n" + " }\n" + " }\n" + " }\n" + " }\n" + " ]\n" + " }\n" + " ]\n" + "}"));
// important line
PrebidMobile.setPrebidServerHost(Host.CUSTOM);
HttpUrl httpUrl = mockServer.url("/testAdManagerAdRequestBuilderUseCase");
Host.CUSTOM.setHostUrl(httpUrl.toString());
PrebidMobile.setPrebidServerAccountId("1001");
final ReferenceWrapper<Bundle> customTargetingBundleWrapper1 = new ReferenceWrapper<>();
// when
final AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
AdUnit adUnit = new BannerAdUnit("1001-1", 300, 250);
adUnit.fetchDemand(builder, new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
builder.addCustomTargeting("key2", "value2");
AdManagerAdRequest adManagerAdRequest = builder.build();
Bundle customTargetingBundle = adManagerAdRequest.getCustomTargeting();
customTargetingBundleWrapper1.value = (Bundle) customTargetingBundle.clone();
}
});
try {
Thread.sleep(1_000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// then
Bundle customTargetingBundle = customTargetingBundleWrapper1.value;
assertEquals(3, customTargetingBundle.keySet().size());
assertEquals("top_bid_1", customTargetingBundle.getString("hb_cache_id"));
assertEquals("value1", customTargetingBundle.getString("key1"));
assertEquals("value2", customTargetingBundle.getString("key2"));
}
use of org.prebid.mobile.OnCompleteListener in project prebid-mobile-android by prebid.
the class ExtraTests method testPostDataWithContext.
@Test
public void testPostDataWithContext() throws Exception {
server.setDispatcher(new Dispatcher() {
@Override
public MockResponse dispatch(RecordedRequest request) {
if (request.getPath().equals("/testPostData")) {
String postDataString = request.getBody().readUtf8();
try {
JSONObject postData = new JSONObject(postDataString);
JSONObject device = postData.getJSONObject("device");
String ifa = device.getString("ifa");
assertTrue(ifa != null && !ifa.isEmpty());
String ua = device.getString("ua");
assertTrue(ua != null && !ua.isEmpty());
} catch (JSONException e) {
fail("error:" + e);
}
return getAppNexusDemand(postDataString);
}
return new MockResponse().setResponseCode(404);
}
});
PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
PrebidMobile.setPrebidServerAccountId("1001");
PrebidMobile.setPrebidServerHost(Host.CUSTOM);
Host.CUSTOM.setHostUrl(server.url("testPostData").toString());
mHandler.post(new Runnable() {
@Override
public void run() {
BannerAdUnit adUnit = new BannerAdUnit("1001-1", 300, 250);
final MoPubView adObject = new MoPubView(m.getActivity());
adUnit.fetchDemand(adObject, new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
}
});
}
});
Thread.sleep(5_000);
}
Aggregations