Search in sources :

Example 1 with AdManagerAdRequest

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

the class PublisherAdViewWrapper method loadAd.

// endregion ==================== GAM AdEventListener Implementation
public void loadAd(Bid bid) {
    try {
        AdManagerAdRequest adRequest = new AdManagerAdRequest.Builder().build();
        if (bid != null) {
            Map<String, String> targetingMap = new HashMap<>(bid.getPrebid().getTargeting());
            GamUtils.handleGamCustomTargetingUpdate(adRequest, targetingMap);
        }
        mAdView.loadAd(adRequest);
    } catch (Throwable throwable) {
        LogUtil.error(TAG, Log.getStackTraceString(throwable));
    }
}
Also used : HashMap(java.util.HashMap) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest)

Example 2 with AdManagerAdRequest

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

the class RewardedAdWrapper method loadAd.

// endregion ==================== GAM FullScreenContentCallback Implementation
public void loadAd(Bid bid) {
    try {
        AdManagerAdRequest adRequest = new AdManagerAdRequest.Builder().build();
        if (bid != null) {
            Map<String, String> targetingMap = new HashMap<>(bid.getPrebid().getTargeting());
            GamUtils.handleGamCustomTargetingUpdate(adRequest, targetingMap);
        }
        RewardedAd.load(mContextWeakReference.get(), mAdUnitId, adRequest, mRewardedAdLoadCallback);
    } catch (Throwable throwable) {
        LogUtil.error(TAG, Log.getStackTraceString(throwable));
    }
}
Also used : HashMap(java.util.HashMap) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest)

Example 3 with AdManagerAdRequest

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

the class PublisherInterstitialAdWrapper method loadAd.

public void loadAd(Bid bid) {
    mInterstitialAd = null;
    try {
        AdManagerAdRequest adRequest = new AdManagerAdRequest.Builder().build();
        if (bid != null) {
            Map<String, String> targetingMap = new HashMap<>(bid.getPrebid().getTargeting());
            GamUtils.handleGamCustomTargetingUpdate(adRequest, targetingMap);
        }
        AdManagerInterstitialAd.load(mActivityWeakReference.get(), mAdUnitId, adRequest, mAdLoadCallback);
    } catch (Throwable throwable) {
        LogUtil.error(TAG, Log.getStackTraceString(throwable));
    }
}
Also used : HashMap(java.util.HashMap) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest)

Example 4 with AdManagerAdRequest

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

the class GamUtilsTest method handleGamKeywordsUpdate_KeyWordsShouldMatchExpected.

@Test
public void handleGamKeywordsUpdate_KeyWordsShouldMatchExpected() {
    AdManagerAdRequest.Builder builder = new AdManagerAdRequest.Builder();
    builder.addCustomTargeting("Key", "Value");
    HashMap<String, String> bids = new HashMap<>();
    bids.put("hb_pb", "0.50");
    bids.put("hb_cache_id", "123456");
    AdManagerAdRequest request = builder.build();
    GamUtils.handleGamCustomTargetingUpdate(request, bids);
    Assert.assertEquals(3, request.getCustomTargeting().size());
    assertTrue(request.getCustomTargeting().containsKey("Key"));
    Assert.assertEquals("Value", request.getCustomTargeting().get("Key"));
    assertTrue(request.getCustomTargeting().containsKey("hb_pb"));
    Assert.assertEquals("0.50", request.getCustomTargeting().get("hb_pb"));
    assertTrue(request.getCustomTargeting().containsKey("hb_cache_id"));
    Assert.assertEquals("123456", request.getCustomTargeting().get("hb_cache_id"));
    GamUtils.handleGamCustomTargetingUpdate(request, null);
    Assert.assertEquals(1, request.getCustomTargeting().size());
    assertTrue(request.getCustomTargeting().containsKey("Key"));
    Assert.assertEquals("Value", request.getCustomTargeting().get("Key"));
}
Also used : HashMap(java.util.HashMap) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) Test(org.junit.Test)

Example 5 with AdManagerAdRequest

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

the class ResultCodeTest method testSuccessForDFP.

@Test
public void testSuccessForDFP() throws Exception {
    HttpUrl httpUrl = server.url("/");
    Host.CUSTOM.setHostUrl(httpUrl.toString());
    PrebidMobile.setPrebidServerHost(Host.CUSTOM);
    PrebidMobile.setApplicationContext(activity.getApplicationContext());
    PrebidMobile.setPrebidServerAccountId("123456");
    server.enqueue(new MockResponse().setResponseCode(200).setBody(MockPrebidServerResponses.oneBidFromAppNexus()));
    BannerAdUnit adUnit = new BannerAdUnit("123456", 300, 250);
    AdManagerAdRequest testRequest = new AdManagerAdRequest.Builder().build();
    OnCompleteListener mockListener = mock(OnCompleteListener.class);
    adUnit.fetchDemand(testRequest, mockListener);
    DemandFetcher fetcher = (DemandFetcher) FieldUtils.readField(adUnit, "fetcher", true);
    PrebidMobile.setTimeoutMillis(Integer.MAX_VALUE);
    ShadowLooper fetcherLooper = shadowOf(fetcher.getHandler().getLooper());
    fetcherLooper.runOneTask();
    ShadowLooper demandLooper = shadowOf(fetcher.getDemandHandler().getLooper());
    demandLooper.runOneTask();
    ShadowLooper bgLooper = Shadows.shadowOf(((BackgroundThreadExecutor) TasksManager.getInstance().backgroundThreadExecutor).getBackgroundHandler().getLooper());
    bgLooper.runToEndOfTasks();
    Robolectric.flushBackgroundThreadScheduler();
    Robolectric.flushForegroundThreadScheduler();
    verify(mockListener).onComplete(ResultCode.SUCCESS);
    Bundle bundle = testRequest.getCustomTargeting();
    assertEquals(10, bundle.size());
    assertTrue(bundle.containsKey("hb_pb"));
    assertEquals("0.50", bundle.get("hb_pb"));
    assertTrue(bundle.containsKey("hb_bidder"));
    assertEquals("appnexus", bundle.get("hb_bidder"));
    assertTrue(bundle.containsKey("hb_bidder_appnexus"));
    assertEquals("appnexus", bundle.get("hb_bidder_appnexus"));
    assertTrue(bundle.containsKey("hb_cache_id"));
    assertEquals("df4aba04-5e69-44b8-8608-058ab21600b8", bundle.get("hb_cache_id"));
    assertTrue(bundle.containsKey("hb_cache_id_appnexus"));
    assertEquals("df4aba04-5e69-44b8-8608-058ab21600b8", bundle.get("hb_cache_id_appnexus"));
    assertTrue(bundle.containsKey("hb_env"));
    assertEquals("mobile-app", bundle.get("hb_env"));
    assertTrue(bundle.containsKey("hb_env_appnexus"));
    assertEquals("mobile-app", bundle.get("hb_env_appnexus"));
    assertTrue(bundle.containsKey("hb_pb_appnexus"));
    assertEquals("0.50", bundle.get("hb_pb_appnexus"));
    assertTrue(bundle.containsKey("hb_size"));
    assertEquals("300x250", bundle.get("hb_size"));
    assertTrue(bundle.containsKey("hb_size_appnexus"));
    assertEquals("300x250", bundle.get("hb_size_appnexus"));
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) Bundle(android.os.Bundle) ShadowLooper(org.robolectric.shadows.ShadowLooper) BackgroundThreadExecutor(org.prebid.mobile.tasksmanager.BackgroundThreadExecutor) AdManagerAdRequest(com.google.android.gms.ads.admanager.AdManagerAdRequest) HttpUrl(okhttp3.HttpUrl) Test(org.junit.Test)

Aggregations

AdManagerAdRequest (com.google.android.gms.ads.admanager.AdManagerAdRequest)29 Test (org.junit.Test)17 OnCompleteListener (org.prebid.mobile.OnCompleteListener)13 ResultCode (org.prebid.mobile.ResultCode)13 Bundle (android.os.Bundle)9 MockResponse (okhttp3.mockwebserver.MockResponse)9 HttpUrl (okhttp3.HttpUrl)8 BackgroundThreadExecutor (org.prebid.mobile.tasksmanager.BackgroundThreadExecutor)8 ShadowLooper (org.robolectric.shadows.ShadowLooper)8 NonNull (androidx.annotation.NonNull)7 FrameLayout (android.widget.FrameLayout)6 AdManagerAdView (com.google.android.gms.ads.admanager.AdManagerAdView)6 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 BannerAdUnit (org.prebid.mobile.BannerAdUnit)6 AdListener (com.google.android.gms.ads.AdListener)5 LoadAdError (com.google.android.gms.ads.LoadAdError)5 AdSize (com.google.android.gms.ads.AdSize)4 PbFindSizeError (org.prebid.mobile.addendum.PbFindSizeError)4 AlertDialog (androidx.appcompat.app.AlertDialog)3