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();
}
};
}
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"));
}
};
}
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"));
}
}
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"));
}
}
Aggregations