Search in sources :

Example 16 with BannerAdUnit

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

the class SdkTest method setupPrebid.

private void setupPrebid() {
    GeneralSettings generalSettings = SettingsManager.getInstance(mContext).getGeneralSettings();
    PrebidServerSettings prebidServerSettings = SettingsManager.getInstance(mContext).getPrebidServerSettings();
    setPrebidTargetingParams();
    if (generalSettings.getAdFormat() == AdFormat.BANNER) {
        AdSize adSize = generalSettings.getAdSize();
        mAdUnit = new BannerAdUnit(prebidServerSettings.getConfigId(), adSize.getWidth(), adSize.getHeight());
    } else if (generalSettings.getAdFormat() == AdFormat.INTERSTITIAL) {
        mAdUnit = new InterstitialAdUnit(prebidServerSettings.getConfigId());
    }
    PrebidMobile.setPrebidServerAccountId(prebidServerSettings.getAccountId());
    switch(prebidServerSettings.getPrebidServer()) {
        case APPNEXUS:
            PrebidMobile.setPrebidServerHost(Host.APPNEXUS);
            break;
        case RUBICON:
            PrebidMobile.setPrebidServerHost(Host.RUBICON);
            break;
        case CUSTOM:
            PrebidMobile.setPrebidServerHost(Host.CUSTOM);
            Host.CUSTOM.setHostUrl(buildCustomServerEndpoint(prebidServerSettings.getCustomPrebidServerUrl()));
            break;
    }
    if (mListener != null) {
        mListener.onAdUnitRegistered();
    }
}
Also used : PrebidServerSettings(org.prebid.mobile.drprebid.model.PrebidServerSettings) AdSize(org.prebid.mobile.drprebid.model.AdSize) GeneralSettings(org.prebid.mobile.drprebid.model.GeneralSettings) BannerAdUnit(org.prebid.mobile.BannerAdUnit) InterstitialAdUnit(org.prebid.mobile.InterstitialAdUnit)

Example 17 with BannerAdUnit

use of org.prebid.mobile.BannerAdUnit 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 18 with BannerAdUnit

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

the class XandrBannerGamDemoActivity 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);
    BannerAdUnit adUnit = new BannerAdUnit(Constants.PBS_CONFIG_ID_300x250_APPNEXUS, 300, 250);
    BannerBaseAdUnit.Parameters parameters = new BannerBaseAdUnit.Parameters();
    parameters.setApi(Arrays.asList(Signals.Api.MRAID_2));
    // parameters.setApi(Arrays.asList(new Signals.Api(5)));
    adUnit.setParameters(parameters);
    this.adUnit = adUnit;
    // Util.enableAdditionalFunctionality(this.adUnit);
    final AdManagerAdView amBanner = new AdManagerAdView(this);
    amBanner.setAdUnitId(Constants.DFP_BANNER_ADUNIT_ID_ALL_SIZES_APPNEXUS);
    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) 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 19 with BannerAdUnit

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

the class ExtraTests method testRubiconEmptyInvalidPrebidServerConfigId.

@Test
public void testRubiconEmptyInvalidPrebidServerConfigId() throws Exception {
    PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("1001");
    PrebidMobile.setPrebidServerHost(Host.RUBICON);
    PrebidMobile.setShareGeoLocation(true);
    final OnCompleteListener[] listener = new OnCompleteListener[1];
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            final MoPubView adObject = new MoPubView(m.getActivity());
            adObject.setAdUnitId(Constants.MOPUB_BANNER_ADUNIT_ID_300x250_RUBICON);
            adObject.setMinimumHeight(250);
            adObject.setMinimumWidth(300);
            BannerAdUnit adUnit = new BannerAdUnit("", 300, 250);
            OnCompleteListener l = new OnCompleteListener() {

                @Override
                public void onComplete(ResultCode resultCode) {
                    FrameLayout adFrame = m.getActivity().findViewById(R.id.adFrame);
                    adFrame.addView(adObject);
                    adObject.loadAd();
                }
            };
            listener[0] = spy(l);
            adUnit.fetchDemand(adObject, listener[0]);
        }
    });
    Thread.sleep(2000);
    verify(listener[0], times(1)).onComplete(ResultCode.INVALID_CONFIG_ID);
}
Also used : OnCompleteListener(org.prebid.mobile.OnCompleteListener) FrameLayout(android.widget.FrameLayout) ResultCode(org.prebid.mobile.ResultCode) MoPubView(com.mopub.mobileads.MoPubView) BannerAdUnit(org.prebid.mobile.BannerAdUnit) Test(org.junit.Test)

Example 20 with BannerAdUnit

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

the class ExtraTests method testRubiconEmptyInvalidPrebidServerAccountId.

@Test
public void testRubiconEmptyInvalidPrebidServerAccountId() throws Exception {
    PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("");
    PrebidMobile.setPrebidServerHost(Host.RUBICON);
    PrebidMobile.setShareGeoLocation(true);
    final OnCompleteListener[] listener = new OnCompleteListener[1];
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            final MoPubView adObject = new MoPubView(m.getActivity());
            adObject.setAdUnitId(Constants.MOPUB_BANNER_ADUNIT_ID_300x250_RUBICON);
            adObject.setMinimumHeight(250);
            adObject.setMinimumWidth(300);
            BannerAdUnit adUnit = new BannerAdUnit("1001-1", 300, 250);
            OnCompleteListener l = new OnCompleteListener() {

                @Override
                public void onComplete(ResultCode resultCode) {
                    FrameLayout adFrame = m.getActivity().findViewById(R.id.adFrame);
                    adFrame.addView(adObject);
                    adObject.loadAd();
                }
            };
            listener[0] = spy(l);
            adUnit.fetchDemand(adObject, listener[0]);
        }
    });
    Thread.sleep(2000);
    verify(listener[0], times(1)).onComplete(ResultCode.INVALID_ACCOUNT_ID);
}
Also used : OnCompleteListener(org.prebid.mobile.OnCompleteListener) FrameLayout(android.widget.FrameLayout) ResultCode(org.prebid.mobile.ResultCode) MoPubView(com.mopub.mobileads.MoPubView) BannerAdUnit(org.prebid.mobile.BannerAdUnit) Test(org.junit.Test)

Aggregations

BannerAdUnit (org.prebid.mobile.BannerAdUnit)29 OnCompleteListener (org.prebid.mobile.OnCompleteListener)26 ResultCode (org.prebid.mobile.ResultCode)26 FrameLayout (android.widget.FrameLayout)24 MoPubView (com.mopub.mobileads.MoPubView)22 Test (org.junit.Test)22 MockResponse (okhttp3.mockwebserver.MockResponse)8 Matchers.containsString (org.hamcrest.Matchers.containsString)7 Dispatcher (okhttp3.mockwebserver.Dispatcher)6 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)6 AdUnit (org.prebid.mobile.AdUnit)6 AdManagerAdRequest (com.google.android.gms.ads.admanager.AdManagerAdRequest)5 InterstitialAdUnit (org.prebid.mobile.InterstitialAdUnit)5 AdManagerAdView (com.google.android.gms.ads.admanager.AdManagerAdView)4 ArrayList (java.util.ArrayList)4 JSONException (org.json.JSONException)4 BannerBaseAdUnit (org.prebid.mobile.BannerBaseAdUnit)4 AdListener (com.google.android.gms.ads.AdListener)3 AdSize (com.google.android.gms.ads.AdSize)3 PbFindSizeError (org.prebid.mobile.addendum.PbFindSizeError)3