use of com.google.android.gms.ads.admanager.AdManagerAdRequest 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 com.google.android.gms.ads.admanager.AdManagerAdRequest in project prebid-mobile-android by prebid.
the class ExtraTests method testSameConfigIdOnDifferentAdObjects.
@Test
public void testSameConfigIdOnDifferentAdObjects() throws Exception {
final ArrayList<AdUnit> adUnits = new ArrayList<AdUnit>();
final ArrayList<OnCompleteListener> spies = new ArrayList<>();
PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
PrebidMobile.setPrebidServerAccountId("bfa84af2-bd16-4d35-96ad-31c6bb888df0");
PrebidMobile.setPrebidServerHost(Host.APPNEXUS);
PrebidMobile.setShareGeoLocation(true);
mHandler.post(new Runnable() {
@Override
public void run() {
final MoPubView adObject1 = new MoPubView(m.getActivity());
adObject1.setAdUnitId(Constants.MOPUB_BANNER_ADUNIT_ID_320x50_APPNEXUS);
adObject1.setMinimumWidth(320);
adObject1.setMinimumHeight(50);
BannerAdUnit adUnit1 = new BannerAdUnit(Constants.PBS_CONFIG_ID_320x50_APPNEXUS, 320, 50);
adUnits.add(adUnit1);
OnCompleteListener l1 = new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
assertTrue(adObject1.getKeywords().contains("hb_pb:0.50"));
assertTrue(adObject1.getKeywords().contains("hb_cache_id:"));
FrameLayout adFrame = m.getActivity().findViewById(R.id.adFrame);
adFrame.addView(adObject1);
adObject1.loadAd();
}
};
l1 = spy(l1);
spies.add(l1);
adUnit1.fetchDemand(adObject1, l1);
AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
final AdManagerAdRequest adObject2 = builder.build();
BannerAdUnit adUnit2 = new BannerAdUnit(Constants.PBS_CONFIG_ID_320x50_APPNEXUS, 320, 50);
adUnits.add(adUnit2);
OnCompleteListener l2 = new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
assertEquals(10, adObject2.getCustomTargeting().size());
assertTrue(adObject2.getCustomTargeting().keySet().contains("hb_pb"));
assertTrue(adObject2.getCustomTargeting().keySet().contains("hb_cache_id"));
assertEquals("0.50", adObject2.getCustomTargeting().getString("hb_pb"));
FrameLayout adFrame = m.getActivity().findViewById(R.id.adFrame);
AdManagerAdView adView = new AdManagerAdView(m.getActivity());
adView.setAdSizes(AdSize.BANNER);
adView.setAdUnitId(Constants.DFP_BANNER_ADUNIT_ID_ALL_SIZES_APPNEXUS);
adFrame.addView(adView);
adView.setId(1);
adView.loadAd(adObject2);
}
};
l2 = spy(l2);
spies.add(l2);
adUnit1.fetchDemand(adObject2, l2);
}
});
Thread.sleep(10000);
verify(spies.get(0), times(1)).onComplete(ResultCode.SUCCESS);
verify(spies.get(1), times(1)).onComplete(ResultCode.SUCCESS);
}
use of com.google.android.gms.ads.admanager.AdManagerAdRequest 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 com.google.android.gms.ads.admanager.AdManagerAdRequest 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"));
}
Aggregations