com.applovin.sdk.AppLovinAdLoadListener Java Examples
The following examples show how to use
com.applovin.sdk.AppLovinAdLoadListener.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApplovinAdapter.java From googleads-mobile-android-mediation with Apache License 2.0 | 4 votes |
@Override public void requestInterstitialAd( Context context, MediationInterstitialListener interstitialListener, Bundle serverParameters, MediationAdRequest mediationAdRequest, Bundle networkExtras) { if (!(context instanceof Activity)) { String adapterError = createAdapterError( ERROR_CONTEXT_NOT_ACTIVITY, "AppLovin requires an Activity context to load ads."); log(ERROR, "Failed to load interstitial ad from AppLovin: " + adapterError); interstitialListener.onAdFailedToLoad(ApplovinAdapter.this, ERROR_CONTEXT_NOT_ACTIVITY); return; } // Store parent objects. mSdk = AppLovinUtils.retrieveSdk(serverParameters, context); mContext = context; mNetworkExtras = networkExtras; mMediationInterstitialListener = interstitialListener; mZoneId = AppLovinUtils.retrieveZoneId(serverParameters); log(DEBUG, "Requesting interstitial for zone: " + mZoneId); // Create Ad Load listener. final AppLovinAdLoadListener adLoadListener = new AppLovinAdLoadListener() { @Override public void adReceived(final AppLovinAd ad) { log(DEBUG, "Interstitial did load ad: " + ad.getAdIdNumber() + " for zone: " + mZoneId); synchronized (INTERSTITIAL_AD_QUEUES_LOCK) { Queue<AppLovinAd> preloadedAds = INTERSTITIAL_AD_QUEUES.get(mZoneId); if (preloadedAds == null) { preloadedAds = new LinkedList<>(); INTERSTITIAL_AD_QUEUES.put(mZoneId, preloadedAds); } preloadedAds.offer(ad); AppLovinSdkUtils.runOnUiThread( new Runnable() { @Override public void run() { mMediationInterstitialListener.onAdLoaded(ApplovinAdapter.this); } }); } } @Override public void failedToReceiveAd(final int code) { String errorMessage = createSDKError(code); log(ERROR, errorMessage); AppLovinSdkUtils.runOnUiThread( new Runnable() { @Override public void run() { mMediationInterstitialListener.onAdFailedToLoad(ApplovinAdapter.this, code); } }); } }; synchronized (INTERSTITIAL_AD_QUEUES_LOCK) { final Queue<AppLovinAd> queue = INTERSTITIAL_AD_QUEUES.get(mZoneId); if (queue == null || (queue != null && queue.isEmpty())) { // If we don't already have enqueued ads, fetch from SDK. if (!TextUtils.isEmpty(mZoneId)) { mSdk.getAdService().loadNextAdForZoneId(mZoneId, adLoadListener); } else { mSdk.getAdService().loadNextAd(AppLovinAdSize.INTERSTITIAL, adLoadListener); } } else { log(DEBUG, "Enqueued interstitial found. Finishing load..."); AppLovinSdkUtils.runOnUiThread( new Runnable() { @Override public void run() { mMediationInterstitialListener.onAdLoaded(ApplovinAdapter.this); } }); } } }