Search in sources :

Example 1 with DisplayViewListener

use of org.prebid.mobile.rendering.bidding.listeners.DisplayViewListener in project prebid-mobile-android by prebid.

the class PrebidBannerAdapter method getListener.

@NonNull
private DisplayViewListener getListener(CustomEventBannerListener adMobListener) {
    return new DisplayViewListener() {

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

        @Override
        public void onAdDisplayed() {
        }

        @Override
        public void onAdFailed(AdException exception) {
            String message = exception.getMessage();
            if (message == null)
                message = "Failed to load DisplayView ad";
            adMobListener.onAdFailedToLoad(new AdError(1010, message, "prebid"));
        }

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

        @Override
        public void onAdClosed() {
            adMobListener.onAdClosed();
        }
    };
}
Also used : DisplayViewListener(org.prebid.mobile.rendering.bidding.listeners.DisplayViewListener) AdError(com.google.android.gms.ads.AdError) AdException(org.prebid.mobile.rendering.errors.AdException) NonNull(androidx.annotation.NonNull)

Example 2 with DisplayViewListener

use of org.prebid.mobile.rendering.bidding.listeners.DisplayViewListener in project prebid-mobile-android by prebid.

the class PrebidBannerAdapter method requestBannerAd.

@Override
public void requestBannerAd(@NonNull Context context, @NonNull CustomEventBannerListener adMobListener, @Nullable String serverParameter, @NonNull AdSize adSize, @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 + ")");
    BidResponse response = BidResponseCache.getInstance().popBidResponse(responseId);
    if (response == null) {
        String error = "There's no response for the response id: " + responseId;
        adMobListener.onAdFailedToLoad(new AdError(1004, error, "prebid"));
        return;
    }
    AdConfiguration adConfiguration = new AdConfiguration();
    adConfiguration.setAdUnitIdentifierType(AdConfiguration.AdUnitIdentifierType.BANNER);
    DisplayViewListener listener = getListener(adMobListener);
    adView = new DisplayView(context, listener, adConfiguration, response);
}
Also used : DisplayViewListener(org.prebid.mobile.rendering.bidding.listeners.DisplayViewListener) AdConfiguration(org.prebid.mobile.rendering.models.AdConfiguration) BidResponse(org.prebid.mobile.rendering.bidding.data.bid.BidResponse) AdError(com.google.android.gms.ads.AdError) DisplayView(org.prebid.mobile.rendering.bidding.display.DisplayView)

Aggregations

AdError (com.google.android.gms.ads.AdError)2 DisplayViewListener (org.prebid.mobile.rendering.bidding.listeners.DisplayViewListener)2 NonNull (androidx.annotation.NonNull)1 BidResponse (org.prebid.mobile.rendering.bidding.data.bid.BidResponse)1 DisplayView (org.prebid.mobile.rendering.bidding.display.DisplayView)1 AdException (org.prebid.mobile.rendering.errors.AdException)1 AdConfiguration (org.prebid.mobile.rendering.models.AdConfiguration)1