Java Code Examples for com.google.android.gms.ads.AdSize#getWidth()
The following examples show how to use
com.google.android.gms.ads.AdSize#getWidth() .
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: RNPublisherBannerViewManager.java From react-native-admob with BSD 2-Clause "Simplified" License | 6 votes |
private void sendOnSizeChangeEvent() { int width; int height; ReactContext reactContext = (ReactContext) getContext(); WritableMap event = Arguments.createMap(); AdSize adSize = this.adView.getAdSize(); if (adSize == AdSize.SMART_BANNER) { width = (int) PixelUtil.toDIPFromPixel(adSize.getWidthInPixels(reactContext)); height = (int) PixelUtil.toDIPFromPixel(adSize.getHeightInPixels(reactContext)); } else { width = adSize.getWidth(); height = adSize.getHeight(); } event.putDouble("width", width); event.putDouble("height", height); sendEvent(RNPublisherBannerViewManager.EVENT_SIZE_CHANGE, event); }
Example 2
Source File: RNAdMobBannerViewManager.java From react-native-admob with BSD 2-Clause "Simplified" License | 6 votes |
private void sendOnSizeChangeEvent() { int width; int height; ReactContext reactContext = (ReactContext) getContext(); WritableMap event = Arguments.createMap(); AdSize adSize = this.adView.getAdSize(); if (this.adSize == AdSize.SMART_BANNER) { width = (int) PixelUtil.toDIPFromPixel(adSize.getWidthInPixels(reactContext)); height = (int) PixelUtil.toDIPFromPixel(adSize.getHeightInPixels(reactContext)); } else { width = adSize.getWidth(); height = adSize.getHeight(); } event.putDouble("width", width); event.putDouble("height", height); sendEvent(RNAdMobBannerViewManager.EVENT_SIZE_CHANGE, event); }
Example 3
Source File: VungleInterstitialAdapter.java From googleads-mobile-android-mediation with Apache License 2.0 | 5 votes |
private boolean hasBannerSizeAd(Context context, AdSize adSize, AdConfig adConfig) { ArrayList<AdSize> potentials = new ArrayList<>(); potentials.add(new AdSize(BANNER_SHORT.getWidth(), BANNER_SHORT.getHeight())); potentials.add(new AdSize(BANNER.getWidth(), BANNER.getHeight())); potentials.add(new AdSize(BANNER_LEADERBOARD.getWidth(), BANNER_LEADERBOARD.getHeight())); potentials.add(new AdSize(VUNGLE_MREC.getWidth(), VUNGLE_MREC.getHeight())); AdSize closestSize = MediationUtils.findClosestSize(context, adSize, potentials); if (closestSize == null) { Log.i(TAG, "Not found closest ad size: " + adSize); return false; } Log.i( TAG, "Found closest ad size: " + closestSize.toString() + " for requested ad size: " + adSize); if (closestSize.getWidth() == BANNER_SHORT.getWidth() && closestSize.getHeight() == BANNER_SHORT.getHeight()) { adConfig.setAdSize(BANNER_SHORT); } else if (closestSize.getWidth() == BANNER.getWidth() && closestSize.getHeight() == BANNER.getHeight()) { adConfig.setAdSize(BANNER); } else if (closestSize.getWidth() == BANNER_LEADERBOARD.getWidth() && closestSize.getHeight() == BANNER_LEADERBOARD.getHeight()) { adConfig.setAdSize(BANNER_LEADERBOARD); } else if (closestSize.getWidth() == VUNGLE_MREC.getWidth() && closestSize.getHeight() == VUNGLE_MREC.getHeight()) { adConfig.setAdSize(VUNGLE_MREC); } return true; }
Example 4
Source File: NendAdapter.java From googleads-mobile-android-mediation with Apache License 2.0 | 5 votes |
@Nullable private AdSize getSupportedAdSize(@NonNull Context context, @NonNull AdSize adSize) { // Check if the specified adSize is a Smart banner since nend supports any Smart banner with at // least a height of 50. if (adSize.getWidth() == AdSize.FULL_WIDTH && adSize.getHeight() == AdSize.AUTO_HEIGHT) { DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics(); final int heightPixel = adSize.getHeightInPixels(context); final int heightDip = Math.round(heightPixel / displayMetrics.density); if (heightDip >= 50) { return adSize; } } /* Supported Sizes: https://github.com/fan-ADN/nendSDK-Android/wiki/About-Ad-Sizes#available-ad-sizes-are-listed-below. 320 × 50 320 × 100 300 × 100 300 × 250 728 × 90 */ ArrayList<AdSize> potentials = new ArrayList<>(); potentials.add(AdSize.BANNER); potentials.add(AdSize.LARGE_BANNER); potentials.add(new AdSize(300, 100)); potentials.add(AdSize.MEDIUM_RECTANGLE); potentials.add(AdSize.LEADERBOARD); return MediationUtils.findClosestSize(context, adSize, potentials); }
Example 5
Source File: FacebookAdapter.java From googleads-mobile-android-mediation with Apache License 2.0 | 5 votes |
@Nullable private com.facebook.ads.AdSize getAdSize(@NonNull Context context, @NonNull AdSize adSize) { // Get the actual width of the ad size since Smart Banners and FULL_WIDTH sizes return a // width of -1. int width = adSize.getWidth(); if (width < 0) { float density = context.getResources().getDisplayMetrics().density; width = Math.round(adSize.getWidthInPixels(context) / density); } ArrayList<AdSize> potentials = new ArrayList<>(3); potentials.add(0, new AdSize(width, 50)); potentials.add(1, new AdSize(width, 90)); potentials.add(2, new AdSize(width, 250)); Log.i(TAG, "Potential ad sizes: " + potentials.toString()); AdSize closestSize = MediationUtils.findClosestSize(context, adSize, potentials); if (closestSize == null) { return null; } Log.i(TAG, "Found closest ad size: " + closestSize.toString()); int adHeight = closestSize.getHeight(); if (adHeight == com.facebook.ads.AdSize.BANNER_HEIGHT_50.getHeight()) { return com.facebook.ads.AdSize.BANNER_HEIGHT_50; } if (adHeight == com.facebook.ads.AdSize.BANNER_HEIGHT_90.getHeight()) { return com.facebook.ads.AdSize.BANNER_HEIGHT_90; } if (adHeight == com.facebook.ads.AdSize.RECTANGLE_HEIGHT_250.getHeight()) { return com.facebook.ads.AdSize.RECTANGLE_HEIGHT_250; } return null; }
Example 6
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 7
Source File: IMobileAdapter.java From googleads-mobile-android-mediation with Apache License 2.0 | 4 votes |
private boolean canScale(AdSize iMobileAdSize) { return iMobileAdSize.getWidth() == 320 && (iMobileAdSize.getHeight() == 50 || iMobileAdSize.getHeight() == 100); }
Example 8
Source File: MyTargetAdapter.java From googleads-mobile-android-mediation with Apache License 2.0 | 4 votes |
@Override public void requestBannerAd(Context context, MediationBannerListener mediationBannerListener, Bundle serverParameters, AdSize adSize, MediationAdRequest mediationAdRequest, Bundle mediationExtras) { int slotId = MyTargetTools.checkAndGetSlotId(context, serverParameters); Log.d(TAG, "Requesting myTarget banner mediation, slotId: " + slotId); if (slotId < 0) { if (mediationBannerListener != null) { mediationBannerListener.onAdFailedToLoad( MyTargetAdapter.this, AdRequest.ERROR_CODE_INVALID_REQUEST); } return; } adSize = getSupportedAdSize(context, adSize); if (adSize == null) { Log.w(TAG, "Failed to request ad, AdSize is null."); if (mediationBannerListener != null) { mediationBannerListener.onAdFailedToLoad( MyTargetAdapter.this, AdRequest.ERROR_CODE_INVALID_REQUEST); } return; } MyTargetBannerListener bannerListener = null; if (mediationBannerListener != null) { bannerListener = new MyTargetBannerListener(mediationBannerListener); } if (adSize.getWidth() == 300 && adSize.getHeight() == 250) { Log.d(TAG, "Loading myTarget banner, size: 300x250"); loadBanner(bannerListener, mediationAdRequest, slotId, MyTargetView.AdSize.BANNER_300x250, context); } else if (adSize.getWidth() == 728 && adSize.getHeight() == 90) { Log.d(TAG, "Loading myTarget banner, size: 728x90"); loadBanner(bannerListener, mediationAdRequest, slotId, MyTargetView.AdSize.BANNER_728x90, context); } else if (adSize.getWidth() == 320 && adSize.getHeight() == 50) { Log.d(TAG, "Loading myTarget banner, size: 320x50"); loadBanner(bannerListener, mediationAdRequest, slotId, MyTargetView.AdSize.BANNER_320x50, context); } else { Log.w(TAG, "AdSize " + adSize.toString() + " is not currently supported"); if (mediationBannerListener != null) { mediationBannerListener .onAdFailedToLoad(MyTargetAdapter.this, AdRequest.ERROR_CODE_NO_FILL); } } }
Example 9
Source File: VerizonMediaBannerRenderer.java From googleads-mobile-android-mediation with Apache License 2.0 | 4 votes |
public void render(@NonNull Context context, MediationBannerListener listener, Bundle serverParameters, AdSize adSize, MediationAdRequest mediationAdRequest, Bundle mediationExtras) { bannerListener = listener; String siteId = VerizonMediaAdapterUtils.getSiteId(serverParameters, mediationExtras); MediationBannerAdapter adapter = bannerAdapterWeakRef.get(); if (TextUtils.isEmpty(siteId)) { Log.e(TAG, "Failed to request ad: siteID is null or empty."); if (bannerListener != null && adapter != null) { bannerListener.onAdFailedToLoad(adapter, AdRequest.ERROR_CODE_INVALID_REQUEST); } return; } if (!initializeSDK(context, siteId)) { Log.e(TAG, "Unable to initialize Verizon Ads SDK."); if (bannerListener != null && adapter != null) { bannerListener.onAdFailedToLoad(adapter, AdRequest.ERROR_CODE_INTERNAL_ERROR); } return; } String placementId = VerizonMediaAdapterUtils.getPlacementId(serverParameters); if (TextUtils.isEmpty(placementId)) { Log.e(TAG, "Failed to request ad: placementID is null or empty."); if (bannerListener != null && adapter != null) { bannerListener.onAdFailedToLoad(adapter, AdRequest.ERROR_CODE_INVALID_REQUEST); } return; } if (adSize == null) { Log.w(TAG, "Fail to request banner ad, adSize is null."); if (bannerListener != null && adapter != null) { bannerListener.onAdFailedToLoad(adapter, AdRequest.ERROR_CODE_INVALID_REQUEST); } return; } AdSize normalizedSize = VerizonMediaAdapterUtils.normalizeSize(context, adSize); if (normalizedSize == null) { Log.w(TAG, "The input ad size " + adSize.toString() + " is not currently supported."); if (bannerListener != null && adapter != null) { bannerListener.onAdFailedToLoad(adapter, AdRequest.ERROR_CODE_INVALID_REQUEST); } return; } adContainer = new LinearLayout(context); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); lp.gravity = Gravity.CENTER_HORIZONTAL; adContainer.setLayoutParams(lp); com.verizon.ads.inlineplacement.AdSize verizonAdSize = new com.verizon.ads.inlineplacement.AdSize(normalizedSize.getWidth(), normalizedSize.getHeight()); VASAds.setLocationEnabled((mediationAdRequest.getLocation() != null)); VerizonMediaAdapterUtils.setCoppaValue(mediationAdRequest); InlineAdFactory inlineAdFactory = new InlineAdFactory(context, placementId, Collections.singletonList(verizonAdSize), this); inlineAdFactory.setRequestMetaData( VerizonMediaAdapterUtils.getRequestMetadata(mediationAdRequest)); inlineAdFactory.load(this); }