Search in sources :

Example 46 with AdException

use of org.prebid.mobile.rendering.errors.AdException in project prebid-mobile-android by prebid.

the class DisplayViewTest method whenAdViewManagerListenerFailedToLoad_NotifyListenerOnAdFailed.

@Test
public void whenAdViewManagerListenerFailedToLoad_NotifyListenerOnAdFailed() throws IllegalAccessException {
    AdViewManagerListener adViewManagerListener = getAdViewManagerListener();
    adViewManagerListener.failedToLoad(new AdException(AdException.INTERNAL_ERROR, "Test"));
    verify(mMockDisplayViewListener).onAdFailed(any(AdException.class));
}
Also used : AdViewManagerListener(org.prebid.mobile.rendering.views.AdViewManagerListener) AdException(org.prebid.mobile.rendering.errors.AdException) Test(org.junit.Test)

Example 47 with AdException

use of org.prebid.mobile.rendering.errors.AdException in project prebid-mobile-android by prebid.

the class TransactionTest method onSuccessWithCreativeTimeout_TransactionListenerSuccessNotCalled.

@Test
public void onSuccessWithCreativeTimeout_TransactionListenerSuccessNotCalled() throws Exception {
    List<CreativeModel> creativeModels = Arrays.asList(mock(CreativeModel.class), mock(CreativeModel.class));
    Transaction.Listener mockListener = mock(Transaction.Listener.class);
    InterstitialManager mockInterstitialManager = mock(InterstitialManager.class);
    Transaction transaction = Transaction.createTransaction(mMockContext, createModelResult(creativeModels, ""), mockInterstitialManager, mockListener);
    Transaction.CreativeFactoryListener creativeFactoryListener = new Transaction.CreativeFactoryListener(transaction);
    Iterator<CreativeFactory> mockIterator = mock(Iterator.class);
    when(mockIterator.hasNext()).thenReturn(true);
    when(mockIterator.next()).thenReturn(mock(CreativeFactory.class));
    WhiteBox.setInternalState(transaction, "mCreativeFactoryIterator", mockIterator);
    creativeFactoryListener.onSuccess();
    verify(mockListener, never()).onTransactionSuccess(transaction);
    AdException adException = new AdException(AdException.INTERNAL_ERROR, "CreativeFactory Timeout");
    creativeFactoryListener.onFailure(adException);
    verify(mockListener).onTransactionFailure(eq(adException), anyString());
}
Also used : CreativeModel(org.prebid.mobile.rendering.models.CreativeModel) InterstitialManager(org.prebid.mobile.rendering.views.interstitial.InterstitialManager) AdException(org.prebid.mobile.rendering.errors.AdException) Test(org.junit.Test)

Example 48 with AdException

use of org.prebid.mobile.rendering.errors.AdException in project prebid-mobile-android by prebid.

the class PrebidWebViewBanner method preloaded.

@Override
public void preloaded(WebViewBase adBaseView) {
    if (adBaseView == null) {
        // This should never happen.
        LogUtil.error(TAG, "Failed to preload a banner ad. Webview is null.");
        if (mWebViewDelegate != null) {
            mWebViewDelegate.webViewFailedToLoad(new AdException(AdException.INTERNAL_ERROR, "Preloaded adview is null!"));
        }
        return;
    }
    mCurrentWebViewBase = adBaseView;
    if (mCurrentWebViewBase.mMRAIDBridgeName.equals("twopart")) {
        // SHould have expanded url here, as last param
        mInterstitialManager.displayPrebidWebViewForMraid(mMraidWebView, true);
    } else {
        if (adBaseView.getParent() == null) {
            if (getChildCount() >= 1) {
                LogUtil.debug(TAG, "Adding second view");
                // safe removal from parent before adding
                Views.removeFromParent(adBaseView);
                addView(adBaseView, 1);
                adBaseView.bringToFront();
                swapWebViews();
            } else {
                LogUtil.debug(TAG, "Adding first view");
                // safe removal from parent before adding
                Views.removeFromParent(adBaseView);
                addView(adBaseView, 0);
                renderAdView(adBaseView);
            }
        } else {
            LogUtil.debug(TAG, "Adding the only view");
            adBaseView.bringToFront();
            swapWebViews();
        }
    }
    /*
         * This postInvalidate fixes the cosmetic issue that KitKat created with the white banner
         * fragment/remnant showing up at the bottom of the screen.
         */
    if (mContext instanceof Activity) {
        ((Activity) mContext).getWindow().getDecorView().findViewById(android.R.id.content).postInvalidate();
        ((Activity) mContext).getWindow().getDecorView().findViewById(android.R.id.content).postInvalidateDelayed(100);
    }
    if (mWebViewDelegate != null) {
        mWebViewDelegate.webViewReadyToDisplay();
    }
}
Also used : Activity(android.app.Activity) AdException(org.prebid.mobile.rendering.errors.AdException)

Example 49 with AdException

use of org.prebid.mobile.rendering.errors.AdException in project prebid-mobile-android by prebid.

the class PrebidInterstitialAdapter method getListener.

private InterstitialControllerListener getListener(CustomEventInterstitialListener adMobListener) {
    return new InterstitialControllerListener() {

        @Override
        public void onInterstitialReadyForDisplay() {
            adMobListener.onAdLoaded();
        }

        @Override
        public void onInterstitialDisplayed() {
            adMobListener.onAdOpened();
        }

        @Override
        public void onInterstitialClicked() {
            adMobListener.onAdClicked();
        }

        @Override
        public void onInterstitialClosed() {
            adMobListener.onAdClosed();
        }

        @Override
        public void onInterstitialFailedToLoad(AdException exception) {
            String error = "Failed to load ad: " + exception.getMessage();
            Log.e(TAG, error);
            adMobListener.onAdFailedToLoad(new AdError(1005, error, "prebid"));
        }
    };
}
Also used : InterstitialControllerListener(org.prebid.mobile.rendering.bidding.interfaces.InterstitialControllerListener) AdError(com.google.android.gms.ads.AdError) AdException(org.prebid.mobile.rendering.errors.AdException)

Example 50 with AdException

use of org.prebid.mobile.rendering.errors.AdException in project prebid-mobile-android by prebid.

the class PrebidInterstitialAdapter method requestInterstitialAd.

@Override
public void requestInterstitialAd(@NonNull Context context, @NonNull CustomEventInterstitialListener adMobListener, @Nullable String serverParameter, @NonNull MediationAdRequest mediationAdRequest, @Nullable Bundle extras) {
    if (extras == null) {
        String error = "Extras are empty! Check if you add custom event extras bundle to  " + TAG;
        Log.e(TAG, error);
        adMobListener.onAdFailedToLoad(new AdError(1001, error, "prebid"));
        return;
    }
    String responseId = extras.getString(EXTRA_RESPONSE_ID);
    if (responseId == null) {
        String error = "Response id is null";
        adMobListener.onAdFailedToLoad(new AdError(1002, error, "prebid"));
        return;
    }
    HashMap<String, String> prebidParameters = BidResponseCache.getInstance().getKeywords(responseId);
    if (!ParametersMatcher.doParametersMatch(serverParameter, prebidParameters)) {
        String error = "Parameters are different";
        adMobListener.onAdFailedToLoad(new AdError(1003, error, "prebid"));
        return;
    }
    LogUtil.v(TAG, "Parameters are matched! (" + serverParameter + ")");
    try {
        InterstitialControllerListener listener = getListener(adMobListener);
        interstitialController = new InterstitialController(context, listener);
        interstitialController.loadAd(responseId, false);
    } catch (AdException e) {
        String error = "Exception in Prebid interstitial controller (" + e.getMessage() + ")";
        Log.e(TAG, error);
        adMobListener.onAdFailedToLoad(new AdError(1004, error, "prebid"));
    }
}
Also used : InterstitialControllerListener(org.prebid.mobile.rendering.bidding.interfaces.InterstitialControllerListener) InterstitialController(org.prebid.mobile.rendering.bidding.display.InterstitialController) AdError(com.google.android.gms.ads.AdError) AdException(org.prebid.mobile.rendering.errors.AdException)

Aggregations

AdException (org.prebid.mobile.rendering.errors.AdException)54 Test (org.junit.Test)25 InterstitialController (org.prebid.mobile.rendering.bidding.display.InterstitialController)7 AdConfiguration (org.prebid.mobile.rendering.models.AdConfiguration)6 AdError (com.google.android.gms.ads.AdError)5 BidResponse (org.prebid.mobile.rendering.bidding.data.bid.BidResponse)5 Bid (org.prebid.mobile.rendering.bidding.data.bid.Bid)4 InterstitialControllerListener (org.prebid.mobile.rendering.bidding.interfaces.InterstitialControllerListener)4 CreativeModel (org.prebid.mobile.rendering.models.CreativeModel)4 InterstitialManager (org.prebid.mobile.rendering.views.interstitial.InterstitialManager)4 Context (android.content.Context)2 Bundle (android.os.Bundle)2 NonNull (androidx.annotation.NonNull)2 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 InterstitialView (org.prebid.mobile.rendering.bidding.display.InterstitialView)2 BannerEventListener (org.prebid.mobile.rendering.bidding.listeners.BannerEventListener)2 InterstitialEventListener (org.prebid.mobile.rendering.bidding.listeners.InterstitialEventListener)2 RewardedVideoEventListener (org.prebid.mobile.rendering.bidding.listeners.RewardedVideoEventListener)2 VastExtractorResult (org.prebid.mobile.rendering.models.internal.VastExtractorResult)2