Search in sources :

Example 6 with NativeCustomTemplateAd

use of com.google.android.gms.ads.formats.NativeCustomTemplateAd in project prebid-mobile-android by prebid.

the class UtilTest method testFindNativeLoadedDFP.

@Test
public void testFindNativeLoadedDFP() {
    String mockedResponse = MockPrebidServerResponses.validResponsePrebidNativeNativeBid();
    String cacheId = CacheManager.save(mockedResponse);
    NativeCustomTemplateAd nativeCustomTemplateAd = Mockito.mock(NativeCustomTemplateAd.class);
    Mockito.when(nativeCustomTemplateAd.getText("isPrebid")).thenReturn("1");
    Mockito.when(nativeCustomTemplateAd.getText("hb_cache_id_local")).thenReturn(cacheId);
    AdViewUtils.findNative(nativeCustomTemplateAd, new PrebidNativeAdListener() {

        @Override
        public void onPrebidNativeLoaded(PrebidNativeAd ad) {
            assertTrue(ad != null);
        }

        @Override
        public void onPrebidNativeNotFound() {
            fail();
        }

        @Override
        public void onPrebidNativeNotValid() {
            fail();
        }
    });
}
Also used : NativeCustomTemplateAd(com.google.android.gms.ads.formats.NativeCustomTemplateAd) Test(org.junit.Test)

Example 7 with NativeCustomTemplateAd

use of com.google.android.gms.ads.formats.NativeCustomTemplateAd in project prebid-mobile-android by prebid.

the class XandrNativeInAppGAMDemoActivity method loadDfp.

private void loadDfp(AdManagerAdRequest adManagerAdRequest) {
    adLoader = new AdLoader.Builder(this, DFP_NATIVE_NATIVE_ADUNIT_ID_APPNEXUS).forAdManagerAdView(new OnAdManagerAdViewLoadedListener() {

        @Override
        public void onAdManagerAdViewLoaded(AdManagerAdView adManagerAdView) {
            adView = adManagerAdView;
            ((FrameLayout) findViewById(R.id.adFrame)).addView(adManagerAdView);
        }
    }, AdSize.BANNER).forUnifiedNativeAd(new UnifiedNativeAd.OnUnifiedNativeAdLoadedListener() {

        @Override
        public void onUnifiedNativeAdLoaded(UnifiedNativeAd unifiedNativeAd) {
            LogUtil.d("Prebid", "native loaded");
            XandrNativeInAppGAMDemoActivity.this.unifiedNativeAd = unifiedNativeAd;
        }
    }).forCustomTemplateAd("11963183", new NativeCustomTemplateAd.OnCustomTemplateAdLoadedListener() {

        @Override
        public void onCustomTemplateAdLoaded(NativeCustomTemplateAd nativeCustomTemplateAd) {
            LogUtil.d("Prebid", "custom ad loaded");
            AdViewUtils.findNative(nativeCustomTemplateAd, new PrebidNativeAdListener() {

                @Override
                public void onPrebidNativeLoaded(PrebidNativeAd ad) {
                    inflatePrebidNativeAd(ad);
                }

                @Override
                public void onPrebidNativeNotFound() {
                    LogUtil.d("Prebid", "onPrebidNativeNotFound");
                // inflate nativeCustomTemplateAd
                }

                @Override
                public void onPrebidNativeNotValid() {
                    LogUtil.d("Prebid", "onPrebidNativeNotFound");
                // show your own content
                }
            });
        }
    }, new NativeCustomTemplateAd.OnCustomClickListener() {

        @Override
        public void onCustomClick(NativeCustomTemplateAd nativeCustomTemplateAd, String s) {
        }
    }).withAdListener(new AdListener() {

        @Override
        public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
            super.onAdFailedToLoad(loadAdError);
            Toast.makeText(XandrNativeInAppGAMDemoActivity.this, "DFP onAdFailedToLoad", Toast.LENGTH_SHORT).show();
        }
    }).build();
    adLoader.loadAd(adManagerAdRequest);
}
Also used : LoadAdError(com.google.android.gms.ads.LoadAdError) AdListener(com.google.android.gms.ads.AdListener) PrebidNativeAdListener(org.prebid.mobile.PrebidNativeAdListener) NativeCustomTemplateAd(com.google.android.gms.ads.formats.NativeCustomTemplateAd) AdManagerAdView(com.google.android.gms.ads.admanager.AdManagerAdView) FrameLayout(android.widget.FrameLayout) PrebidNativeAdListener(org.prebid.mobile.PrebidNativeAdListener) OnAdManagerAdViewLoadedListener(com.google.android.gms.ads.formats.OnAdManagerAdViewLoadedListener) PrebidNativeAd(org.prebid.mobile.PrebidNativeAd) UnifiedNativeAd(com.google.android.gms.ads.formats.UnifiedNativeAd)

Aggregations

NativeCustomTemplateAd (com.google.android.gms.ads.formats.NativeCustomTemplateAd)7 Test (org.junit.Test)6 Field (java.lang.reflect.Field)3 HttpUrl (okhttp3.HttpUrl)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 BackgroundThreadExecutor (org.prebid.mobile.tasksmanager.BackgroundThreadExecutor)3 ShadowLooper (org.robolectric.shadows.ShadowLooper)3 View (android.view.View)2 FrameLayout (android.widget.FrameLayout)1 AdListener (com.google.android.gms.ads.AdListener)1 LoadAdError (com.google.android.gms.ads.LoadAdError)1 AdManagerAdView (com.google.android.gms.ads.admanager.AdManagerAdView)1 OnAdManagerAdViewLoadedListener (com.google.android.gms.ads.formats.OnAdManagerAdViewLoadedListener)1 UnifiedNativeAd (com.google.android.gms.ads.formats.UnifiedNativeAd)1 PrebidNativeAd (org.prebid.mobile.PrebidNativeAd)1 PrebidNativeAdListener (org.prebid.mobile.PrebidNativeAdListener)1