Search in sources :

Example 1 with NativeTitleAsset

use of org.prebid.mobile.NativeTitleAsset 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
    // ================================================================================
    }
}
Also used : MoPubNative(com.mopub.nativeads.MoPubNative) ArrayList(java.util.ArrayList) NativeTitleAsset(org.prebid.mobile.NativeTitleAsset) NativeDataAsset(org.prebid.mobile.NativeDataAsset) NativeAdUnit(org.prebid.mobile.NativeAdUnit) NativeErrorCode(com.mopub.nativeads.NativeErrorCode) MoPubStaticNativeAdRenderer(com.mopub.nativeads.MoPubStaticNativeAdRenderer) RequestParameters(com.mopub.nativeads.RequestParameters) OnCompleteListener(org.prebid.mobile.OnCompleteListener) StaticNativeAd(com.mopub.nativeads.StaticNativeAd) PrebidNativeAd(org.prebid.mobile.PrebidNativeAd) NativeAd(com.mopub.nativeads.NativeAd) NativeImageAsset(org.prebid.mobile.NativeImageAsset) NativeEventTracker(org.prebid.mobile.NativeEventTracker) PrebidNativeAdListener(org.prebid.mobile.PrebidNativeAdListener) PrebidNativeAd(org.prebid.mobile.PrebidNativeAd) ResultCode(org.prebid.mobile.ResultCode)

Example 2 with NativeTitleAsset

use of org.prebid.mobile.NativeTitleAsset 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 3 with NativeTitleAsset

use of org.prebid.mobile.NativeTitleAsset 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 4 with NativeTitleAsset

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

the class XandrNativeInBannerMoPubDemoActivity 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);
    final FrameLayout adFrame = (FrameLayout) findViewById(R.id.adFrame);
    adFrame.removeAllViews();
    final MoPubView adView = new MoPubView(this);
    adView.setAdUnitId(Constants.MOPUB_IN_BANNER_NATIVE_ADUNIT_ID_APPNEXUS);
    adView.setBannerAdListener(new MoPubView.BannerAdListener() {

        @Override
        public void onBannerLoaded(final MoPubView banner) {
            adFrame.addView(banner);
        }

        @Override
        public void onBannerFailed(MoPubView banner, MoPubErrorCode errorCode) {
            LogUtil.d("Banner failed " + errorCode);
        }

        @Override
        public void onBannerClicked(MoPubView banner) {
        }

        @Override
        public void onBannerExpanded(MoPubView banner) {
        }

        @Override
        public void onBannerCollapsed(MoPubView banner) {
        }
    });
    adView.setAutorefreshEnabled(false);
    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);
    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);
    int millis = getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0);
    nativeAdUnit.setAutoRefreshPeriodMillis(millis);
    nativeAdUnit.fetchDemand(adView, new OnCompleteListener() {

        @Override
        public void onComplete(ResultCode resultCode) {
            adView.loadAd(MoPubView.MoPubAdSize.MATCH_VIEW);
        }
    });
}
Also used : MoPubErrorCode(com.mopub.mobileads.MoPubErrorCode) 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) FrameLayout(android.widget.FrameLayout) NativeEventTracker(org.prebid.mobile.NativeEventTracker) ResultCode(org.prebid.mobile.ResultCode) MoPubView(com.mopub.mobileads.MoPubView)

Aggregations

ArrayList (java.util.ArrayList)4 NativeAdUnit (org.prebid.mobile.NativeAdUnit)4 NativeDataAsset (org.prebid.mobile.NativeDataAsset)4 NativeEventTracker (org.prebid.mobile.NativeEventTracker)4 NativeImageAsset (org.prebid.mobile.NativeImageAsset)4 NativeTitleAsset (org.prebid.mobile.NativeTitleAsset)4 OnCompleteListener (org.prebid.mobile.OnCompleteListener)4 ResultCode (org.prebid.mobile.ResultCode)4 FrameLayout (android.widget.FrameLayout)2 AdManagerAdRequest (com.google.android.gms.ads.admanager.AdManagerAdRequest)2 AdListener (com.google.android.gms.ads.AdListener)1 AdManagerAdView (com.google.android.gms.ads.admanager.AdManagerAdView)1 MoPubErrorCode (com.mopub.mobileads.MoPubErrorCode)1 MoPubView (com.mopub.mobileads.MoPubView)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