Search in sources :

Example 11 with ResultCode

use of org.prebid.mobile.ResultCode 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 12 with ResultCode

use of org.prebid.mobile.ResultCode 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 13 with ResultCode

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

the class RubiconRewardedVideoMoPubDemoActivity 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)));
    RewardedVideoAdUnit adUnit = new RewardedVideoAdUnit("1001-1");
    adUnit.setParameters(parameters);
    this.adUnit = adUnit;
    SdkConfiguration sdkConfiguration = new SdkConfiguration.Builder(Constants.MP_ADUNITID_REWARDED).build();
    MoPub.initializeSdk(this, sdkConfiguration, null);
    MoPubRewardedVideos.setRewardedVideoListener(this);
    final Map<String, String> keywordsMap = new HashMap<>();
    adUnit.fetchDemand(keywordsMap, new OnCompleteListener() {

        @Override
        public void onComplete(ResultCode resultCode) {
            MoPubRewardedVideoManager.RequestParameters parameters = new MoPubRewardedVideoManager.RequestParameters(Util.convertMapToMoPubKeywords(keywordsMap));
            MoPubRewardedVideos.loadRewardedVideo(Constants.MP_ADUNITID_REWARDED, parameters, (MediationSettings) null);
        }
    });
}
Also used : HashMap(java.util.HashMap) RewardedVideoAdUnit(org.prebid.mobile.RewardedVideoAdUnit) OnCompleteListener(org.prebid.mobile.OnCompleteListener) VideoBaseAdUnit(org.prebid.mobile.VideoBaseAdUnit) SdkConfiguration(com.mopub.common.SdkConfiguration) MediationSettings(com.mopub.common.MediationSettings) ResultCode(org.prebid.mobile.ResultCode) MoPubRewardedVideoManager(com.mopub.mobileads.MoPubRewardedVideoManager)

Example 14 with ResultCode

use of org.prebid.mobile.ResultCode 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 ResultCode

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

the class AdManagerComplexTest method testFetchDemandBidsAutoRefresh.

@Test
public void testFetchDemandBidsAutoRefresh() throws Exception {
    final IntegerWrapper requestCountWrapper = new IntegerWrapper();
    fetchDemandHelper(31_000, new FetchDemandCompleteListener() {

        @Override
        public void preFetchDemand() {
            mockServer.enqueue(new MockResponse().setResponseCode(200).setBody("{\n" + "  \"seatbid\": [\n" + "    {\n" + "      \"bid\": [\n" + "        {\n" + "          \"ext\": {\n" + "            \"prebid\": {\n" + "              \"targeting\": {\n" + "                \"hb_cache_id\": \"top_bid_1\",\n" + "                \"key1\": \"value1\"\n" + "              }\n" + "            }\n" + "          }\n" + "        }\n" + "      ]\n" + "    }\n" + "  ]\n" + "}"));
        }

        @Override
        public void executeFetchDemand(AdUnit adUnit, final List<Map<String, String>> resultList) {
            adUnit.fetchDemand(new OnCompleteListener2() {

                @Override
                public void onComplete(ResultCode resultCode, Map<String, String> unmodifiableMap) {
                    requestCountWrapper.value++;
                    resultList.add(new HashMap(unmodifiableMap));
                }
            });
        }

        @Override
        public void postFetchDemand(List<Map<String, String>> resultList) {
            Map<String, String> result = resultList.get(1);
            assertEquals("top_bid_1", result.get("hb_cache_id"));
            assertEquals("value1", result.get("key1"));
        }
    });
    assertEquals(2, requestCountWrapper.value);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) BannerAdUnit(org.prebid.mobile.BannerAdUnit) AdUnit(org.prebid.mobile.AdUnit) HashMap(java.util.HashMap) OnCompleteListener2(org.prebid.mobile.OnCompleteListener2) HashMap(java.util.HashMap) Map(java.util.Map) ResultCode(org.prebid.mobile.ResultCode) Test(org.junit.Test)

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