Search in sources :

Example 36 with ResultCode

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

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

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

the class AdManagerComplexTest method testFetchDemand.

@Test
public void testFetchDemand() throws Exception {
    final AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
    fetchDemandHelper(0, new FetchDemandCompleteListener() {

        @Override
        public void preFetchDemand() {
        }

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

                @Override
                public void onComplete(ResultCode resultCode) {
                    Bundle customTargetingBundle = builder.build().getCustomTargeting();
                    Map<String, String> map = new HashMap<>(customTargetingBundle.keySet().size());
                    for (String key : customTargetingBundle.keySet()) {
                        map.put(key, customTargetingBundle.get(key).toString());
                    }
                    resultList.add(map);
                }
            });
        }

        @Override
        public void postFetchDemand(List<Map<String, String>> resultList) {
        }
    });
}
Also used : HashMap(java.util.HashMap) Bundle(android.os.Bundle) OnCompleteListener(org.prebid.mobile.OnCompleteListener) BannerAdUnit(org.prebid.mobile.BannerAdUnit) AdUnit(org.prebid.mobile.AdUnit) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) HashMap(java.util.HashMap) Map(java.util.Map) ResultCode(org.prebid.mobile.ResultCode) Test(org.junit.Test)

Example 39 with ResultCode

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

the class AdManagerComplexTest method testFetchDemandAutoRefresh.

@Test
public void testFetchDemandAutoRefresh() throws Exception {
    final AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
    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(builder, new OnCompleteListener() {

                @Override
                public void onComplete(ResultCode resultCode) {
                    requestCountWrapper.value++;
                    AdManagerAdRequest adManagerAdRequest = builder.build();
                    Bundle customTargetingBundle = adManagerAdRequest.getCustomTargeting();
                    Map<String, String> map = new HashMap<>(customTargetingBundle.keySet().size());
                    for (String key : customTargetingBundle.keySet()) {
                        map.put(key, customTargetingBundle.get(key).toString());
                    }
                    resultList.add(map);
                }
            });
        }

        @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) HashMap(java.util.HashMap) Bundle(android.os.Bundle) OnCompleteListener(org.prebid.mobile.OnCompleteListener) BannerAdUnit(org.prebid.mobile.BannerAdUnit) AdUnit(org.prebid.mobile.AdUnit) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) HashMap(java.util.HashMap) Map(java.util.Map) ResultCode(org.prebid.mobile.ResultCode) Test(org.junit.Test)

Example 40 with ResultCode

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

the class AdManagerComplexTest method testAdManagerAdRequestBuilderUseCase.

@Test
public void testAdManagerAdRequestBuilderUseCase() throws Exception {
    // given
    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" + "}"));
    // important line
    PrebidMobile.setPrebidServerHost(Host.CUSTOM);
    HttpUrl httpUrl = mockServer.url("/testAdManagerAdRequestBuilderUseCase");
    Host.CUSTOM.setHostUrl(httpUrl.toString());
    PrebidMobile.setPrebidServerAccountId("1001");
    final ReferenceWrapper<Bundle> customTargetingBundleWrapper1 = new ReferenceWrapper<>();
    // when
    final AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
    AdUnit adUnit = new BannerAdUnit("1001-1", 300, 250);
    adUnit.fetchDemand(builder, new OnCompleteListener() {

        @Override
        public void onComplete(ResultCode resultCode) {
            builder.addCustomTargeting("key2", "value2");
            AdManagerAdRequest adManagerAdRequest = builder.build();
            Bundle customTargetingBundle = adManagerAdRequest.getCustomTargeting();
            customTargetingBundleWrapper1.value = (Bundle) customTargetingBundle.clone();
        }
    });
    try {
        Thread.sleep(1_000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    // then
    Bundle customTargetingBundle = customTargetingBundleWrapper1.value;
    assertEquals(3, customTargetingBundle.keySet().size());
    assertEquals("top_bid_1", customTargetingBundle.getString("hb_cache_id"));
    assertEquals("value1", customTargetingBundle.getString("key1"));
    assertEquals("value2", customTargetingBundle.getString("key2"));
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) Bundle(android.os.Bundle) HttpUrl(okhttp3.HttpUrl) BannerAdUnit(org.prebid.mobile.BannerAdUnit) OnCompleteListener(org.prebid.mobile.OnCompleteListener) BannerAdUnit(org.prebid.mobile.BannerAdUnit) AdUnit(org.prebid.mobile.AdUnit) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) 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