Search in sources :

Example 1 with InterstitialControllerListener

use of org.prebid.mobile.rendering.bidding.interfaces.InterstitialControllerListener in project prebid-mobile-android by prebid.

the class PrebidRewardedAdapter method getListener.

private InterstitialControllerListener getListener(MediationAdLoadCallback<MediationRewardedAd, MediationRewardedAdCallback> adMobCallback) {
    return new InterstitialControllerListener() {

        @Override
        public void onInterstitialReadyForDisplay() {
            rewardedAdCallback = adMobCallback.onSuccess(context -> {
                interstitialController.show();
            });
        }

        @Override
        public void onInterstitialDisplayed() {
            rewardedAdCallback.onAdOpened();
            rewardedAdCallback.onVideoStart();
            rewardedAdCallback.reportAdImpression();
        }

        @Override
        public void onInterstitialClicked() {
            rewardedAdCallback.reportAdClicked();
        }

        @Override
        public void onInterstitialFailedToLoad(AdException exception) {
            String errorMessage = exception.getMessage() != null ? exception.getMessage() : "Failed to load ad";
            AdError adError = new AdError(1006, errorMessage, "prebid");
            adMobCallback.onFailure(adError);
            if (rewardedAdCallback != null) {
                rewardedAdCallback.onAdFailedToShow(adError);
            }
        }

        @Override
        public void onInterstitialClosed() {
            rewardedAdCallback.onVideoComplete();
            rewardedAdCallback.onAdClosed();
        }
    };
}
Also used : InterstitialControllerListener(org.prebid.mobile.rendering.bidding.interfaces.InterstitialControllerListener) RewardItem(com.google.android.gms.ads.rewarded.RewardItem) InterstitialControllerListener(org.prebid.mobile.rendering.bidding.interfaces.InterstitialControllerListener) Bundle(android.os.Bundle) AdException(org.prebid.mobile.rendering.errors.AdException) NonNull(androidx.annotation.NonNull) MediationRewardedAd(com.google.android.gms.ads.mediation.MediationRewardedAd) HashMap(java.util.HashMap) AdError(com.google.android.gms.ads.AdError) InterstitialController(org.prebid.mobile.rendering.bidding.display.InterstitialController) Keep(androidx.annotation.Keep) BidResponseCache(org.prebid.mobile.rendering.bidding.display.BidResponseCache) MediationRewardedAdConfiguration(com.google.android.gms.ads.mediation.MediationRewardedAdConfiguration) MediationRewardedAdCallback(com.google.android.gms.ads.mediation.MediationRewardedAdCallback) MediationAdLoadCallback(com.google.android.gms.ads.mediation.MediationAdLoadCallback) Log(android.util.Log) AdError(com.google.android.gms.ads.AdError) AdException(org.prebid.mobile.rendering.errors.AdException)

Example 2 with InterstitialControllerListener

use of org.prebid.mobile.rendering.bidding.interfaces.InterstitialControllerListener 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 3 with InterstitialControllerListener

use of org.prebid.mobile.rendering.bidding.interfaces.InterstitialControllerListener 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)

Example 4 with InterstitialControllerListener

use of org.prebid.mobile.rendering.bidding.interfaces.InterstitialControllerListener in project prebid-mobile-android by prebid.

the class PrebidRewardedAdapter method loadRewardedAd.

@Override
public void loadRewardedAd(@NonNull MediationRewardedAdConfiguration adConfiguration, @NonNull MediationAdLoadCallback<MediationRewardedAd, MediationRewardedAdCallback> callback) {
    Bundle serverParameters = adConfiguration.getServerParameters();
    String adMobParameters = serverParameters.getString("parameter");
    String adMobClassName = serverParameters.getString("class_name");
    if (!adMobClassName.equals(CLASS_NAME)) {
        String error = "Class name is different";
        callback.onFailure(new AdError(1001, error, "prebid"));
        return;
    }
    String responseId = adConfiguration.getMediationExtras().getString(EXTRA_RESPONSE_ID);
    if (responseId == null) {
        String error = "Empty response id";
        callback.onFailure(new AdError(1002, error, "prebid"));
        return;
    }
    HashMap<String, String> prebidParameters = BidResponseCache.getInstance().getKeywords(responseId);
    if (prebidParameters == null) {
        String error = "Prebid keywords are empty";
        callback.onFailure(new AdError(1003, error, "prebid"));
        return;
    }
    if (!ParametersMatcher.doParametersMatch(adMobParameters, prebidParameters)) {
        String error = "Parameters are different";
        callback.onFailure(new AdError(1004, error, "prebid"));
        return;
    }
    try {
        InterstitialControllerListener listener = getListener(callback);
        interstitialController = new InterstitialController(adConfiguration.getContext(), listener);
        interstitialController.loadAd(responseId, true);
    } catch (AdException e) {
        String error = "Exception in Prebid interstitial controller (" + e.getMessage() + ")";
        Log.e(TAG, error);
        callback.onFailure(new AdError(1005, error, "prebid"));
    }
}
Also used : InterstitialControllerListener(org.prebid.mobile.rendering.bidding.interfaces.InterstitialControllerListener) Bundle(android.os.Bundle) InterstitialController(org.prebid.mobile.rendering.bidding.display.InterstitialController) AdError(com.google.android.gms.ads.AdError) AdException(org.prebid.mobile.rendering.errors.AdException)

Aggregations

AdError (com.google.android.gms.ads.AdError)4 InterstitialControllerListener (org.prebid.mobile.rendering.bidding.interfaces.InterstitialControllerListener)4 AdException (org.prebid.mobile.rendering.errors.AdException)4 InterstitialController (org.prebid.mobile.rendering.bidding.display.InterstitialController)3 Bundle (android.os.Bundle)2 Log (android.util.Log)1 Keep (androidx.annotation.Keep)1 NonNull (androidx.annotation.NonNull)1 MediationAdLoadCallback (com.google.android.gms.ads.mediation.MediationAdLoadCallback)1 MediationRewardedAd (com.google.android.gms.ads.mediation.MediationRewardedAd)1 MediationRewardedAdCallback (com.google.android.gms.ads.mediation.MediationRewardedAdCallback)1 MediationRewardedAdConfiguration (com.google.android.gms.ads.mediation.MediationRewardedAdConfiguration)1 RewardItem (com.google.android.gms.ads.rewarded.RewardItem)1 HashMap (java.util.HashMap)1 BidResponseCache (org.prebid.mobile.rendering.bidding.display.BidResponseCache)1