Search in sources :

Example 21 with ResultCode

use of org.prebid.mobile.ResultCode 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
// ================================================================================
}
Also used : ArrayList(java.util.ArrayList) NativeTitleAsset(org.prebid.mobile.NativeTitleAsset) NativeDataAsset(org.prebid.mobile.NativeDataAsset) NativeAdUnit(org.prebid.mobile.NativeAdUnit) OnCompleteListener(org.prebid.mobile.OnCompleteListener) NativeImageAsset(org.prebid.mobile.NativeImageAsset) NativeEventTracker(org.prebid.mobile.NativeEventTracker) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) ResultCode(org.prebid.mobile.ResultCode)

Example 22 with ResultCode

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

the class XandrNativeInBannerGamDemoActivity 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 NativeAdUnit(Constants.PBS_CONFIG_ID_NATIVE_APPNEXUS);
    FrameLayout adFrame = (FrameLayout) findViewById(R.id.adFrame);
    adFrame.removeAllViews();
    final AdManagerAdView nativeAdView = new AdManagerAdView(this);
    nativeAdView.setAdListener(new AdListener() {

        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            LogUtil.d("ad loaded");
        }
    });
    nativeAdView.setAdUnitId(Constants.DFP_IN_BANNER_NATIVE_ADUNIT_ID_APPNEXUS);
    nativeAdView.setAdSizes(AdSize.FLUID);
    adFrame.addView(nativeAdView);
    final AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
    NativeAdUnit nativeAdUnit = (NativeAdUnit) adUnit;
    nativeAdUnit.setContextType(NativeAdUnit.CONTEXT_TYPE.SOCIAL_CENTRIC);
    nativeAdUnit.setPlacementType(NativeAdUnit.PLACEMENTTYPE.CONTENT_FEED);
    nativeAdUnit.setContextSubType(NativeAdUnit.CONTEXTSUBTYPE.GENERAL_SOCIAL);
    ArrayList<NativeEventTracker.EVENT_TRACKING_METHOD> methods = new ArrayList<>();
    methods.add(NativeEventTracker.EVENT_TRACKING_METHOD.IMAGE);
    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);
    int millis = getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0);
    nativeAdUnit.setAutoRefreshPeriodMillis(millis);
    nativeAdUnit.fetchDemand(builder, new OnCompleteListener() {

        @Override
        public void onComplete(ResultCode resultCode) {
            AdManagerAdRequest request = builder.build();
            nativeAdView.loadAd(request);
        }
    });
}
Also used : ArrayList(java.util.ArrayList) NativeTitleAsset(org.prebid.mobile.NativeTitleAsset) NativeDataAsset(org.prebid.mobile.NativeDataAsset) NativeAdUnit(org.prebid.mobile.NativeAdUnit) AdListener(com.google.android.gms.ads.AdListener) OnCompleteListener(org.prebid.mobile.OnCompleteListener) AdManagerAdView(com.google.android.gms.ads.admanager.AdManagerAdView) NativeImageAsset(org.prebid.mobile.NativeImageAsset) FrameLayout(android.widget.FrameLayout) NativeEventTracker(org.prebid.mobile.NativeEventTracker) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) ResultCode(org.prebid.mobile.ResultCode)

Example 23 with ResultCode

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

the class RubiconBannerGamDemoActivity 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);
    String adSizeName = getIntent().getStringExtra(Constants.AD_SIZE_NAME);
    int width = 0;
    int height = 0;
    String[] wAndH = adSizeName.split("x");
    width = Integer.valueOf(wAndH[0]);
    height = Integer.valueOf(wAndH[1]);
    adUnit = new BannerAdUnit(Constants.PBS_CONFIG_ID_300x250_RUBICON, width, height);
    BannerBaseAdUnit.Parameters parameters = new BannerBaseAdUnit.Parameters();
    parameters.setApi(Arrays.asList(Signals.Api.MRAID_2));
    adUnit.setParameters(parameters);
    // pre GAM v20.0
    // final PublisherAdView amBanner = new PublisherAdView(this);
    final AdManagerAdView amBanner = new AdManagerAdView(this);
    amBanner.setAdUnitId(Constants.DFP_BANNER_ADUNIT_ID_300x250_RUBICON);
    amBanner.setAdSizes(new AdSize(width, height));
    FrameLayout adFrame = findViewById(R.id.adFrame);
    adFrame.removeAllViews();
    adFrame.addView(amBanner);
    amBanner.setAdListener(new AdListener() {

        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            AdViewUtils.findPrebidCreativeSize(amBanner, new AdViewUtils.PbFindSizeListener() {

                @Override
                public void success(int width, int height) {
                    amBanner.setAdSizes(new AdSize(width, height));
                }

                @Override
                public void failure(@NonNull PbFindSizeError error) {
                    Log.d("MyTag", "error: " + error);
                }
            });
        }
    });
    // pre GAM v20.0
    // final PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder();
    final AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
    // region PrebidMobile Mobile API 1.0 usage
    int millis = getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0);
    adUnit.setAutoRefreshPeriodMillis(millis);
    adUnit.fetchDemand(builder, new OnCompleteListener() {

        @Override
        public void onComplete(ResultCode resultCode) {
            // pre GAM v20.0
            // PublisherAdRequest request = builder.build();
            AdManagerAdRequest request = builder.build();
            amBanner.loadAd(request);
            refreshCount++;
            RubiconBannerGamDemoActivity.this.resultCode = resultCode;
        }
    });
}
Also used : PbFindSizeError(org.prebid.mobile.addendum.PbFindSizeError) BannerAdUnit(org.prebid.mobile.BannerAdUnit) AdListener(com.google.android.gms.ads.AdListener) OnCompleteListener(org.prebid.mobile.OnCompleteListener) AdManagerAdView(com.google.android.gms.ads.admanager.AdManagerAdView) BannerBaseAdUnit(org.prebid.mobile.BannerBaseAdUnit) AdSize(com.google.android.gms.ads.AdSize) FrameLayout(android.widget.FrameLayout) NonNull(androidx.annotation.NonNull) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) ResultCode(org.prebid.mobile.ResultCode)

Example 24 with ResultCode

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

the class RubiconBannerVideoGamDemoActivity 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_VAST_RUBICON);
    VideoBaseAdUnit.Parameters parameters = new VideoBaseAdUnit.Parameters();
    parameters.setMimes(Arrays.asList("video/mp4"));
    parameters.setProtocols(Arrays.asList(Signals.Protocols.VAST_2_0));
    // parameters.setProtocols(Arrays.asList(new Signals.Protocols(2)));
    parameters.setPlaybackMethod(Arrays.asList(Signals.PlaybackMethod.AutoPlaySoundOff));
    // parameters.setPlaybackMethod(Arrays.asList(new Signals.PlaybackMethod(2)));
    parameters.setPlacement(Signals.Placement.InBanner);
    // parameters.setPlacement(new Signals.Placement(2));
    VideoAdUnit adUnit = new VideoAdUnit("1001-1", 300, 250);
    adUnit.setParameters(parameters);
    this.adUnit = adUnit;
    final AdManagerAdView amBanner = new AdManagerAdView(this);
    amBanner.setAdUnitId(Constants.DFP_VAST_ADUNIT_ID_RUBICON);
    amBanner.setAdSizes(new AdSize(300, 250));
    FrameLayout adFrame = findViewById(R.id.adFrame);
    adFrame.removeAllViews();
    adFrame.addView(amBanner);
    amBanner.setAdListener(new AdListener() {

        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            AdViewUtils.findPrebidCreativeSize(amBanner, new AdViewUtils.PbFindSizeListener() {

                @Override
                public void success(int width, int height) {
                    amBanner.setAdSizes(new AdSize(width, height));
                }

                @Override
                public void failure(@NonNull PbFindSizeError error) {
                    Log.d("MyTag", "error: " + error);
                }
            });
        }
    });
    final AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
    // region PrebidMobile Mobile API 1.0 usage
    int millis = getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0);
    adUnit.setAutoRefreshPeriodMillis(millis);
    adUnit.fetchDemand(builder, new OnCompleteListener() {

        @Override
        public void onComplete(ResultCode resultCode) {
            AdManagerAdRequest request = builder.build();
            amBanner.loadAd(request);
        }
    });
}
Also used : PbFindSizeError(org.prebid.mobile.addendum.PbFindSizeError) VideoAdUnit(org.prebid.mobile.VideoAdUnit) AdListener(com.google.android.gms.ads.AdListener) OnCompleteListener(org.prebid.mobile.OnCompleteListener) AdManagerAdView(com.google.android.gms.ads.admanager.AdManagerAdView) AdSize(com.google.android.gms.ads.AdSize) FrameLayout(android.widget.FrameLayout) NonNull(androidx.annotation.NonNull) VideoBaseAdUnit(org.prebid.mobile.VideoBaseAdUnit) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) ResultCode(org.prebid.mobile.ResultCode)

Example 25 with ResultCode

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

the class RubiconInterstitialVideoGamDemoActivity 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_VAST_RUBICON);
    VideoBaseAdUnit.Parameters parameters = new VideoBaseAdUnit.Parameters();
    parameters.setMimes(Arrays.asList("video/mp4"));
    parameters.setProtocols(Arrays.asList(Signals.Protocols.VAST_2_0));
    // parameters.setProtocols(Arrays.asList(new Signals.Protocols(2)));
    parameters.setPlaybackMethod(Arrays.asList(Signals.PlaybackMethod.AutoPlaySoundOff));
    // parameters.setPlaybackMethod(Arrays.asList(new Signals.PlaybackMethod(2)));
    VideoInterstitialAdUnit adUnit = new VideoInterstitialAdUnit("1001-1");
    adUnit.setParameters(parameters);
    this.adUnit = adUnit;
    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(RubiconInterstitialVideoGamDemoActivity.this, Constants.DFP_VAST_ADUNIT_ID_RUBICON, request, new AdManagerInterstitialAdLoadCallback() {

                @Override
                public void onAdLoaded(@NonNull AdManagerInterstitialAd adManagerInterstitialAd) {
                    super.onAdLoaded(adManagerInterstitialAd);
                    adManagerInterstitialAd.show(RubiconInterstitialVideoGamDemoActivity.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(RubiconInterstitialVideoGamDemoActivity.this, android.R.style.Theme_Material_Dialog_Alert);
                    } else {
                        builder = new AlertDialog.Builder(RubiconInterstitialVideoGamDemoActivity.this);
                    }
                    builder.setTitle("Failed to load AdManager interstitial ad").setMessage("Error: " + loadAdError.toString()).setIcon(android.R.drawable.ic_dialog_alert).show();
                }
            });
        }
    });
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) LoadAdError(com.google.android.gms.ads.LoadAdError) VideoInterstitialAdUnit(org.prebid.mobile.VideoInterstitialAdUnit) AdManagerInterstitialAdLoadCallback(com.google.android.gms.ads.admanager.AdManagerInterstitialAdLoadCallback) AdManagerInterstitialAd(com.google.android.gms.ads.admanager.AdManagerInterstitialAd) OnCompleteListener(org.prebid.mobile.OnCompleteListener) NonNull(androidx.annotation.NonNull) VideoBaseAdUnit(org.prebid.mobile.VideoBaseAdUnit) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) ResultCode(org.prebid.mobile.ResultCode)

Aggregations

ResultCode (org.prebid.mobile.ResultCode)42 OnCompleteListener (org.prebid.mobile.OnCompleteListener)41 BannerAdUnit (org.prebid.mobile.BannerAdUnit)29 FrameLayout (android.widget.FrameLayout)27 Test (org.junit.Test)25 MoPubView (com.mopub.mobileads.MoPubView)23 AdManagerAdRequest (com.google.android.gms.ads.admanager.AdManagerAdRequest)14 MockResponse (okhttp3.mockwebserver.MockResponse)9 NonNull (androidx.annotation.NonNull)7 ArrayList (java.util.ArrayList)7 Matchers.containsString (org.hamcrest.Matchers.containsString)7 AdUnit (org.prebid.mobile.AdUnit)7 InterstitialAdUnit (org.prebid.mobile.InterstitialAdUnit)7 AdManagerAdView (com.google.android.gms.ads.admanager.AdManagerAdView)6 Dispatcher (okhttp3.mockwebserver.Dispatcher)6 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)6 AdListener (com.google.android.gms.ads.AdListener)5 LoadAdError (com.google.android.gms.ads.LoadAdError)5 VideoBaseAdUnit (org.prebid.mobile.VideoBaseAdUnit)5 AdSize (com.google.android.gms.ads.AdSize)4