use of org.prebid.mobile.OnCompleteListener in project prebid-mobile-android by prebid.
the class XandrInterstitialGamDemoActivity 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);
adUnit = new InterstitialAdUnit(Constants.PBS_CONFIG_ID_INTERSTITIAL_APPNEXUS);
int millis = getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0);
adUnit.setAutoRefreshPeriodMillis(millis);
final AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
adUnit.fetchDemand(builder, new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
AdManagerAdRequest request = builder.build();
AdManagerInterstitialAd.load(XandrInterstitialGamDemoActivity.this, Constants.DFP_INTERSTITIAL_ADUNIT_ID_APPNEXUS, request, new AdManagerInterstitialAdLoadCallback() {
@Override
public void onAdLoaded(@NonNull AdManagerInterstitialAd adManagerInterstitialAd) {
super.onAdLoaded(adManagerInterstitialAd);
adManagerInterstitialAd.show(XandrInterstitialGamDemoActivity.this);
}
@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
super.onAdFailedToLoad(loadAdError);
AlertDialog.Builder builder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder = new AlertDialog.Builder(XandrInterstitialGamDemoActivity.this, android.R.style.Theme_Material_Dialog_Alert);
} else {
builder = new AlertDialog.Builder(XandrInterstitialGamDemoActivity.this);
}
builder.setTitle("Failed to load AdManager interstitial ad").setMessage("Error: " + loadAdError.toString()).setIcon(android.R.drawable.ic_dialog_alert).show();
}
});
}
});
}
use of org.prebid.mobile.OnCompleteListener in project prebid-mobile-android by prebid.
the class RubiconInterstitialGamDemoActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_demo);
PrebidMobile.setPrebidServerHost(Host.RUBICON);
PrebidMobile.setPrebidServerAccountId(Constants.PBS_ACCOUNT_ID_RUBICON);
PrebidMobile.setStoredAuctionResponse(Constants.PBS_STORED_RESPONSE_300x250_RUBICON);
adUnit = new InterstitialAdUnit(Constants.PBS_CONFIG_ID_INTERSTITIAL_RUBICON);
int millis = getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0);
adUnit.setAutoRefreshPeriodMillis(millis);
final AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
adUnit.fetchDemand(builder, new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
AdManagerAdRequest request = builder.build();
AdManagerInterstitialAd.load(RubiconInterstitialGamDemoActivity.this, Constants.DFP_INTERSTITIAL_ADUNIT_ID_RUBICON, request, new AdManagerInterstitialAdLoadCallback() {
@Override
public void onAdLoaded(@NonNull AdManagerInterstitialAd adManagerInterstitialAd) {
super.onAdLoaded(adManagerInterstitialAd);
adManagerInterstitialAd.show(RubiconInterstitialGamDemoActivity.this);
}
@Override
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
super.onAdFailedToLoad(loadAdError);
AlertDialog.Builder builder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder = new AlertDialog.Builder(RubiconInterstitialGamDemoActivity.this, android.R.style.Theme_Material_Dialog_Alert);
} else {
builder = new AlertDialog.Builder(RubiconInterstitialGamDemoActivity.this);
}
builder.setTitle("Failed to load AdManager interstitial ad").setMessage("Error: " + loadAdError.toString()).setIcon(android.R.drawable.ic_dialog_alert).show();
}
});
refreshCount++;
RubiconInterstitialGamDemoActivity.this.resultCode = resultCode;
}
});
}
use of org.prebid.mobile.OnCompleteListener in project prebid-mobile-android by prebid.
the class XandrInterstitialMoPubDemoActivity 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);
adUnit = new InterstitialAdUnit(Constants.PBS_CONFIG_ID_INTERSTITIAL_APPNEXUS);
final MoPubInterstitial mpInterstitial = new MoPubInterstitial(this, Constants.MOPUB_INTERSTITIAL_ADUNIT_ID_APPNEXUS);
mpInterstitial.setInterstitialAdListener(new MoPubInterstitial.InterstitialAdListener() {
@Override
public void onInterstitialLoaded(MoPubInterstitial interstitial) {
interstitial.show();
}
@Override
public void onInterstitialFailed(MoPubInterstitial interstitial, MoPubErrorCode errorCode) {
AlertDialog.Builder builder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder = new AlertDialog.Builder(XandrInterstitialMoPubDemoActivity.this, android.R.style.Theme_Material_Dialog_Alert);
} else {
builder = new AlertDialog.Builder(XandrInterstitialMoPubDemoActivity.this);
}
builder.setTitle("Failed to load MoPub interstitial ad").setMessage("Error code: " + errorCode.toString()).setIcon(android.R.drawable.ic_dialog_alert).show();
}
@Override
public void onInterstitialShown(MoPubInterstitial interstitial) {
}
@Override
public void onInterstitialClicked(MoPubInterstitial interstitial) {
}
@Override
public void onInterstitialDismissed(MoPubInterstitial interstitial) {
}
});
int millis = getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0);
adUnit.setAutoRefreshPeriodMillis(millis);
adUnit.fetchDemand(mpInterstitial, new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
mpInterstitial.load();
}
});
}
use of org.prebid.mobile.OnCompleteListener 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
// ================================================================================
}
}
use of org.prebid.mobile.OnCompleteListener in project prebid-mobile-android by prebid.
the class XandrNativeInAppGAMDemoActivity method loadInAppNative.
private void loadInAppNative() {
removePreviousAds();
PrebidMobile.setPrebidServerHost(Host.APPNEXUS);
PrebidMobile.setPrebidServerAccountId(Constants.PBS_ACCOUNT_ID_APPNEXUS);
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);
final AdManagerAdRequest adManagerAdRequest = new AdManagerAdRequest.Builder().build();
// Fetching the demannd using OnCompleteListener
nativeAdUnit.fetchDemand(adManagerAdRequest, new OnCompleteListener() {
@Override
public void onComplete(ResultCode resultCode) {
if (resultCode == ResultCode.SUCCESS) {
loadDfp(adManagerAdRequest);
} else {
Toast.makeText(XandrNativeInAppGAMDemoActivity.this, "Native Ad Unit: " + resultCode.name(), Toast.LENGTH_SHORT).show();
}
refreshCount++;
XandrNativeInAppGAMDemoActivity.this.resultCode = resultCode;
request = adManagerAdRequest;
}
});
// ================================================================================
// SAMPLE CODE: Fetching the demand using OnCompleteListener2
// ================================================================================
/*
nativeAdUnit.fetchDemand(new OnCompleteListener2() {
@Override
public void onComplete(ResultCode resultCode, Map<String, String> unmodifiableMap) {
if (resultCode == ResultCode.SUCCESS) {
final AdManagerAdRequest.Builder adManagerAdRequestBuilder = new AdManagerAdRequest.Builder();
for (String key: unmodifiableMap.keySet()) {
adManagerAdRequestBuilder.addCustomTargeting(key, unmodifiableMap.get(key));
}
loadDfp(adManagerAdRequestBuilder.build());
}
Toast.makeText(XandrNativeInAppGAMDemoActivity.this, "Native Ad Unit: " + resultCode.name(), Toast.LENGTH_SHORT).show();
}
});
*/
// ================================================================================
// SAMPLE CODE: END
// ================================================================================
}
Aggregations