use of org.prebid.mobile.PrebidNativeAd in project prebid-mobile-android by prebid.
the class PbFindSizeErrorFactory method createPrebidNativeAd.
private static PrebidNativeAd createPrebidNativeAd(String cacheId, PrebidNativeAdListener listener) {
Class clazz = null;
try {
clazz = Class.forName("org.prebid.mobile.PrebidNativeAd");
Method method = clazz.getDeclaredMethod("create", String.class);
method.setAccessible(true);
return (PrebidNativeAd) method.invoke(null, cacheId);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of org.prebid.mobile.PrebidNativeAd in project prebid-mobile-android by prebid.
the class PbFindSizeErrorFactory method findNativeInGAMCustomTemplateAd.
private static void findNativeInGAMCustomTemplateAd(@NonNull Object object, @NonNull PrebidNativeAdListener listener) {
String isPrebid = (String) callMethodOnObject(object, "getText", "isPrebid");
if ("1".equals(isPrebid)) {
String cacheId = (String) callMethodOnObject(object, "getText", "hb_cache_id_local");
PrebidNativeAd ad = createPrebidNativeAd(cacheId, listener);
if (ad != null) {
listener.onPrebidNativeLoaded(ad);
} else {
listener.onPrebidNativeNotValid();
}
} else {
listener.onPrebidNativeNotFound();
}
}
use of org.prebid.mobile.PrebidNativeAd in project prebid-mobile-android by prebid.
the class PrebidNativeAdapter method loadNativeAd.
@Override
protected void loadNativeAd(@NonNull Context context, @NonNull CustomEventNativeListener moPubListener, @NonNull Map<String, Object> localExtras, @NonNull Map<String, String> serverExtras) {
Object bidResponseObj = localExtras.get(MoPubBaseMediationUtils.KEY_BID_RESPONSE);
if (!(bidResponseObj instanceof String)) {
moPubListener.onNativeAdFailed(NativeErrorCode.NATIVE_ADAPTER_CONFIGURATION_ERROR);
return;
}
String cacheId = (String) bidResponseObj;
PrebidNativeAd nativeAd = PrebidNativeAd.create(cacheId);
if (nativeAd == null) {
moPubListener.onNativeAdFailed(NativeErrorCode.EMPTY_AD_RESPONSE);
return;
}
PrebidNativeAdWrapper mapper = new PrebidNativeAdWrapper(nativeAd);
moPubListener.onNativeAdLoaded(mapper);
}
use of org.prebid.mobile.PrebidNativeAd in project prebid-mobile-android by prebid.
the class GamUtilsTest method nativeAdProvider_putEmptyExtras_returnNull.
@Test
public void nativeAdProvider_putEmptyExtras_returnNull() {
Bundle extras = new Bundle();
PrebidNativeAd prebidNativeAd = NativeAdProvider.getNativeAd(extras);
assertNull(prebidNativeAd);
}
use of org.prebid.mobile.PrebidNativeAd in project prebid-mobile-android by prebid.
the class XandrNativeInAppMoPubDemoActivity method loadInAppNativeMopub.
// Mopub
private void loadInAppNativeMopub() {
{
removePreviousAds();
PrebidMobile.setPrebidServerHost(Host.APPNEXUS);
PrebidMobile.setPrebidServerAccountId(Constants.PBS_ACCOUNT_ID_APPNEXUS);
final NativeAdUnit nativeAdUnit = new NativeAdUnit(Constants.PBS_CONFIG_ID_NATIVE_APPNEXUS);
nativeAdUnit.setContextType(NativeAdUnit.CONTEXT_TYPE.SOCIAL_CENTRIC);
nativeAdUnit.setPlacementType(NativeAdUnit.PLACEMENTTYPE.CONTENT_FEED);
nativeAdUnit.setContextSubType(NativeAdUnit.CONTEXTSUBTYPE.GENERAL_SOCIAL);
adUnit = nativeAdUnit;
ArrayList<NativeEventTracker.EVENT_TRACKING_METHOD> methods = new ArrayList<>();
methods.add(NativeEventTracker.EVENT_TRACKING_METHOD.IMAGE);
methods.add(NativeEventTracker.EVENT_TRACKING_METHOD.JS);
try {
NativeEventTracker tracker = new NativeEventTracker(NativeEventTracker.EVENT_TYPE.IMPRESSION, methods);
nativeAdUnit.addEventTracker(tracker);
} catch (Exception e) {
e.printStackTrace();
}
NativeTitleAsset title = new NativeTitleAsset();
title.setLength(90);
title.setRequired(true);
nativeAdUnit.addAsset(title);
NativeImageAsset icon = new NativeImageAsset();
icon.setImageType(NativeImageAsset.IMAGE_TYPE.ICON);
icon.setWMin(20);
icon.setHMin(20);
icon.setRequired(true);
nativeAdUnit.addAsset(icon);
NativeImageAsset image = new NativeImageAsset();
image.setImageType(NativeImageAsset.IMAGE_TYPE.MAIN);
image.setHMin(200);
image.setWMin(200);
image.setRequired(true);
nativeAdUnit.addAsset(image);
NativeDataAsset data = new NativeDataAsset();
data.setLen(90);
data.setDataType(NativeDataAsset.DATA_TYPE.SPONSORED);
data.setRequired(true);
nativeAdUnit.addAsset(data);
NativeDataAsset body = new NativeDataAsset();
body.setRequired(true);
body.setDataType(NativeDataAsset.DATA_TYPE.DESC);
nativeAdUnit.addAsset(body);
NativeDataAsset cta = new NativeDataAsset();
cta.setRequired(true);
cta.setDataType(NativeDataAsset.DATA_TYPE.CTATEXT);
nativeAdUnit.addAsset(cta);
moPubNative = new MoPubNative(XandrNativeInAppMoPubDemoActivity.this, "2674981035164b2db5ef4b4546bf3d49", new MoPubNative.MoPubNativeNetworkListener() {
@Override
public void onNativeLoad(final NativeAd nativeAd) {
Log.d("Prebid", "MoPub native ad loaded");
XandrNativeInAppMoPubDemoActivity.this.ad = nativeAd;
AdViewUtils.findNative(nativeAd, new PrebidNativeAdListener() {
@Override
public void onPrebidNativeLoaded(final PrebidNativeAd ad) {
inflatePrebidNativeAd(ad);
}
@Override
public void onPrebidNativeNotFound() {
inflateMoPubNativeAd(nativeAd);
}
@Override
public void onPrebidNativeNotValid() {
Log.e("ERROR", "onPrebidNativeNotValid");
// should not show the NativeAd on the screen, do something else
}
});
}
@Override
public void onNativeFail(NativeErrorCode errorCode) {
Log.d("Prebid", "MoPub native failed to load: " + errorCode.toString());
}
});
moPubNative.registerAdRenderer(new MoPubStaticNativeAdRenderer(null));
RequestParameters.Builder mRP = new RequestParameters.Builder();
// Fetching the demannd using OnCompleteListener
nativeAdUnit.fetchDemand(mRP, new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
if (resultCode == ResultCode.SUCCESS) {
moPubNative.makeRequest(mRP.build());
} else {
Toast.makeText(XandrNativeInAppMoPubDemoActivity.this, "Native Ad Unit: " + resultCode.name(), Toast.LENGTH_SHORT).show();
}
refreshCount++;
XandrNativeInAppMoPubDemoActivity.this.resultCode = resultCode;
request = mRP.build();
}
});
// ================================================================================
// SAMPLE CODE: Fetching the demand using OnCompleteListener2
// ================================================================================
/*
nativeAdUnit.fetchDemand(new OnCompleteListener2() {
@Override
public void onComplete(ResultCode resultCode, Map<String, String> unmodifiableMap) {
Log.e("MAP", unmodifiableMap.toString());
if (resultCode == ResultCode.SUCCESS) {
String keywords = "";
for (String key: unmodifiableMap.keySet()) {
keywords += key + ":" + unmodifiableMap.get(key) + ",";
}
// removing last ","
keywords = keywords.substring(0, keywords.length()-1);
RequestParameters mRP = new RequestParameters.Builder().keywords(keywords).build();
Log.d("Prebid", mRP.getKeywords());
mMoPubNative.makeRequest(mRP);
}
Toast.makeText(XandrNativeInAppMoPubDemoActivity.this, "Native Ad Unit: " + resultCode.name(), Toast.LENGTH_SHORT).show();
}
});
*/
// ================================================================================
// SAMPLE CODE: END
// ================================================================================
}
}
Aggregations