com.applovin.sdk.AppLovinAdSize Java Examples
The following examples show how to use
com.applovin.sdk.AppLovinAdSize.
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: AppLovinUtils.java From googleads-mobile-android-mediation with Apache License 2.0 | 6 votes |
/** Get the {@link AppLovinAdSize} from a given {@link AdSize} from AdMob. */ @Nullable public static AppLovinAdSize appLovinAdSizeFromAdMobAdSize( @NonNull Context context, @NonNull AdSize adSize) { ArrayList<AdSize> potentials = new ArrayList<>(); potentials.add(AdSize.BANNER); potentials.add(AdSize.LEADERBOARD); potentials.add(AdSize.MEDIUM_RECTANGLE); AdSize closestSize = MediationUtils.findClosestSize(context, adSize, potentials); if (AdSize.BANNER.equals(closestSize)) { return AppLovinAdSize.BANNER; } else if (AdSize.MEDIUM_RECTANGLE.equals(closestSize)) { return AppLovinAdSize.MREC; } else if (AdSize.LEADERBOARD.equals(closestSize)) { return AppLovinAdSize.LEADER; } return null; }
Example #2
Source File: AppLovinRtbBannerRenderer.java From googleads-mobile-android-mediation with Apache License 2.0 | 5 votes |
public void loadAd() { Context context = adConfiguration.getContext(); if (!(context instanceof Activity)) { String adapterError = createAdapterError( ERROR_CONTEXT_NOT_ACTIVITY, "AppLovin requires an Activity context to load ads."); Log.e(TAG, "Failed to load banner ad from AppLovin: " + adapterError); callback.onFailure(adapterError); return; } AppLovinAdSize adSize = AppLovinUtils.appLovinAdSizeFromAdMobAdSize(context, adConfiguration.getAdSize()); if (adSize == null) { String errorMessage = createAdapterError( ERROR_BANNER_SIZE_MISMATCH, "Failed to request banner with unsupported size."); callback.onFailure(errorMessage); return; } AppLovinSdk sdk = AppLovinUtils.retrieveSdk(adConfiguration.getServerParameters(), context); adView = new AppLovinAdView(sdk, adSize, context); adView.setAdDisplayListener(this); adView.setAdClickListener(this); adView.setAdViewEventListener(this); // Load ad! sdk.getAdService().loadNextAdForAdToken(adConfiguration.getBidResponse(), this); }
Example #3
Source File: AppLovinCustomEventBanner.java From SDK-Network-Adapters with MIT License | 5 votes |
private AppLovinAdSize appLovinAdSizeFromAdMobAdSize(final AdSize adSize) { final boolean isSmartBanner = ( adSize.getWidth() == AdSize.FULL_WIDTH ) && ( adSize.getHeight() == AdSize.AUTO_HEIGHT ); if ( AdSize.BANNER.equals( adSize ) || AdSize.LARGE_BANNER.equals( adSize ) || isSmartBanner ) { return AppLovinAdSize.BANNER; } else if ( AdSize.MEDIUM_RECTANGLE.equals( adSize ) ) { return AppLovinAdSize.MREC; } else if ( AdSize.LEADERBOARD.equals( adSize ) ) { return AppLovinAdSize.LEADER; } // This is not a one of AdMob's predefined size else { // Assume fluid width, and check for height with offset tolerance final int offset = Math.abs( BANNER_STANDARD_HEIGHT - adSize.getHeight() ); if ( offset <= BANNER_HEIGHT_OFFSET_TOLERANCE ) { return AppLovinAdSize.BANNER; } } return null; }
Example #4
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); } }); } } }
Example #5
Source File: ApplovinAdapter.java From googleads-mobile-android-mediation with Apache License 2.0 | 4 votes |
@Override public void requestBannerAd( Context context, final MediationBannerListener mediationBannerListener, Bundle serverParameters, AdSize adSize, 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 banner ad from AppLovin: " + adapterError); mediationBannerListener.onAdFailedToLoad(ApplovinAdapter.this, ERROR_CONTEXT_NOT_ACTIVITY); return; } // Store parent objects mSdk = AppLovinUtils.retrieveSdk(serverParameters, context); mZoneId = AppLovinUtils.retrieveZoneId(serverParameters); // Convert requested size to AppLovin Ad Size. final AppLovinAdSize appLovinAdSize = AppLovinUtils.appLovinAdSizeFromAdMobAdSize(context, adSize); if (appLovinAdSize == null) { String errorMessage = createAdapterError( ERROR_BANNER_SIZE_MISMATCH, "Failed to request banner with unsupported size: " + adSize.toString()); log(ERROR, errorMessage); if (mediationBannerListener != null) { mediationBannerListener.onAdFailedToLoad(ApplovinAdapter.this, ERROR_BANNER_SIZE_MISMATCH); } } log(DEBUG, "Requesting banner of size " + appLovinAdSize + " for zone: " + mZoneId); mAdView = new AppLovinAdView(mSdk, appLovinAdSize, context); final AppLovinBannerAdListener listener = new AppLovinBannerAdListener(mZoneId, mAdView, this, mediationBannerListener); mAdView.setAdDisplayListener(listener); mAdView.setAdClickListener(listener); mAdView.setAdViewEventListener(listener); if (!TextUtils.isEmpty(mZoneId)) { mSdk.getAdService().loadNextAdForZoneId(mZoneId, listener); } else { mSdk.getAdService().loadNextAd(appLovinAdSize, listener); } }
Example #6
Source File: AppLovinCustomEventBanner.java From SDK-Network-Adapters with MIT License | 4 votes |
private AppLovinAdSize appLovinAdSizeFromLocalExtras(final Map<String, Object> localExtras) { // Handle trivial case if ( localExtras == null || localExtras.isEmpty() ) { log( ERROR, "No serverExtras provided" ); return null; } try { final int width = (Integer) localExtras.get( AD_WIDTH_KEY ); final int height = (Integer) localExtras.get( AD_HEIGHT_KEY ); // We have valid dimensions if ( width > 0 && height > 0 ) { log( DEBUG, "Valid width (" + width + ") and height (" + height + ") provided" ); // Assume fluid width, and check for height with offset tolerance final int bannerOffset = Math.abs( BANNER_STANDARD_HEIGHT - height ); final int leaderOffset = Math.abs( LEADER_STANDARD_HEIGHT - height ); if ( bannerOffset <= BANNER_HEIGHT_OFFSET_TOLERANCE ) { return AppLovinAdSize.BANNER; } else if ( leaderOffset <= LEADER_HEIGHT_OFFSET_TOLERANCE ) { return AppLovinAdSize.LEADER; } else if ( height <= AppLovinAdSize.MREC.getHeight() ) { return AppLovinAdSize.MREC; } else { log( ERROR, "Provided dimensions does not meet the dimensions required of banner or mrec ads" ); } } else { log( ERROR, "Invalid width (" + width + ") and height (" + height + ") provided" ); } } catch ( Throwable th ) { log( ERROR, "Encountered error while parsing width and height from serverExtras", th ); } return null; }
Example #7
Source File: AppLovinCustomEventInterstitial.java From SDK-Network-Adapters with MIT License | 4 votes |
@Override public void loadInterstitial(final Context context, final CustomEventInterstitialListener listener, final Map<String, Object> localExtras, final Map<String, String> serverExtras) { log( DEBUG, "Requesting AppLovin interstitial with serverExtras: " + serverExtras + " and localExtras: " + localExtras ); // SDK versions BELOW 7.2.0 require a instance of an Activity to be passed in as the context if ( AppLovinSdk.VERSION_CODE < 720 && !( context instanceof Activity ) ) { log( ERROR, "Unable to request AppLovin banner. Invalid context provided." ); listener.onInterstitialFailed( MoPubErrorCode.ADAPTER_CONFIGURATION_ERROR ); return; } // Pass the user consent from the MoPub SDK as per GDPR PersonalInfoManager personalInfoManager = MoPub.getPersonalInformationManager(); if ( personalInfoManager != null && personalInfoManager.gdprApplies() ) { boolean canCollectPersonalInfo = personalInfoManager.canCollectPersonalInformation(); AppLovinPrivacySettings.setHasUserConsent( canCollectPersonalInfo, context ); } // Store parent objects this.listener = listener; this.context = context; sdk = retrieveSdk( serverExtras, context ); sdk.setPluginVersion( "MoPub-3.0.0" ); // Zones support is available on AppLovin SDK 7.5.0 and higher final String serverExtrasZoneId = serverExtras != null ? serverExtras.get( "zone_id" ) : null; zoneId = ( !TextUtils.isEmpty( serverExtrasZoneId ) && AppLovinSdk.VERSION_CODE >= 750 ) ? serverExtrasZoneId : DEFAULT_ZONE; // Check if we already have a preloaded ad for the given zone final AppLovinAd preloadedAd = dequeueAd( zoneId ); if ( preloadedAd != null ) { log( DEBUG, "Found preloaded ad for zone: {" + zoneId + "}" ); adReceived( preloadedAd ); } else { // If this is a default Zone, create the incentivized ad normally if ( DEFAULT_ZONE.equals( zoneId ) ) { sdk.getAdService().loadNextAd( AppLovinAdSize.INTERSTITIAL, this ); } // Otherwise, use the Zones API else { sdk.getAdService().loadNextAdForZoneId( zoneId, this ); } } }
Example #8
Source File: AppLovinCustomEventInterstitial.java From SDK-Network-Adapters with MIT License | 4 votes |
@Override public void requestInterstitialAd(final Context context, final CustomEventInterstitialListener listener, final String serverParameter, final MediationAdRequest mediationAdRequest, final Bundle customEventExtras) { log( DEBUG, "Requesting AppLovin interstitial..." ); // SDK versions BELOW 7.2.0 require a instance of an Activity to be passed in as the context if ( AppLovinSdk.VERSION_CODE < 720 && !( context instanceof Activity ) ) { log( ERROR, "Unable to request AppLovin interstitial. Invalid context provided." ); listener.onAdFailedToLoad( AdRequest.ERROR_CODE_INVALID_REQUEST ); return; } // Store parent objects this.listener = listener; this.context = context; final AppLovinSdk sdk = AppLovinSdk.getInstance( context ); sdk.setPluginVersion( "AdMob-2.2.1" ); // Zones support is available on AppLovin SDK 7.5.0 and higher if ( AppLovinSdk.VERSION_CODE >= 750 && customEventExtras != null && customEventExtras.containsKey( "zone_id" ) ) { zoneId = customEventExtras.getString( "zone_id" ); } else { zoneId = DEFAULT_ZONE; } // Check if we already have a preloaded ad for the given zone final AppLovinAd preloadedAd = dequeueAd( zoneId ); if ( preloadedAd != null ) { log( DEBUG, "Found preloaded ad for zone: {" + zoneId + "}" ); adReceived( preloadedAd ); } else { // If this is a default Zone, load the interstitial ad normally if ( DEFAULT_ZONE.equals( zoneId ) ) { sdk.getAdService().loadNextAd( AppLovinAdSize.INTERSTITIAL, this ); } // Otherwise, use the Zones API else { sdk.getAdService().loadNextAdForZoneId( zoneId, this ); } } }