Search in sources :

Example 11 with BannerAdUnit

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

the class ExtraTests method testRubiconDemand.

@Test
public void testRubiconDemand() 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_APPNEXUS);
            adObject.setMinimumHeight(250);
            adObject.setMinimumWidth(300);
            BannerAdUnit adUnit = new BannerAdUnit("1001-2", 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(10000);
    verify(listener[0], times(1)).onComplete(ResultCode.SUCCESS);
    onView(withId(R.id.adFrame)).check(matches(isDisplayed()));
    onWebView().check(webMatches(getCurrentUrl(), containsString("ads.mopub.com")));
    onWebView().check(webContent(containingTextInBody("ucTag.renderAd")));
}
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 12 with BannerAdUnit

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

the class ExtraTests method testAppNexusKeyValueTargeting2.

@Test
public void testAppNexusKeyValueTargeting2() throws Exception {
    PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("bfa84af2-bd16-4d35-96ad-31c6bb888df0");
    PrebidMobile.setPrebidServerHost(Host.APPNEXUS);
    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_APPNEXUS);
            adObject.setMinimumHeight(250);
            adObject.setMinimumWidth(300);
            BannerAdUnit adUnit = new BannerAdUnit("67bac530-9832-4f78-8c94-fbf88ac7bd14", 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(10000);
    verify(listener[0], times(1)).onComplete(ResultCode.NO_BIDS);
    onView(withId(R.id.adFrame)).check(matches(isDisplayed()));
    onWebView().check(webMatches(getCurrentUrl(), containsString("ads.mopub.com")));
    onWebView().check(webContent(containingTextInBody("Hello, I'm not a Prebid ad.")));
}
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 13 with BannerAdUnit

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

the class RubiconBannerMoPubDemoActivity 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);
    FrameLayout adFrame = findViewById(R.id.adFrame);
    adFrame.removeAllViews();
    final MoPubView adView = new MoPubView(this);
    adView.setAdUnitId(Constants.MOPUB_BANNER_ADUNIT_ID_300x250_RUBICON);
    adView.setMinimumWidth(width);
    adView.setMinimumHeight(height);
    adFrame.addView(adView);
    adUnit.setAutoRefreshPeriodMillis(getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0));
    adUnit.fetchDemand(adView, new OnCompleteListener() {

        @Override
        public void onComplete(ResultCode resultCode) {
            adView.loadAd();
            refreshCount++;
            RubiconBannerMoPubDemoActivity.this.resultCode = resultCode;
        }
    });
}
Also used : OnCompleteListener(org.prebid.mobile.OnCompleteListener) BannerBaseAdUnit(org.prebid.mobile.BannerBaseAdUnit) FrameLayout(android.widget.FrameLayout) ResultCode(org.prebid.mobile.ResultCode) BannerAdUnit(org.prebid.mobile.BannerAdUnit) MoPubView(com.mopub.mobileads.MoPubView)

Example 14 with BannerAdUnit

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

the class XandrBannerMoPubDemoActivity 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);
    FrameLayout adFrame = findViewById(R.id.adFrame);
    adFrame.removeAllViews();
    final MoPubView adView = new MoPubView(this);
    adView.setAdUnitId(Constants.MOPUB_BANNER_ADUNIT_ID_300x250_APPNEXUS);
    adView.setMinimumWidth(300);
    adView.setMinimumHeight(250);
    adFrame.addView(adView);
    adUnit.setAutoRefreshPeriodMillis(getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0));
    adUnit.fetchDemand(adView, new OnCompleteListener() {

        @Override
        public void onComplete(ResultCode resultCode) {
            adView.loadAd();
        }
    });
}
Also used : OnCompleteListener(org.prebid.mobile.OnCompleteListener) BannerBaseAdUnit(org.prebid.mobile.BannerBaseAdUnit) FrameLayout(android.widget.FrameLayout) ResultCode(org.prebid.mobile.ResultCode) BannerAdUnit(org.prebid.mobile.BannerAdUnit) MoPubView(com.mopub.mobileads.MoPubView)

Example 15 with BannerAdUnit

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

the class AdManagerComplexTest method testRubiconDFPBannerResizeSanityAppCheckTest.

// 30x250 -> 728x90
@Test
public void testRubiconDFPBannerResizeSanityAppCheckTest() throws Exception {
    final CountDownLatch lock = new CountDownLatch(1);
    PrebidMobile.setPrebidServerHost(Host.RUBICON);
    PrebidMobile.setPrebidServerAccountId(Constants.PBS_ACCOUNT_ID_RUBICON);
    PrebidMobile.setStoredAuctionResponse("1001-rubicon-300x250");
    TestActivity activity = testActivityRule.getActivity();
    final IntegerWrapper firstTransactionCount = new IntegerWrapper();
    final IntegerWrapper secondTransactionCount = new IntegerWrapper();
    final int transactionFailRepeatCount = 5;
    final int screenshotDelayMillis = 3_000;
    final int transactionFailDelayMillis = 3_000;
    final FrameLayout adFrame = activity.findViewById(R.id.adFrame);
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            adFrame.removeAllViews();
        }
    });
    final AdManagerAdView dfpAdView = new AdManagerAdView(activity);
    // Programmatic fix
    dfpAdView.setAdUnitId("/5300653/test_adunit_pavliuchyk_300x250_puc_ucTagData_prebid-server.rubiconproject.com");
    dfpAdView.setAdSizes(new AdSize(300, 250));
    // Targeting creative
    /*
        dfpAdView.setAdUnitId("/5300653/Banner_PUC_b397711");
        dfpAdView.setAdSizes(new AdSize(300, 250), new AdSize(728, 90));
        */
    final BannerAdUnit bannerAdUnit = new BannerAdUnit(Constants.PBS_CONFIG_ID_300x250_RUBICON, 300, 250);
    final AdManagerAdRequest request = new AdManagerAdRequest.Builder().build();
    final OnCompleteListener completeListener = new OnCompleteListener() {

        @Override
        public void onComplete(ResultCode resultCode) {
            dfpAdView.loadAd(request);
        }
    };
    dfpAdView.setAdListener(new AdListener() {

        private void notifyResult() {
            lock.countDown();
        }

        private void update(boolean isSuccess) {
            if (isSuccess) {
                if (firstTransactionCount.value != -1) {
                    firstTransactionCount.value = -1;
                    PrebidMobile.setStoredAuctionResponse("1001-rubicon-300x50");
                    bannerAdUnit.fetchDemand(request, completeListener);
                } else if (secondTransactionCount.value != -1) {
                    secondTransactionCount.value = -1;
                    notifyResult();
                }
            } else {
                try {
                    Thread.sleep(transactionFailDelayMillis);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                if (firstTransactionCount.value != -1) {
                    if (firstTransactionCount.value > transactionFailRepeatCount - 2) {
                        fail("first Transaction Count == " + transactionFailRepeatCount);
                    } else {
                        // repeat
                        firstTransactionCount.value++;
                        bannerAdUnit.fetchDemand(request, completeListener);
                    }
                } else if (secondTransactionCount.value != -1) {
                    if (secondTransactionCount.value > transactionFailRepeatCount - 2) {
                        fail("second Transaction Count == " + transactionFailRepeatCount);
                    } else {
                        // repeat
                        secondTransactionCount.value++;
                        bannerAdUnit.fetchDemand(request, completeListener);
                    }
                } else {
                    fail("Unexpected");
                }
            }
        }

        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            // Programmatic fix
            AdViewUtils.findPrebidCreativeSize(dfpAdView, new AdViewUtils.PbFindSizeListener() {

                @Override
                public void success(final int width, final int height) {
                    dfpAdView.setAdSizes(new AdSize(width, height));
                    final View child = dfpAdView.getChildAt(0);
                    child.setBackgroundColor(Color.RED);
                    dfpAdView.post(new Runnable() {

                        @Override
                        public void run() {
                            float density = dfpAdView.getResources().getDisplayMetrics().density;
                            double dpW = Math.ceil(child.getMinimumWidth() / density);
                            double dpH = Math.ceil(child.getMinimumHeight() / density);
                            try {
                                Thread.sleep(screenshotDelayMillis);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                            assertEquals((int) dpW, width);
                            assertEquals((int) dpH, height);
                            update(true);
                        }
                    });
                }

                @Override
                public void failure(PbFindSizeError error) {
                    LogUtil.w("failure:" + error.getDescription());
                    update(false);
                }
            });
        // Targeting creative
        /*
                try {
                    Thread.sleep(screenshotDelayMillis);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                update(true);
                */
        }

        @Override
        public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
            LogUtil.w("onAdFailedToLoad:" + loadAdError);
            update(false);
        }
    });
    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            adFrame.addView(dfpAdView);
        }
    });
    bannerAdUnit.fetchDemand(request, completeListener);
    // TravisCI fix
    Thread.sleep(2 * transactionFailRepeatCount * transactionFailDelayMillis + 2 * screenshotDelayMillis);
    try {
        Thread.sleep(screenshotDelayMillis);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    assertEquals(-1, firstTransactionCount.value);
    assertEquals(-1, secondTransactionCount.value);
}
Also used : PbFindSizeError(org.prebid.mobile.addendum.PbFindSizeError) LoadAdError(com.google.android.gms.ads.LoadAdError) CountDownLatch(java.util.concurrent.CountDownLatch) View(android.view.View) AdManagerAdView(com.google.android.gms.ads.admanager.AdManagerAdView) 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) FrameLayout(android.widget.FrameLayout) AdSize(com.google.android.gms.ads.AdSize) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) ResultCode(org.prebid.mobile.ResultCode) 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