Search in sources :

Example 11 with MoPubInterstitial

use of com.mopub.mobileads.MoPubInterstitial 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();
        }
    });
}
Also used : MoPubErrorCode(com.mopub.mobileads.MoPubErrorCode) OnCompleteListener(org.prebid.mobile.OnCompleteListener) MoPubInterstitial(com.mopub.mobileads.MoPubInterstitial) ResultCode(org.prebid.mobile.ResultCode) InterstitialAdUnit(org.prebid.mobile.InterstitialAdUnit)

Example 12 with MoPubInterstitial

use of com.mopub.mobileads.MoPubInterstitial in project prebid-mobile-android by prebid.

the class RubiconInterstitialMoPubDemoActivity 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);
    final MoPubInterstitial mpInterstitial = new MoPubInterstitial(this, Constants.MOPUB_INTERSTITIAL_ADUNIT_ID_RUBICON);
    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(RubiconInterstitialMoPubDemoActivity.this, android.R.style.Theme_Material_Dialog_Alert);
            } else {
                builder = new AlertDialog.Builder(RubiconInterstitialMoPubDemoActivity.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();
            refreshCount++;
            RubiconInterstitialMoPubDemoActivity.this.resultCode = resultCode;
        }
    });
}
Also used : MoPubErrorCode(com.mopub.mobileads.MoPubErrorCode) OnCompleteListener(org.prebid.mobile.OnCompleteListener) MoPubInterstitial(com.mopub.mobileads.MoPubInterstitial) ResultCode(org.prebid.mobile.ResultCode) InterstitialAdUnit(org.prebid.mobile.InterstitialAdUnit)

Example 13 with MoPubInterstitial

use of com.mopub.mobileads.MoPubInterstitial in project prebid-mobile-android by prebid.

the class RubiconInterstitialVideoMoPubDemoActivity 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;
    final MoPubInterstitial mpInterstitial = new MoPubInterstitial(this, Constants.MOPUB_INTERSTITIAL_VIDEO_ADUNIT_ID_RUBICON);
    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(RubiconInterstitialVideoMoPubDemoActivity.this, android.R.style.Theme_Material_Dialog_Alert);
            } else {
                builder = new AlertDialog.Builder(RubiconInterstitialVideoMoPubDemoActivity.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();
        }
    });
}
Also used : MoPubErrorCode(com.mopub.mobileads.MoPubErrorCode) OnCompleteListener(org.prebid.mobile.OnCompleteListener) MoPubInterstitial(com.mopub.mobileads.MoPubInterstitial) VideoInterstitialAdUnit(org.prebid.mobile.VideoInterstitialAdUnit) VideoBaseAdUnit(org.prebid.mobile.VideoBaseAdUnit) ResultCode(org.prebid.mobile.ResultCode)

Example 14 with MoPubInterstitial

use of com.mopub.mobileads.MoPubInterstitial in project prebid-mobile-android by prebid.

the class AdServerTest method startTest.

public void startTest() {
    GeneralSettings generalSettings = SettingsManager.getInstance(mContext).getGeneralSettings();
    AdServerSettings adServerSettings = SettingsManager.getInstance(mContext).getAdServerSettings();
    PrebidServerSettings prebidServerSettings = SettingsManager.getInstance(mContext).getPrebidServerSettings();
    switch(generalSettings.getAdSize()) {
        case BANNER_300x250:
            break;
        case BANNER_300x600:
            break;
        case BANNER_320x50:
            break;
        case BANNER_320x100:
            break;
        case BANNER_320x480:
            break;
        case BANNER_728x90:
            break;
    }
    mKeywords = createMapKeywords(adServerSettings.getBidPrice(), generalSettings.getAdSize(), generalSettings.getAdFormat(), prebidServerSettings.getPrebidServer());
    if (adServerSettings.getAdServer() == AdServer.MOPUB) {
        String keywords = createStringKeywords();
        if (generalSettings.getAdFormat() == AdFormat.BANNER) {
            AdSize adSize = generalSettings.getAdSize();
            FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(DimenUtil.convertPxToDp(mContext, adSize.getWidth()), DimenUtil.convertPxToDp(mContext, adSize.getHeight()));
            mMoPubAd = new MoPubView(mContext);
            mMoPubAd.setLayoutParams(layoutParams);
            mMoPubAd.setAdUnitId(adServerSettings.getAdUnitId());
            mMoPubAd.setAutorefreshEnabled(false);
            mMoPubAd.setBannerAdListener(this);
            mMoPubAd.setKeywords(keywords);
            Networking.getRequestQueue(mContext).addRequestFinishedListener(mMoPubRequestFinishedListener);
            mMoPubAd.loadAd();
        } else if (generalSettings.getAdFormat() == AdFormat.INTERSTITIAL) {
            mMoPubInterstitial = new MoPubInterstitial(mContext, adServerSettings.getAdUnitId());
            mMoPubInterstitial.setInterstitialAdListener(this);
            mMoPubInterstitial.setKeywords(keywords);
            Networking.getRequestQueue(mContext).addRequestFinishedListener(mMoPubRequestFinishedListener);
            mMoPubInterstitial.load();
        }
    } else if (adServerSettings.getAdServer() == AdServer.GOOGLE_AD_MANAGER) {
        PublisherAdRequest adRequest = null;
        if (generalSettings.getAdFormat() == AdFormat.BANNER) {
            mGoogleAd = new PublisherAdView(mContext);
            AdSize adSize = generalSettings.getAdSize();
            mGoogleAd.setAdSizes(new com.google.android.gms.ads.AdSize(adSize.getWidth(), adSize.getHeight()));
            mGoogleAd.setAdUnitId(adServerSettings.getAdUnitId());
            mGoogleAd.setAdListener(mGoogleBannerListener);
        } else if (generalSettings.getAdFormat() == AdFormat.INTERSTITIAL) {
            mGoogleInterstitial = new PublisherInterstitialAd(mContext);
            mGoogleInterstitial.setAdUnitId(adServerSettings.getAdUnitId());
            mGoogleInterstitial.setAdListener(mGoogleInterstitialListener);
        }
        PublisherAdRequest.Builder adRequestBuilder = new PublisherAdRequest.Builder();
        for (String key : mKeywords.keySet()) {
            if (mKeywords.containsKey(key)) {
                adRequestBuilder.addCustomTargeting(key, mKeywords.get(key));
            }
        }
        adRequest = adRequestBuilder.build();
        if (generalSettings.getAdFormat() == AdFormat.BANNER) {
            mGoogleAd.loadAd(adRequest);
        } else if (generalSettings.getAdFormat() == AdFormat.INTERSTITIAL) {
            mGoogleInterstitial.loadAd(adRequest);
        }
        checkRequestForKeywordsAM(adRequest);
    }
}
Also used : PrebidServerSettings(org.prebid.mobile.drprebid.model.PrebidServerSettings) MoPubInterstitial(com.mopub.mobileads.MoPubInterstitial) AdServerSettings(org.prebid.mobile.drprebid.model.AdServerSettings) GeneralSettings(org.prebid.mobile.drprebid.model.GeneralSettings) PublisherAdView(com.google.android.gms.ads.doubleclick.PublisherAdView) AdSize(org.prebid.mobile.drprebid.model.AdSize) FrameLayout(android.widget.FrameLayout) PublisherAdRequest(com.google.android.gms.ads.doubleclick.PublisherAdRequest) PublisherInterstitialAd(com.google.android.gms.ads.doubleclick.PublisherInterstitialAd) MoPubView(com.mopub.mobileads.MoPubView)

Example 15 with MoPubInterstitial

use of com.mopub.mobileads.MoPubInterstitial in project prebid-mobile-android by prebid.

the class UtilTest method testSupportedAdObject.

@Test
public void testSupportedAdObject() throws Exception {
    MoPubView testView = new MoPubView(activity);
    assertTrue(Util.supportedAdObject(testView));
    assertFalse(Util.supportedAdObject(null));
    MoPubInterstitial interstitial = new MoPubInterstitial(activity, "");
    assertTrue(Util.supportedAdObject(interstitial));
    AdManagerAdRequest request = new AdManagerAdRequest.Builder().build();
    assertTrue(Util.supportedAdObject(request));
    AdManagerAdRequest.Builder requestBuilder = new AdManagerAdRequest.Builder();
    assertTrue(Util.supportedAdObject(requestBuilder));
    Object object = new Object();
    assertFalse(Util.supportedAdObject(object));
}
Also used : MoPubInterstitial(com.mopub.mobileads.MoPubInterstitial) JSONObject(org.json.JSONObject) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) MoPubView(com.mopub.mobileads.MoPubView) Test(org.junit.Test)

Aggregations

MoPubInterstitial (com.mopub.mobileads.MoPubInterstitial)15 MoPubView (com.mopub.mobileads.MoPubView)5 MoPubErrorCode (com.mopub.mobileads.MoPubErrorCode)4 Test (org.junit.Test)4 InterstitialAdUnit (org.prebid.mobile.InterstitialAdUnit)4 FrameLayout (android.widget.FrameLayout)3 HashMap (java.util.HashMap)3 OnCompleteListener (org.prebid.mobile.OnCompleteListener)3 ResultCode (org.prebid.mobile.ResultCode)3 View (android.view.View)2 PublisherAdRequest (com.google.android.gms.ads.doubleclick.PublisherAdRequest)2 PublisherAdView (com.google.android.gms.ads.doubleclick.PublisherAdView)2 PublisherInterstitialAd (com.google.android.gms.ads.doubleclick.PublisherInterstitialAd)2 AdUnit (org.prebid.mobile.AdUnit)2 BannerAdUnit (org.prebid.mobile.BannerAdUnit)2 Activity (android.app.Activity)1 Context (android.content.Context)1 Uri (android.net.Uri)1 Nullable (android.support.annotation.Nullable)1 TextUtils (android.text.TextUtils)1