com.google.android.gms.ads.AdSize Java Examples
The following examples show how to use
com.google.android.gms.ads.AdSize.
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: AdsManager.java From text_converter with GNU General Public License v3.0 | 6 votes |
/** * Create {@link PublisherAdView} and add to container * * @param context - android context * @param container - parent view for add ad view * @return true if ads has been added */ public static boolean addBannerAds(Context context, @Nullable ViewGroup container) { if (isPremiumUser(context)) { if (container != null) { container.setVisibility(View.GONE); } return false; } else { if (container == null) return false; container.setVisibility(View.VISIBLE); PublisherAdView publisherAdView = new PublisherAdView(context); publisherAdView.setAdSizes(AdSize.SMART_BANNER, AdSize.FLUID); publisherAdView.setAdUnitId(AdConstants.AdUnitId.AD_UNIT_ID_NATIVE_MAIN_320_50); PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder(); if (BuildConfig.DEBUG) builder.addTestDevice(TEST_DEVICE_ID); publisherAdView.loadAd(builder.build()); container.removeAllViews(); container.addView(publisherAdView); } return false; }
Example #2
Source File: AdMobPlugin.java From cordova-admob-pro with MIT License | 6 votes |
/** * Gets an AdSize object from the string size passed in from JavaScript. * Returns null if an improper string is provided. * * @param size The string size representing an ad format constant. * @return An AdSize object used to create a banner. */ public static AdSize adSizeFromString(String size) { if ("BANNER".equals(size)) { return AdSize.BANNER; } else if ("SMART_BANNER".equals(size)) { return AdSize.SMART_BANNER; } else if ("MEDIUM_RECTANGLE".equals(size)) { return AdSize.MEDIUM_RECTANGLE; } else if ("FULL_BANNER".equals(size)) { return AdSize.FULL_BANNER; } else if ("LEADERBOARD".equals(size)) { return AdSize.LEADERBOARD; } else if ("SKYSCRAPER".equals(size)) { return AdSize.WIDE_SKYSCRAPER; } else if ("LARGE_BANNER".equals(size)) { return AdSize.LARGE_BANNER; } else { return null; } }
Example #3
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 #4
Source File: RNAdMobBannerViewManager.java From react-native-admob with BSD 2-Clause "Simplified" License | 6 votes |
private AdSize getAdSizeFromString(String adSize) { switch (adSize) { case "banner": return AdSize.BANNER; case "largeBanner": return AdSize.LARGE_BANNER; case "mediumRectangle": return AdSize.MEDIUM_RECTANGLE; case "fullBanner": return AdSize.FULL_BANNER; case "leaderBoard": return AdSize.LEADERBOARD; case "smartBannerPortrait": return AdSize.SMART_BANNER; case "smartBannerLandscape": return AdSize.SMART_BANNER; case "smartBanner": return AdSize.SMART_BANNER; default: return AdSize.BANNER; } }
Example #5
Source File: RNPublisherBannerViewManager.java From react-native-admob with BSD 2-Clause "Simplified" License | 6 votes |
private AdSize getAdSizeFromString(String adSize) { switch (adSize) { case "banner": return AdSize.BANNER; case "largeBanner": return AdSize.LARGE_BANNER; case "mediumRectangle": return AdSize.MEDIUM_RECTANGLE; case "fullBanner": return AdSize.FULL_BANNER; case "leaderBoard": return AdSize.LEADERBOARD; case "smartBannerPortrait": return AdSize.SMART_BANNER; case "smartBannerLandscape": return AdSize.SMART_BANNER; case "smartBanner": return AdSize.SMART_BANNER; default: return AdSize.BANNER; } }
Example #6
Source File: AdsManager.java From text_converter with GNU General Public License v3.0 | 6 votes |
@Nullable public static PublisherAdView addBannerAds(Context context, @Nullable ViewGroup container, AdSize... adSizes) { if (isPremiumUser(context)) { if (container != null) { container.setVisibility(View.GONE); } return null; } else { if (container == null) return null; container.setVisibility(View.VISIBLE); PublisherAdView publisherAdView = new PublisherAdView(context); publisherAdView.setAdSizes(adSizes); publisherAdView.setAdUnitId(AdConstants.AdUnitId.AD_UNIT_ID_NATIVE_MAIN_320_50); PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder(); if (BuildConfig.DEBUG) builder.addTestDevice(TEST_DEVICE_ID); publisherAdView.loadAd(builder.build()); container.removeAllViews(); container.addView(publisherAdView); return publisherAdView; } }
Example #7
Source File: AdColonyAdapterUtils.java From googleads-mobile-android-mediation with Apache License 2.0 | 6 votes |
@Nullable public static AdColonyAdSize adColonyAdSizeFromAdMobAdSize(@NonNull Context context, @NonNull AdSize adSize) { ArrayList<AdSize> potentials = new ArrayList<>(); potentials.add(AdSize.BANNER); potentials.add(AdSize.LEADERBOARD); potentials.add(AdSize.MEDIUM_RECTANGLE); potentials.add(AdSize.WIDE_SKYSCRAPER); AdSize closestSize = MediationUtils.findClosestSize(context, adSize, potentials); if (AdSize.BANNER.equals(closestSize)) { return AdColonyAdSize.BANNER; } else if (AdSize.MEDIUM_RECTANGLE.equals(closestSize)) { return AdColonyAdSize.MEDIUM_RECTANGLE; } else if (AdSize.LEADERBOARD.equals(closestSize)) { return AdColonyAdSize.LEADERBOARD; } else if (AdSize.WIDE_SKYSCRAPER.equals(closestSize)) { return AdColonyAdSize.SKYSCRAPER; } return null; }
Example #8
Source File: RuleListAdapter.java From FwdPortForwardingApp with GNU General Public License v3.0 | 6 votes |
public AdViewHolder(View v) { super(v); AdRequest request = new AdRequest.Builder() .addTestDevice(AdRequest.DEVICE_ID_EMULATOR) .build(); AdView adView = new AdView(v.getContext()); adView.setAdSize(AdSize.SMART_BANNER); // Load ad type based on theme - dark or light if (PreferenceManager.getDefaultSharedPreferences(v.getContext()) .getBoolean(PREF_DARK_THEME, false)) { adView.setAdUnitId(DARK_AD_ID); } else { adView.setAdUnitId(LIGHT_AD_ID); } ((LinearLayout) v).addView(adView, 1); adView.loadAd(request); }
Example #9
Source File: GooglePlayDFPBanner.java From mobile-sdk-android with Apache License 2.0 | 6 votes |
/** * Interface called by the AN SDK to request an ad from the mediating SDK. * * @param mBC the object which will be called with events from the 3rd party SDK * @param activity the activity from which this is launched * @param parameter String parameter received from the server for instantiation of this object * @param adUnitID The 3rd party placement, in DFP this is the adUnitID * @param width Width of the ad * @param height Height of the ad * @param targetingParameters targetingParameters */ @Override public View requestAd(MediatedBannerAdViewController mBC, Activity activity, String parameter, String adUnitID, int width, int height, TargetingParameters targetingParameters) { adListener = new GooglePlayAdListener(mBC, super.getClass().getSimpleName()); adListener.printToClog(String.format(" - requesting an ad: [%s, %s, %dx%d]", parameter, adUnitID, width, height)); DFBBannerSSParameters ssparm = new DFBBannerSSParameters(parameter); AdSize adSize = ssparm.isSmartBanner ? AdSize.SMART_BANNER : new AdSize(width, height); adView = new PublisherAdView(activity); adView.setAdUnitId(adUnitID); adView.setAdSizes(adSize); adView.setAdListener(adListener); adView.setAppEventListener(adListener); adView.loadAd(buildRequest(ssparm, targetingParameters)); return adView; }
Example #10
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 #11
Source File: HomeFragment.java From Android with MIT License | 6 votes |
private void Ads(View v) { //adView = view.findViewById(R.id.adView); View adContainer = v.findViewById(R.id.adMobView); // Log.e("TAG :BANNERhomefragment",ADMOB_PLEX_BANNER_1); AdView mAdView = new AdView(mContext); mAdView.setAdSize(AdSize.SMART_BANNER); mAdView.setAdUnitId(ADMOB_PLEX_BANNER_1); ((RelativeLayout)adContainer).addView(mAdView); AdRequest adRequest = new AdRequest.Builder().build(); mAdView.loadAd(adRequest); mInterstitialAd = new InterstitialAd(getActivity()); mInterstitialAd.setAdUnitId(ADMOB_PLEX_INTERSTITIAL_1); mInterstitialAd.loadAd(new AdRequest.Builder().build()); mInterstitialAd.setAdListener(new AdListener() { @Override public void onAdClosed() { } }); }
Example #12
Source File: TvShowsFragment.java From Android with MIT License | 6 votes |
private void Ads(View v) { View adContainer1 = v.findViewById(R.id.adView_tvshow_fragment); AdView mAdView = new AdView(mContext); mAdView.setAdSize(AdSize.MEDIUM_RECTANGLE); mAdView.setAdUnitId(ADMOB_PLEX_BANNER_2); ((RelativeLayout)adContainer1).addView(mAdView); AdRequest adRequest = new AdRequest.Builder().build(); mAdView.loadAd(adRequest); View adContainer2 = v.findViewById(R.id.adView_tvshow_fragment2); AdView mAdVie2 = new AdView(mContext); mAdVie2.setAdSize(AdSize.SMART_BANNER); mAdVie2.setAdUnitId(ADMOB_PLEX_BANNER_2); ((RelativeLayout)adContainer2).addView(mAdVie2); AdRequest adReques2 = new AdRequest.Builder().build(); mAdVie2.loadAd(adReques2); }
Example #13
Source File: MainActivity.java From BusyBox with Apache License 2.0 | 5 votes |
private void setupBanners() { AdRequest.Builder builder = new AdRequest.Builder(); if (App.isDebuggable()) { builder.addTestDevice(DeviceUtils.getDeviceId()); } adViewTiers[currentAdViewIndex] = new AdView(this); adViewTiers[currentAdViewIndex].setAdSize(AdSize.SMART_BANNER); adViewTiers[currentAdViewIndex] .setAdUnitId(getResources().getStringArray(R.array.banners_id)[currentAdViewIndex]); adViewTiers[currentAdViewIndex].setAdListener(new AdListener() { @Override public void onAdFailedToLoad(int errorCode) { if (currentAdViewIndex != (adViewTiers.length - 1)) { currentAdViewIndex++; setupBanners(); } else if (adContainer.getVisibility() == View.VISIBLE) { Technique.SLIDE_OUT_DOWN.getComposer().hideOnFinished().playOn(adContainer); } } @Override public void onAdLoaded() { adContainer.setVisibility(View.VISIBLE); if (adContainer.getChildCount() != 0) { adContainer.removeAllViews(); } adContainer.addView(adViewTiers[currentAdViewIndex]); Analytics.newEvent("on_ad_loaded") .put("id", adViewTiers[currentAdViewIndex].getAdUnitId()).log(); } }); adViewTiers[currentAdViewIndex].loadAd(builder.build()); }
Example #14
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 #15
Source File: AdmobBannerRecyclerAdapterWrapper.java From admobadapter with Apache License 2.0 | 5 votes |
/** * Sets a single ad size for each ad block. By default it equals to AdSize(AdSize.FULL_WIDTH, 150); */ public Builder setSingleAdSize(@NonNull AdSize adSize){ BannerAdPreset adPreset = adFetcher.getAdPresetSingleOr(new BannerAdPreset(null, null)); adPreset.setAdSize(adSize); adFetcher.setAdPresets(Collections.singletonList(adPreset)); return this; }
Example #16
Source File: AdmobExpressAdapterWrapper.java From admobadapter with Apache License 2.0 | 5 votes |
/** * Sets a single ad size for each ad block. By default it equals to AdSize(AdSize.FULL_WIDTH, 150); */ public Builder setSingleAdSize(@NonNull AdSize adSize){ AdPreset adPreset = adFetcher.getAdPresetSingleOr(new AdPreset(null, null)); adPreset.setAdSize(adSize); adFetcher.setAdPresets(Collections.singletonList(adPreset)); return this; }
Example #17
Source File: MainActivity.java From BusyBox with Apache License 2.0 | 5 votes |
private void setupBanners() { AdRequest.Builder builder = new AdRequest.Builder(); if (App.isDebuggable()) { builder.addTestDevice(DeviceUtils.getDeviceId()); } adViewTiers[currentAdViewIndex] = new AdView(this); adViewTiers[currentAdViewIndex].setAdSize(AdSize.SMART_BANNER); adViewTiers[currentAdViewIndex] .setAdUnitId(getResources().getStringArray(R.array.banners_id)[currentAdViewIndex]); adViewTiers[currentAdViewIndex].setAdListener(new AdListener() { @Override public void onAdFailedToLoad(int errorCode) { if (currentAdViewIndex != (adViewTiers.length - 1)) { currentAdViewIndex++; setupBanners(); } else if (adContainer.getVisibility() == View.VISIBLE) { Technique.SLIDE_OUT_DOWN.getComposer().hideOnFinished().playOn(adContainer); } } @Override public void onAdLoaded() { adContainer.setVisibility(View.VISIBLE); if (adContainer.getChildCount() != 0) { adContainer.removeAllViews(); } adContainer.addView(adViewTiers[currentAdViewIndex]); Analytics.newEvent("on_ad_loaded") .put("id", adViewTiers[currentAdViewIndex].getAdUnitId()).log(); } }); adViewTiers[currentAdViewIndex].loadAd(builder.build()); }
Example #18
Source File: AdMobConfigTest.java From cordova-plugin-admob-free with MIT License | 5 votes |
@Test public void canSetAdSize() throws JSONException { AdMobConfig config = new AdMobConfig(); assertEquals(config.adSize, AdSize.SMART_BANNER); config.setOptions(new JSONObject("{\"adSize\": \"BANNER\"}")); assertEquals(config.adSize, AdSize.BANNER); config.setOptions(new JSONObject("{\"adSize\": \"FULL_BANNER\"}")); assertEquals(config.adSize, AdSize.FULL_BANNER); config.setOptions(new JSONObject("{\"adSize\": \"LARGE_BANNER\"}")); assertEquals(config.adSize, AdSize.LARGE_BANNER); config.setOptions(new JSONObject("{\"adSize\": \"LEADERBOARD\"}")); assertEquals(config.adSize, AdSize.LEADERBOARD); config.setOptions(new JSONObject("{\"adSize\": \"MEDIUM_RECTANGLE\"}")); assertEquals(config.adSize, AdSize.MEDIUM_RECTANGLE); config.setOptions(new JSONObject("{\"adSize\": \"WIDE_SKYSCRAPER\"}")); assertEquals(config.adSize, AdSize.WIDE_SKYSCRAPER); config.setOptions(new JSONObject("{\"adSize\": \"FLUID\"}")); assertEquals(config.adSize, AdSize.FLUID); config.setOptions(new JSONObject("{\"adSize\": \"SEARCH\"}")); assertEquals(config.adSize, AdSize.SEARCH); // backward-compatibility config.setOptions(new JSONObject("{\"adSize\": \"IAB_BANNER\"}")); assertEquals(config.adSize, AdSize.FULL_BANNER); config.setOptions(new JSONObject("{\"adSize\": \"IAB_MRECT\"}")); assertEquals(config.adSize, AdSize.MEDIUM_RECTANGLE); config.setOptions(new JSONObject("{\"adSize\": \"IAB_LEADERBOARD\"}")); assertEquals(config.adSize, AdSize.LEADERBOARD); }
Example #19
Source File: Action.java From admob-plus with MIT License | 5 votes |
public AdSize getAdSize() { final String name = "size"; if (!this.opts.has(name)) { return AdSize.SMART_BANNER; } AdSize adSize = AdSizeType.getAdSize(this.opts.opt(name)); if (adSize != null) { return adSize; } JSONObject adSizeObj = this.opts.optJSONObject(name); if (adSizeObj == null) { return AdSize.SMART_BANNER; } return new AdSize(adSizeObj.optInt("width"), adSizeObj.optInt("height")); }
Example #20
Source File: MainActivity.java From android-ads with Apache License 2.0 | 5 votes |
/** * Adds banner ads to the items list. */ private void addBannerAds() { // Loop through the items array and place a new banner ad in every ith position in // the items List. for (int i = 0; i <= recyclerViewItems.size(); i += ITEMS_PER_AD) { final AdView adView = new AdView(MainActivity.this); adView.setAdSize(AdSize.BANNER); adView.setAdUnitId(AD_UNIT_ID); recyclerViewItems.add(i, adView); } }
Example #21
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 #22
Source File: AdmobExpressRecyclerAdapterWrapper.java From admobadapter with Apache License 2.0 | 5 votes |
/** * Sets a single ad size for each ad block. By default it equals to AdSize(AdSize.FULL_WIDTH, 150); */ public Builder setSingleAdSize(@NonNull AdSize adSize){ AdPreset adPreset = adFetcher.getAdPresetSingleOr(new AdPreset(null, null)); adPreset.setAdSize(adSize); adFetcher.setAdPresets(Collections.singletonList(adPreset)); return this; }
Example #23
Source File: IMobileAdapter.java From googleads-mobile-android-mediation with Apache License 2.0 | 5 votes |
private float calcScaleRatio(Context context, AdSize requestedAdSize, AdSize iMobileAdSize) { return Math.min( ((float) requestedAdSize.getWidthInPixels(context) / iMobileAdSize.getWidthInPixels(context)), ((float) requestedAdSize.getHeightInPixels(context) / iMobileAdSize.getHeightInPixels(context))); }
Example #24
Source File: AdImpl.java From rebootmenu with GNU General Public License v3.0 | 5 votes |
public static void showAdView() { if (adView != null) { //TODO 需要确认这段修复代码的可用性 if (TextUtils.isEmpty(adView.getAdUnitId())) adView.setAdUnitId(AdViewUnitKey); if (adView.getAdSize() == null) adView.setAdSize(AdSize.SMART_BANNER); adView.loadAd(adRequest); } }
Example #25
Source File: AdViewHelper.java From admobadapter with Apache License 2.0 | 5 votes |
public static NativeExpressAdView getExpressAdView(Context context, AdPreset adPreset) { NativeExpressAdView adView = new NativeExpressAdView(context); AdSize adSize = adPreset.getAdSize(); adView.setAdSize(adSize); adView.setAdUnitId(adPreset.getAdUnitId()); adView.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, adSize.getHeightInPixels(context))); //set video options if(adPreset.getVideoOptions() != null) adView.setVideoOptions(adPreset.getVideoOptions()); return adView; }
Example #26
Source File: MyTargetAdapter.java From googleads-mobile-android-mediation with Apache License 2.0 | 5 votes |
@Nullable private AdSize getSupportedAdSize(@NonNull Context context, @NonNull AdSize adSize) { /* Supported Sizes: MyTargetView.AdSize.BANNER_300x250; MyTargetView.AdSize.BANNER_320x50; MyTargetView.AdSize.BANNER_728x90; */ ArrayList<AdSize> potentials = new ArrayList<>(); potentials.add(AdSize.BANNER); potentials.add(AdSize.MEDIUM_RECTANGLE); potentials.add(AdSize.LEADERBOARD); return MediationUtils.findClosestSize(context, adSize, potentials); }
Example #27
Source File: TestAdMobClassicActivity.java From UltimateRecyclerView with Apache License 2.0 | 5 votes |
private AdView createadmob() { AdView mAdView = new AdView(this); mAdView.setAdSize(AdSize.MEDIUM_RECTANGLE); mAdView.setAdUnitId("ca-app-pub-3940256099942544/6300978111"); mAdView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); // Create an ad request. AdRequest.Builder adRequestBuilder = new AdRequest.Builder(); if (admob_test_mode) // Optionally populate the ad request builder. adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR); // Start loading the ad. mAdView.loadAd(adRequestBuilder.build()); return mAdView; }
Example #28
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 #29
Source File: ChartboostAdapterUtils.java From googleads-mobile-android-mediation with Apache License 2.0 | 5 votes |
/** * Find the closest possible {@link BannerSize} format based on the provided {@link AdSize}. * * @param context the context of requesting banner ad. * @param adSize the requested banner ad size. * @return Chartboost {@link BannerSize} object. */ @Nullable static BannerSize findClosestBannerSize(@NonNull Context context, @NonNull AdSize adSize) { AdSize standardSize = new AdSize( BannerSize.getWidth(BannerSize.STANDARD), BannerSize.getHeight(BannerSize.STANDARD)); AdSize mediumSize = new AdSize(BannerSize.getWidth(BannerSize.MEDIUM), BannerSize.getHeight(BannerSize.MEDIUM)); AdSize leaderboardSize = new AdSize( BannerSize.getWidth(BannerSize.LEADERBOARD), BannerSize.getHeight(BannerSize.LEADERBOARD)); ArrayList<AdSize> potentials = new ArrayList<>(); potentials.add(standardSize); potentials.add(mediumSize); potentials.add(leaderboardSize); AdSize supportedAdSize = MediationUtils.findClosestSize(context, adSize, potentials); if (supportedAdSize == null) { return null; } if (supportedAdSize.equals(standardSize)) { return BannerSize.STANDARD; } else if (supportedAdSize.equals(mediumSize)) { return BannerSize.MEDIUM; } else if (supportedAdSize.equals(leaderboardSize)) { return BannerSize.LEADERBOARD; } return null; }
Example #30
Source File: InMobiAdapter.java From googleads-mobile-android-mediation with Apache License 2.0 | 5 votes |
@Nullable private AdSize getSupportedAdSize(@NonNull Context context, @NonNull AdSize adSize) { /* Supported Sizes (ref: https://www.inmobi.com/ui/pdfs/ad-specs.pdf) 320x50, 300x250, 728x90. */ ArrayList<AdSize> potentials = new ArrayList<>(); potentials.add(new AdSize(320, 50)); potentials.add(new AdSize(300, 250)); potentials.add(new AdSize(728, 90)); return MediationUtils.findClosestSize(context, adSize, potentials); }