Search in sources :

Example 6 with AdManagerAdView

use of com.google.android.gms.ads.admanager.AdManagerAdView in project prebid-mobile-android by prebid.

the class RubiconBannerVideoGamDemoActivity 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)));
    parameters.setPlacement(Signals.Placement.InBanner);
    // parameters.setPlacement(new Signals.Placement(2));
    VideoAdUnit adUnit = new VideoAdUnit("1001-1", 300, 250);
    adUnit.setParameters(parameters);
    this.adUnit = adUnit;
    final AdManagerAdView amBanner = new AdManagerAdView(this);
    amBanner.setAdUnitId(Constants.DFP_VAST_ADUNIT_ID_RUBICON);
    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) VideoAdUnit(org.prebid.mobile.VideoAdUnit) AdListener(com.google.android.gms.ads.AdListener) OnCompleteListener(org.prebid.mobile.OnCompleteListener) AdManagerAdView(com.google.android.gms.ads.admanager.AdManagerAdView) AdSize(com.google.android.gms.ads.AdSize) FrameLayout(android.widget.FrameLayout) NonNull(androidx.annotation.NonNull) VideoBaseAdUnit(org.prebid.mobile.VideoBaseAdUnit) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) ResultCode(org.prebid.mobile.ResultCode)

Example 7 with AdManagerAdView

use of com.google.android.gms.ads.admanager.AdManagerAdView 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 8 with AdManagerAdView

use of com.google.android.gms.ads.admanager.AdManagerAdView in project prebid-mobile-android by prebid.

the class ExtraTests method testSameConfigIdOnDifferentAdObjects.

@Test
public void testSameConfigIdOnDifferentAdObjects() throws Exception {
    final ArrayList<AdUnit> adUnits = new ArrayList<AdUnit>();
    final ArrayList<OnCompleteListener> spies = new ArrayList<>();
    PrebidMobile.setApplicationContext(m.getActivity().getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("bfa84af2-bd16-4d35-96ad-31c6bb888df0");
    PrebidMobile.setPrebidServerHost(Host.APPNEXUS);
    PrebidMobile.setShareGeoLocation(true);
    mHandler.post(new Runnable() {

        @Override
        public void run() {
            final MoPubView adObject1 = new MoPubView(m.getActivity());
            adObject1.setAdUnitId(Constants.MOPUB_BANNER_ADUNIT_ID_320x50_APPNEXUS);
            adObject1.setMinimumWidth(320);
            adObject1.setMinimumHeight(50);
            BannerAdUnit adUnit1 = new BannerAdUnit(Constants.PBS_CONFIG_ID_320x50_APPNEXUS, 320, 50);
            adUnits.add(adUnit1);
            OnCompleteListener l1 = new OnCompleteListener() {

                @Override
                public void onComplete(ResultCode resultCode) {
                    assertTrue(adObject1.getKeywords().contains("hb_pb:0.50"));
                    assertTrue(adObject1.getKeywords().contains("hb_cache_id:"));
                    FrameLayout adFrame = m.getActivity().findViewById(R.id.adFrame);
                    adFrame.addView(adObject1);
                    adObject1.loadAd();
                }
            };
            l1 = spy(l1);
            spies.add(l1);
            adUnit1.fetchDemand(adObject1, l1);
            AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
            final AdManagerAdRequest adObject2 = builder.build();
            BannerAdUnit adUnit2 = new BannerAdUnit(Constants.PBS_CONFIG_ID_320x50_APPNEXUS, 320, 50);
            adUnits.add(adUnit2);
            OnCompleteListener l2 = new OnCompleteListener() {

                @Override
                public void onComplete(ResultCode resultCode) {
                    assertEquals(10, adObject2.getCustomTargeting().size());
                    assertTrue(adObject2.getCustomTargeting().keySet().contains("hb_pb"));
                    assertTrue(adObject2.getCustomTargeting().keySet().contains("hb_cache_id"));
                    assertEquals("0.50", adObject2.getCustomTargeting().getString("hb_pb"));
                    FrameLayout adFrame = m.getActivity().findViewById(R.id.adFrame);
                    AdManagerAdView adView = new AdManagerAdView(m.getActivity());
                    adView.setAdSizes(AdSize.BANNER);
                    adView.setAdUnitId(Constants.DFP_BANNER_ADUNIT_ID_ALL_SIZES_APPNEXUS);
                    adFrame.addView(adView);
                    adView.setId(1);
                    adView.loadAd(adObject2);
                }
            };
            l2 = spy(l2);
            spies.add(l2);
            adUnit1.fetchDemand(adObject2, l2);
        }
    });
    Thread.sleep(10000);
    verify(spies.get(0), times(1)).onComplete(ResultCode.SUCCESS);
    verify(spies.get(1), times(1)).onComplete(ResultCode.SUCCESS);
}
Also used : ArrayList(java.util.ArrayList) BannerAdUnit(org.prebid.mobile.BannerAdUnit) OnCompleteListener(org.prebid.mobile.OnCompleteListener) BannerAdUnit(org.prebid.mobile.BannerAdUnit) AdUnit(org.prebid.mobile.AdUnit) InterstitialAdUnit(org.prebid.mobile.InterstitialAdUnit) AdManagerAdView(com.google.android.gms.ads.admanager.AdManagerAdView) FrameLayout(android.widget.FrameLayout) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) ResultCode(org.prebid.mobile.ResultCode) MoPubView(com.mopub.mobileads.MoPubView) Test(org.junit.Test)

Aggregations

AdManagerAdView (com.google.android.gms.ads.admanager.AdManagerAdView)8 FrameLayout (android.widget.FrameLayout)7 AdListener (com.google.android.gms.ads.AdListener)6 AdManagerAdRequest (com.google.android.gms.ads.admanager.AdManagerAdRequest)6 OnCompleteListener (org.prebid.mobile.OnCompleteListener)6 ResultCode (org.prebid.mobile.ResultCode)6 AdSize (com.google.android.gms.ads.AdSize)4 BannerAdUnit (org.prebid.mobile.BannerAdUnit)4 PbFindSizeError (org.prebid.mobile.addendum.PbFindSizeError)4 NonNull (androidx.annotation.NonNull)3 Test (org.junit.Test)3 View (android.view.View)2 LoadAdError (com.google.android.gms.ads.LoadAdError)2 ArrayList (java.util.ArrayList)2 BannerBaseAdUnit (org.prebid.mobile.BannerBaseAdUnit)2 Activity (android.app.Activity)1 NativeCustomTemplateAd (com.google.android.gms.ads.formats.NativeCustomTemplateAd)1 OnAdManagerAdViewLoadedListener (com.google.android.gms.ads.formats.OnAdManagerAdViewLoadedListener)1 UnifiedNativeAd (com.google.android.gms.ads.formats.UnifiedNativeAd)1 MoPubView (com.mopub.mobileads.MoPubView)1