Java Code Examples for com.google.android.gms.ads.AdSize#getWidthInPixels()
The following examples show how to use
com.google.android.gms.ads.AdSize#getWidthInPixels() .
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: AndroidAdMobBanner.java From QtAndroidTools with MIT License | 4 votes |
public void setType(final int type) { if(mBannerView == null) { return; } SyncRunOnUiThread UiThread = new SyncRunOnUiThread(mActivityInstance, new SyncRunOnUiThread.SyncRunOnUiThreadListener() { public void runOnUIThread() { AdSize BannerSize = AdSize.BANNER; switch(type) { case TYPE_BANNER: BannerSize = AdSize.BANNER; break; case TYPE_FULL_BANNER: BannerSize = AdSize.FULL_BANNER; break; case TYPE_LARGE_BANNER: BannerSize = AdSize.LARGE_BANNER; break; case TYPE_MEDIUM_RECTANGLE: BannerSize = AdSize.MEDIUM_RECTANGLE; break; case TYPE_SMART_BANNER: BannerSize = AdSize.SMART_BANNER; break; case TYPE_WIDE_SKYSCRAPER: BannerSize = AdSize.WIDE_SKYSCRAPER; break; } mBannerView.setAdSize(BannerSize); mBannerPixelsSize.width = BannerSize.getWidthInPixels(mActivityInstance); mBannerPixelsSize.height = BannerSize.getHeightInPixels(mActivityInstance); } }); UiThread.exec(); }
Example 2
Source File: SampleAdapter.java From googleads-mobile-android-mediation with Apache License 2.0 | 4 votes |
/** * This method will only ever be called once per adapter instance. */ @Override public void requestBannerAd( Context context, MediationBannerListener listener, Bundle serverParameters, AdSize adSize, MediationAdRequest mediationAdRequest, Bundle mediationExtras) { /* * In this method, you should: * * 1. Create your banner view. * 2. Set your ad network's listener. * 3. Make an ad request. */ // Create the SampleAdView. sampleAdView = new SampleAdView(context); if (serverParameters.containsKey(SAMPLE_AD_UNIT_KEY)) { sampleAdView.setAdUnit(serverParameters.getString(SAMPLE_AD_UNIT_KEY)); } else { listener.onAdFailedToLoad(this, AdRequest.ERROR_CODE_INVALID_REQUEST); } // Internally, smart banners use constants to represent their ad size, which means a call to // AdSize.getHeight could return a negative value. You can accommodate this by using // AdSize.getHeightInPixels and AdSize.getWidthInPixels instead, and then adjusting to match // the device's display metrics. int widthInPixels = adSize.getWidthInPixels(context); int heightInPixels = adSize.getHeightInPixels(context); DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics(); int widthInDp = Math.round(widthInPixels / displayMetrics.density); int heightInDp = Math.round(heightInPixels / displayMetrics.density); sampleAdView.setSize(new SampleAdSize(widthInDp, heightInDp)); /** * Implement a SampleAdListener and forward callbacks to mediation. The callback forwarding * is handled by {@link SampleMediationBannerEventForwarder}. */ sampleAdView.setAdListener(new SampleMediationBannerEventForwarder(listener, this)); SampleAdRequest request = createSampleRequest(mediationAdRequest); /** * If your network supports additional request parameters, the publisher can send these * additional parameters to the adapter using the {@link mediationExtras} bundle. * Creating a bundle builder class makes it easier for the publisher to create this bundle. */ if (mediationExtras != null) { if (mediationExtras.containsKey(MediationExtrasBundleBuilder.KEY_AWESOME_SAUCE)) { request.setShouldAddAwesomeSauce( mediationExtras.getBoolean(MediationExtrasBundleBuilder.KEY_AWESOME_SAUCE)); } if (mediationExtras.containsKey(MediationExtrasBundleBuilder.KEY_INCOME)) { request.setIncome(mediationExtras.getInt(MediationExtrasBundleBuilder.KEY_INCOME)); } } // Make an ad request. sampleAdView.fetchAd(request); }
Example 3
Source File: SampleCustomEvent.java From googleads-mobile-android-mediation with Apache License 2.0 | 4 votes |
@Override public void requestBannerAd(Context context, CustomEventBannerListener listener, String serverParameter, AdSize size, MediationAdRequest mediationAdRequest, Bundle customEventExtras) { /* * In this method, you should: * * 1. Create your banner view. * 2. Set your ad network's listener. * 3. Make an ad request. * * When setting your ad network's listener, don't forget to send the following callbacks: * * listener.onAdLoaded(this); * listener.onAdFailedToLoad(this, AdRequest.ERROR_CODE_*); * listener.onAdClicked(this); * listener.onAdOpened(this); * listener.onAdLeftApplication(this); * listener.onAdClosed(this); */ sampleAdView = new SampleAdView(context); // Assumes that the serverParameter is the AdUnit for the Sample Network. sampleAdView.setAdUnit(serverParameter); // Internally, smart banners use constants to represent their ad size, which means a call to // AdSize.getHeight could return a negative value. You can accommodate this by using // AdSize.getHeightInPixels and AdSize.getWidthInPixels instead, and then adjusting to match // the device's display metrics. int widthInPixels = size.getWidthInPixels(context); int heightInPixels = size.getHeightInPixels(context); DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics(); int widthInDp = Math.round(widthInPixels / displayMetrics.density); int heightInDp = Math.round(heightInPixels / displayMetrics.density); sampleAdView.setSize(new SampleAdSize(widthInDp, heightInDp)); // Implement a SampleAdListener and forward callbacks to mediation. The callback forwarding // is handled by SampleBannerEventFowarder. sampleAdView.setAdListener(new SampleCustomBannerEventForwarder(listener, sampleAdView)); // Make an ad request. sampleAdView.fetchAd(createSampleRequest(mediationAdRequest)); }
Example 4
Source File: NendAdapter.java From googleads-mobile-android-mediation with Apache License 2.0 | 4 votes |
@Override public void requestBannerAd( final Context context, MediationBannerListener listener, Bundle serverParameters, AdSize adSize, MediationAdRequest mediationAdRequest, Bundle mediationExtras) { final AdSize supportedAdSize = getSupportedAdSize(context, adSize); if (supportedAdSize == null) { Log.w(TAG, "Failed to request ad, Unsupported ad size: " + adSize.toString()); listener.onAdFailedToLoad(this, AdRequest.ERROR_CODE_INVALID_REQUEST); return; } AdUnitMapper mapper = AdUnitMapper.createAdUnitMapper(serverParameters); if (mapper == null) { Log.w(TAG, "Failed to request ad from Nend: Invalid Spot ID or API Key."); listener.onAdFailedToLoad(this, AdRequest.ERROR_CODE_INTERNAL_ERROR); return; } mNendAdView = new NendAdView(context, mapper.spotId, mapper.apiKey); bannerContainerView = new FrameLayout(context); FrameLayout.LayoutParams containerViewParams = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); bannerContainerView.setLayoutParams(containerViewParams); int adViewParamHeight = adSize.getHeightInPixels(context); if (adViewParamHeight <= 0) { adViewParamHeight = LayoutParams.WRAP_CONTENT; } FrameLayout.LayoutParams adViewParams = new FrameLayout.LayoutParams(adSize.getWidthInPixels(context), adViewParamHeight); adViewParams.gravity = Gravity.CENTER; bannerContainerView.addView(mNendAdView, adViewParams); mListener = listener; // NOTE: Use the reload function of AdMob mediation instead of NendAdView. // So, reload function of NendAdView should be stopped. mNendAdView.pause(); mNendAdView.setListener(this); mNendAdView.addOnAttachStateChangeListener(mAttachStateChangeListener); mNendAdView.loadAd(); mIsRequestBannerAd = true; }
Example 5
Source File: AdMobPlugin.java From cordova-admob-pro with MIT License | 4 votes |
@Override protected int __getAdViewWidth(View view) { AdSize sz = getAdViewSize(view); return sz.getWidthInPixels(getActivity()); }