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);
}
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);
}
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);
}
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();
}
}
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;
}
Aggregations