Search in sources :

Example 1 with AdManagerAdView

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

the class PublisherAdViewWrapperTest method getView_ReturnGamView.

@Test
public void getView_ReturnGamView() throws IllegalAccessException {
    final Activity activity = Robolectric.buildActivity(Activity.class).create().get();
    AdManagerAdView publisherAdView = new AdManagerAdView(activity);
    WhiteBox.field(PublisherAdViewWrapper.class, "mAdView").set(mPublisherAdViewWrapper, publisherAdView);
    final View view = mPublisherAdViewWrapper.getView();
    assertEquals(publisherAdView, view);
}
Also used : AdManagerAdView(com.google.android.gms.ads.admanager.AdManagerAdView) Activity(android.app.Activity) AdManagerAdView(com.google.android.gms.ads.admanager.AdManagerAdView) View(android.view.View) Test(org.junit.Test)

Example 2 with AdManagerAdView

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

Example 3 with AdManagerAdView

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

the class XandrNativeInAppGAMDemoActivity method loadDfp.

private void loadDfp(AdManagerAdRequest adManagerAdRequest) {
    adLoader = new AdLoader.Builder(this, DFP_NATIVE_NATIVE_ADUNIT_ID_APPNEXUS).forAdManagerAdView(new OnAdManagerAdViewLoadedListener() {

        @Override
        public void onAdManagerAdViewLoaded(AdManagerAdView adManagerAdView) {
            adView = adManagerAdView;
            ((FrameLayout) findViewById(R.id.adFrame)).addView(adManagerAdView);
        }
    }, AdSize.BANNER).forUnifiedNativeAd(new UnifiedNativeAd.OnUnifiedNativeAdLoadedListener() {

        @Override
        public void onUnifiedNativeAdLoaded(UnifiedNativeAd unifiedNativeAd) {
            LogUtil.d("Prebid", "native loaded");
            XandrNativeInAppGAMDemoActivity.this.unifiedNativeAd = unifiedNativeAd;
        }
    }).forCustomTemplateAd("11963183", new NativeCustomTemplateAd.OnCustomTemplateAdLoadedListener() {

        @Override
        public void onCustomTemplateAdLoaded(NativeCustomTemplateAd nativeCustomTemplateAd) {
            LogUtil.d("Prebid", "custom ad loaded");
            AdViewUtils.findNative(nativeCustomTemplateAd, new PrebidNativeAdListener() {

                @Override
                public void onPrebidNativeLoaded(PrebidNativeAd ad) {
                    inflatePrebidNativeAd(ad);
                }

                @Override
                public void onPrebidNativeNotFound() {
                    LogUtil.d("Prebid", "onPrebidNativeNotFound");
                // inflate nativeCustomTemplateAd
                }

                @Override
                public void onPrebidNativeNotValid() {
                    LogUtil.d("Prebid", "onPrebidNativeNotFound");
                // show your own content
                }
            });
        }
    }, new NativeCustomTemplateAd.OnCustomClickListener() {

        @Override
        public void onCustomClick(NativeCustomTemplateAd nativeCustomTemplateAd, String s) {
        }
    }).withAdListener(new AdListener() {

        @Override
        public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
            super.onAdFailedToLoad(loadAdError);
            Toast.makeText(XandrNativeInAppGAMDemoActivity.this, "DFP onAdFailedToLoad", Toast.LENGTH_SHORT).show();
        }
    }).build();
    adLoader.loadAd(adManagerAdRequest);
}
Also used : LoadAdError(com.google.android.gms.ads.LoadAdError) AdListener(com.google.android.gms.ads.AdListener) PrebidNativeAdListener(org.prebid.mobile.PrebidNativeAdListener) NativeCustomTemplateAd(com.google.android.gms.ads.formats.NativeCustomTemplateAd) AdManagerAdView(com.google.android.gms.ads.admanager.AdManagerAdView) FrameLayout(android.widget.FrameLayout) PrebidNativeAdListener(org.prebid.mobile.PrebidNativeAdListener) OnAdManagerAdViewLoadedListener(com.google.android.gms.ads.formats.OnAdManagerAdViewLoadedListener) PrebidNativeAd(org.prebid.mobile.PrebidNativeAd) UnifiedNativeAd(com.google.android.gms.ads.formats.UnifiedNativeAd)

Example 4 with AdManagerAdView

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

the class XandrNativeInBannerGamDemoActivity 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);
    adUnit = new NativeAdUnit(Constants.PBS_CONFIG_ID_NATIVE_APPNEXUS);
    FrameLayout adFrame = (FrameLayout) findViewById(R.id.adFrame);
    adFrame.removeAllViews();
    final AdManagerAdView nativeAdView = new AdManagerAdView(this);
    nativeAdView.setAdListener(new AdListener() {

        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
            LogUtil.d("ad loaded");
        }
    });
    nativeAdView.setAdUnitId(Constants.DFP_IN_BANNER_NATIVE_ADUNIT_ID_APPNEXUS);
    nativeAdView.setAdSizes(AdSize.FLUID);
    adFrame.addView(nativeAdView);
    final AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
    NativeAdUnit nativeAdUnit = (NativeAdUnit) adUnit;
    nativeAdUnit.setContextType(NativeAdUnit.CONTEXT_TYPE.SOCIAL_CENTRIC);
    nativeAdUnit.setPlacementType(NativeAdUnit.PLACEMENTTYPE.CONTENT_FEED);
    nativeAdUnit.setContextSubType(NativeAdUnit.CONTEXTSUBTYPE.GENERAL_SOCIAL);
    ArrayList<NativeEventTracker.EVENT_TRACKING_METHOD> methods = new ArrayList<>();
    methods.add(NativeEventTracker.EVENT_TRACKING_METHOD.IMAGE);
    try {
        NativeEventTracker tracker = new NativeEventTracker(NativeEventTracker.EVENT_TYPE.IMPRESSION, methods);
        nativeAdUnit.addEventTracker(tracker);
    } catch (Exception e) {
        e.printStackTrace();
    }
    NativeTitleAsset title = new NativeTitleAsset();
    title.setLength(90);
    title.setRequired(true);
    nativeAdUnit.addAsset(title);
    NativeImageAsset icon = new NativeImageAsset();
    icon.setImageType(NativeImageAsset.IMAGE_TYPE.ICON);
    icon.setWMin(20);
    icon.setHMin(20);
    icon.setRequired(true);
    nativeAdUnit.addAsset(icon);
    NativeImageAsset image = new NativeImageAsset();
    image.setImageType(NativeImageAsset.IMAGE_TYPE.MAIN);
    image.setHMin(200);
    image.setWMin(200);
    image.setRequired(true);
    nativeAdUnit.addAsset(image);
    NativeDataAsset data = new NativeDataAsset();
    data.setLen(90);
    data.setDataType(NativeDataAsset.DATA_TYPE.SPONSORED);
    data.setRequired(true);
    nativeAdUnit.addAsset(data);
    NativeDataAsset body = new NativeDataAsset();
    body.setRequired(true);
    body.setDataType(NativeDataAsset.DATA_TYPE.DESC);
    nativeAdUnit.addAsset(body);
    NativeDataAsset cta = new NativeDataAsset();
    cta.setRequired(true);
    cta.setDataType(NativeDataAsset.DATA_TYPE.CTATEXT);
    nativeAdUnit.addAsset(cta);
    int millis = getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0);
    nativeAdUnit.setAutoRefreshPeriodMillis(millis);
    nativeAdUnit.fetchDemand(builder, new OnCompleteListener() {

        @Override
        public void onComplete(ResultCode resultCode) {
            AdManagerAdRequest request = builder.build();
            nativeAdView.loadAd(request);
        }
    });
}
Also used : ArrayList(java.util.ArrayList) NativeTitleAsset(org.prebid.mobile.NativeTitleAsset) NativeDataAsset(org.prebid.mobile.NativeDataAsset) NativeAdUnit(org.prebid.mobile.NativeAdUnit) AdListener(com.google.android.gms.ads.AdListener) OnCompleteListener(org.prebid.mobile.OnCompleteListener) AdManagerAdView(com.google.android.gms.ads.admanager.AdManagerAdView) NativeImageAsset(org.prebid.mobile.NativeImageAsset) FrameLayout(android.widget.FrameLayout) NativeEventTracker(org.prebid.mobile.NativeEventTracker) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) ResultCode(org.prebid.mobile.ResultCode)

Example 5 with AdManagerAdView

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

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