Search in sources :

Example 1 with PrebidWebViewBanner

use of org.prebid.mobile.rendering.views.webview.PrebidWebViewBanner in project prebid-mobile-android by prebid.

the class TwoPartExpandRunnable method run.

// NOTE: handleMRAIDEventsInCreative ACTION_EXPAND is invoked from a background thread.
// This means the webview instantiation should be performed from a UI thread.
@Override
public void run() {
    HTMLCreative htmlCreative = mWeakHtmlCreative.get();
    if (htmlCreative == null) {
        LogUtil.error(TAG, "HTMLCreative object is null");
        return;
    }
    PrebidWebViewBase prebidWebViewBanner = new PrebidWebViewBanner(mOldWebViewBase.getContext(), mMraidController.mInterstitialManager);
    // inject mraid.js & load url here, for 2part expand
    prebidWebViewBanner.setOldWebView(mOldWebViewBase);
    prebidWebViewBanner.initTwoPartAndLoad(mMraidEvent.mraidActionHelper);
    prebidWebViewBanner.setWebViewDelegate(htmlCreative);
    prebidWebViewBanner.setCreative(htmlCreative);
    // Set a view before handling any action.
    htmlCreative.setCreativeView(prebidWebViewBanner);
    htmlCreative.setTwoPartNewWebViewBase(prebidWebViewBanner);
    mMraidController.expand(mOldWebViewBase, prebidWebViewBanner, mMraidEvent);
}
Also used : PrebidWebViewBase(org.prebid.mobile.rendering.views.webview.PrebidWebViewBase) PrebidWebViewBanner(org.prebid.mobile.rendering.views.webview.PrebidWebViewBanner) HTMLCreative(org.prebid.mobile.rendering.models.HTMLCreative)

Example 2 with PrebidWebViewBanner

use of org.prebid.mobile.rendering.views.webview.PrebidWebViewBanner in project prebid-mobile-android by prebid.

the class ViewPool method getUnoccupiedView.

// Q: why are we keeping it in occupied? Should we not put/get from unoccupied directly?
// A: Because, when a videoCreativeView is created, we will have to, anyways, add the view to the occupied bucket as it is going to be given to adView.
// So, do that step here itself.(distribution of work!)
public View getUnoccupiedView(Context context, VideoCreativeViewListener videoCreativeViewListener, AdConfiguration.AdUnitIdentifierType adType, InterstitialManager interstitialManager) throws AdException {
    if (context == null) {
        throw new AdException(AdException.INTERNAL_ERROR, "Context is null");
    }
    if (mUnoccupiedViews != null && mUnoccupiedViews.size() > 0) {
        View view = mUnoccupiedViews.get(0);
        Views.removeFromParent(view);
        // get item from unoccupied & add it to occupied
        swapToOccupied(view);
        return mOccupiedViews.get(mOccupiedViews.size() - 1);
    }
    switch(adType) {
        case BANNER:
            plugPlayView = new PrebidWebViewBanner(context, interstitialManager);
            break;
        case INTERSTITIAL:
            plugPlayView = new PrebidWebViewInterstitial(context, interstitialManager);
            // add it to occupied
            break;
        case VAST:
            plugPlayView = new ExoPlayerView(context, videoCreativeViewListener);
            break;
    }
    addToOccupied(plugPlayView);
    return plugPlayView;
}
Also used : PrebidWebViewInterstitial(org.prebid.mobile.rendering.views.webview.PrebidWebViewInterstitial) PrebidWebViewBanner(org.prebid.mobile.rendering.views.webview.PrebidWebViewBanner) ExoPlayerView(org.prebid.mobile.rendering.video.ExoPlayerView) View(android.view.View) ExoPlayerView(org.prebid.mobile.rendering.video.ExoPlayerView) AdException(org.prebid.mobile.rendering.errors.AdException)

Example 3 with PrebidWebViewBanner

use of org.prebid.mobile.rendering.views.webview.PrebidWebViewBanner in project prebid-mobile-android by prebid.

the class HTMLCreativeTest method loadTest.

@Test
public void loadTest() throws Exception {
    PrebidWebViewBanner mockPrebidWebViewBanner = mock(PrebidWebViewBanner.class);
    ViewPool mockViewPool = mock(ViewPool.class);
    when(mockViewPool.getUnoccupiedView(any(Context.class), any(), any(AdConfiguration.AdUnitIdentifierType.class), any(InterstitialManager.class))).thenReturn(mockPrebidWebViewBanner);
    WhiteBox.field(ViewPool.class, "sInstance").set(null, mockViewPool);
    // Test null context
    try {
        WhiteBox.field(HTMLCreative.class, "mContextReference").set(mHtmlCreative, null);
        mHtmlCreative.load();
        fail("AdException was NOT thrown");
    } catch (AdException e) {
    }
    mHtmlCreative = new HTMLCreative(mContext, mMockModel, mMockOmAdSessionManager, mMockInterstitialManager);
    // Test null adType
    try {
        mHtmlCreative.load();
        fail("AdException was NOT thrown");
    } catch (AdException e) {
    }
    // Test empty html
    try {
        when(mMockConfig.getAdUnitIdentifierType()).thenReturn(AdConfiguration.AdUnitIdentifierType.BANNER);
        mHtmlCreative = new HTMLCreative(mContext, mMockModel, mMockOmAdSessionManager, mMockInterstitialManager);
        mHtmlCreative.load();
        fail("AdException was NOT thrown");
    } catch (AdException e) {
    }
    // Test non-empty html
    when(mMockConfig.getAdUnitIdentifierType()).thenReturn(AdConfiguration.AdUnitIdentifierType.BANNER);
    when(mMockModel.getHtml()).thenReturn("foo");
    mHtmlCreative = new HTMLCreative(mContext, mMockModel, mMockOmAdSessionManager, mMockInterstitialManager);
    mHtmlCreative.load();
    verify(mockPrebidWebViewBanner).loadHTML(any(), anyInt(), anyInt());
    assertEquals(mockPrebidWebViewBanner, mHtmlCreative.getCreativeView());
}
Also used : Context(android.content.Context) InterstitialManager(org.prebid.mobile.rendering.views.interstitial.InterstitialManager) PrebidWebViewBanner(org.prebid.mobile.rendering.views.webview.PrebidWebViewBanner) AdException(org.prebid.mobile.rendering.errors.AdException) Test(org.junit.Test)

Aggregations

PrebidWebViewBanner (org.prebid.mobile.rendering.views.webview.PrebidWebViewBanner)3 AdException (org.prebid.mobile.rendering.errors.AdException)2 Context (android.content.Context)1 View (android.view.View)1 Test (org.junit.Test)1 HTMLCreative (org.prebid.mobile.rendering.models.HTMLCreative)1 ExoPlayerView (org.prebid.mobile.rendering.video.ExoPlayerView)1 InterstitialManager (org.prebid.mobile.rendering.views.interstitial.InterstitialManager)1 PrebidWebViewBase (org.prebid.mobile.rendering.views.webview.PrebidWebViewBase)1 PrebidWebViewInterstitial (org.prebid.mobile.rendering.views.webview.PrebidWebViewInterstitial)1