Search in sources :

Example 6 with PrebidNativeAd

use of org.prebid.mobile.PrebidNativeAd 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)

Example 7 with PrebidNativeAd

use of org.prebid.mobile.PrebidNativeAd in project prebid-mobile-android by prebid.

the class GamUtilsTest method nativeAdProvider_putExtrasWithCacheId_returnNativeAd.

@Test
public void nativeAdProvider_putExtrasWithCacheId_returnNativeAd() {
    String cacheId = CacheManager.save(getNativeAdContent());
    Bundle extras = new Bundle();
    extras.putString(NativeAdUnit.BUNDLE_KEY_CACHE_ID, cacheId);
    PrebidNativeAd prebidNativeAd = NativeAdProvider.getNativeAd(extras);
    assertNotNull(prebidNativeAd);
}
Also used : Bundle(android.os.Bundle) PrebidNativeAd(org.prebid.mobile.PrebidNativeAd) Test(org.junit.Test)

Example 8 with PrebidNativeAd

use of org.prebid.mobile.PrebidNativeAd in project prebid-mobile-android by prebid.

the class PrebidNativeAdapter method requestNativeAd.

@Override
public void requestNativeAd(@NonNull Context context, @NonNull CustomEventNativeListener adMobListener, @Nullable String serverParameter, @NonNull NativeMediationAdRequest mediationAdRequest, @Nullable Bundle extras) {
    if (extras == null) {
        String error = "Extras are empty! Check if you add custom event extras bundle to  " + TAG;
        Log.e(TAG, error);
        adMobListener.onAdFailedToLoad(new AdError(1001, error, "prebid"));
        return;
    }
    String cacheId = extras.getString(NativeAdUnit.BUNDLE_KEY_CACHE_ID);
    if (cacheId == null) {
        String error = "Cache id is null";
        adMobListener.onAdFailedToLoad(new AdError(1002, error, "prebid"));
        return;
    }
    Bundle extrasCopy = new Bundle(extras);
    extrasCopy.remove(NativeAdUnit.BUNDLE_KEY_CACHE_ID);
    HashMap<String, String> prebidParameters = convertToMap(extrasCopy);
    if (!ParametersMatcher.doParametersMatch(serverParameter, prebidParameters)) {
        String error = "Parameters are different";
        adMobListener.onAdFailedToLoad(new AdError(1003, error, "prebid"));
        return;
    }
    LogUtil.v(TAG, "Parameters are matched! (" + serverParameter + ")");
    PrebidNativeAd nativeAd = PrebidNativeAd.create(cacheId);
    if (nativeAd == null) {
        String error = "PrebidNativeAd is null";
        adMobListener.onAdFailedToLoad(new AdError(1004, error, "prebid"));
        return;
    }
    PrebidNativeAdMapper mapper = new PrebidNativeAdMapper(nativeAd, adMobListener);
    configureMapper(mapper, nativeAd, context);
    adMobListener.onAdLoaded(mapper);
}
Also used : Bundle(android.os.Bundle) PrebidNativeAd(org.prebid.mobile.PrebidNativeAd) AdError(com.google.android.gms.ads.AdError)

Example 9 with PrebidNativeAd

use of org.prebid.mobile.PrebidNativeAd in project prebid-mobile-android by prebid.

the class PbFindSizeErrorFactory method findNativeInMoPubNativeAd.

private static void findNativeInMoPubNativeAd(@NonNull Object object, @NonNull PrebidNativeAdListener listener) {
    Object baseNativeAd = callMethodOnObject(object, "getBaseNativeAd");
    LogUtil.d("Prebid", "" + baseNativeAd);
    Boolean isPrebid = (Boolean) callMethodOnObject(baseNativeAd, "getExtra", "isPrebid");
    if (isPrebid != null && isPrebid) {
        String cacheId = (String) callMethodOnObject(baseNativeAd, "getExtra", "hb_cache_id_local");
        if (CacheManager.isValid(cacheId)) {
            PrebidNativeAd ad = createPrebidNativeAd(cacheId, listener);
            if (ad != null) {
                listener.onPrebidNativeLoaded(ad);
                return;
            }
        } else {
            listener.onPrebidNativeNotValid();
        }
    } else {
        listener.onPrebidNativeNotFound();
    }
}
Also used : PrebidNativeAd(org.prebid.mobile.PrebidNativeAd)

Example 10 with PrebidNativeAd

use of org.prebid.mobile.PrebidNativeAd in project prebid-mobile-android by prebid.

the class NativeAdProvider method getNativeAd.

@Nullable
public static PrebidNativeAd getNativeAd(@NonNull Bundle extras) {
    String cacheId = extras.getString(NativeAdUnit.BUNDLE_KEY_CACHE_ID);
    if (cacheId == null || cacheId.isEmpty()) {
        LogUtil.error(TAG, "Cache id is null, can't get native ad.");
        return null;
    }
    PrebidNativeAd nativeAd = PrebidNativeAd.create(cacheId);
    if (nativeAd == null) {
        LogUtil.error(TAG, "PrebidNativeAd is null");
        return null;
    }
    return nativeAd;
}
Also used : PrebidNativeAd(org.prebid.mobile.PrebidNativeAd) Nullable(androidx.annotation.Nullable)

Aggregations

PrebidNativeAd (org.prebid.mobile.PrebidNativeAd)10 Bundle (android.os.Bundle)3 Test (org.junit.Test)2 PrebidNativeAdListener (org.prebid.mobile.PrebidNativeAdListener)2 FrameLayout (android.widget.FrameLayout)1 Nullable (androidx.annotation.Nullable)1 AdError (com.google.android.gms.ads.AdError)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 NativeCustomTemplateAd (com.google.android.gms.ads.formats.NativeCustomTemplateAd)1 OnAdManagerAdViewLoadedListener (com.google.android.gms.ads.formats.OnAdManagerAdViewLoadedListener)1 UnifiedNativeAd (com.google.android.gms.ads.formats.UnifiedNativeAd)1 MoPubNative (com.mopub.nativeads.MoPubNative)1 MoPubStaticNativeAdRenderer (com.mopub.nativeads.MoPubStaticNativeAdRenderer)1 NativeAd (com.mopub.nativeads.NativeAd)1 NativeErrorCode (com.mopub.nativeads.NativeErrorCode)1 RequestParameters (com.mopub.nativeads.RequestParameters)1 StaticNativeAd (com.mopub.nativeads.StaticNativeAd)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1