Search in sources :

Example 26 with AdManagerAdRequest

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);
        }
    });
}
Also used : PbFindSizeError(org.prebid.mobile.addendum.PbFindSizeError) BannerAdUnit(org.prebid.mobile.BannerAdUnit) AdListener(com.google.android.gms.ads.AdListener) OnCompleteListener(org.prebid.mobile.OnCompleteListener) AdManagerAdView(com.google.android.gms.ads.admanager.AdManagerAdView) BannerBaseAdUnit(org.prebid.mobile.BannerBaseAdUnit) AdSize(com.google.android.gms.ads.AdSize) FrameLayout(android.widget.FrameLayout) NonNull(androidx.annotation.NonNull) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) ResultCode(org.prebid.mobile.ResultCode)

Example 27 with AdManagerAdRequest

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);
}
Also used : ArrayList(java.util.ArrayList) BannerAdUnit(org.prebid.mobile.BannerAdUnit) OnCompleteListener(org.prebid.mobile.OnCompleteListener) BannerAdUnit(org.prebid.mobile.BannerAdUnit) AdUnit(org.prebid.mobile.AdUnit) InterstitialAdUnit(org.prebid.mobile.InterstitialAdUnit) AdManagerAdView(com.google.android.gms.ads.admanager.AdManagerAdView) FrameLayout(android.widget.FrameLayout) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) ResultCode(org.prebid.mobile.ResultCode) MoPubView(com.mopub.mobileads.MoPubView) Test(org.junit.Test)

Example 28 with AdManagerAdRequest

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);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) HashMap(java.util.HashMap) Bundle(android.os.Bundle) OnCompleteListener(org.prebid.mobile.OnCompleteListener) BannerAdUnit(org.prebid.mobile.BannerAdUnit) AdUnit(org.prebid.mobile.AdUnit) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) HashMap(java.util.HashMap) Map(java.util.Map) ResultCode(org.prebid.mobile.ResultCode) Test(org.junit.Test)

Example 29 with AdManagerAdRequest

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"));
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) Bundle(android.os.Bundle) HttpUrl(okhttp3.HttpUrl) BannerAdUnit(org.prebid.mobile.BannerAdUnit) OnCompleteListener(org.prebid.mobile.OnCompleteListener) BannerAdUnit(org.prebid.mobile.BannerAdUnit) AdUnit(org.prebid.mobile.AdUnit) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) ResultCode(org.prebid.mobile.ResultCode) Test(org.junit.Test)

Aggregations

AdManagerAdRequest (com.google.android.gms.ads.admanager.AdManagerAdRequest)29 Test (org.junit.Test)17 OnCompleteListener (org.prebid.mobile.OnCompleteListener)13 ResultCode (org.prebid.mobile.ResultCode)13 Bundle (android.os.Bundle)9 MockResponse (okhttp3.mockwebserver.MockResponse)9 HttpUrl (okhttp3.HttpUrl)8 BackgroundThreadExecutor (org.prebid.mobile.tasksmanager.BackgroundThreadExecutor)8 ShadowLooper (org.robolectric.shadows.ShadowLooper)8 NonNull (androidx.annotation.NonNull)7 FrameLayout (android.widget.FrameLayout)6 AdManagerAdView (com.google.android.gms.ads.admanager.AdManagerAdView)6 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 BannerAdUnit (org.prebid.mobile.BannerAdUnit)6 AdListener (com.google.android.gms.ads.AdListener)5 LoadAdError (com.google.android.gms.ads.LoadAdError)5 AdSize (com.google.android.gms.ads.AdSize)4 PbFindSizeError (org.prebid.mobile.addendum.PbFindSizeError)4 AlertDialog (androidx.appcompat.app.AlertDialog)3