Java Code Examples for com.google.android.gms.ads.doubleclick.PublisherAdView#setAdSizes()
The following examples show how to use
com.google.android.gms.ads.doubleclick.PublisherAdView#setAdSizes() .
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: 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 3
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 4
Source File: MyActivity.java From googleads-mobile-android-examples with Apache License 2.0 | 5 votes |
private void loadBanner(AdSize adSize) { // Create an ad request. adView = new PublisherAdView(this); adView.setAdUnitId(BACKFILL_IU); adView.setBackgroundColor(getResources().getColor(android.R.color.holo_blue_light)); adContainerView.removeAllViews(); adContainerView.addView(adView); adView.setAdSizes(adSize); PublisherAdRequest adRequest = new PublisherAdRequest.Builder().build(); // Start loading the ad in the background. adView.loadAd(adRequest); }
Example 5
Source File: DemoActivity.java From prebid-mobile-android with Apache License 2.0 | 4 votes |
void createDFPNative() { FrameLayout adFrame = (FrameLayout) findViewById(R.id.adFrame); adFrame.removeAllViews(); final PublisherAdView nativeAdView = new PublisherAdView(this); nativeAdView.setAdListener(new AdListener() { @Override public void onAdLoaded() { super.onAdLoaded(); LogUtil.d("ad loaded"); } }); nativeAdView.setAdUnitId(Constants.DFP_IN_BANNER_NATIVE_ADUNIT_ID_APPNEXUS); nativeAdView.setAdSizes(AdSize.FLUID); adFrame.addView(nativeAdView); final PublisherAdRequest.Builder builder = new PublisherAdRequest.Builder(); request = builder.build(); NativeAdUnit nativeAdUnit = (NativeAdUnit) adUnit; nativeAdUnit.setContextType(NativeAdUnit.CONTEXT_TYPE.SOCIAL_CENTRIC); nativeAdUnit.setPlacementType(NativeAdUnit.PLACEMENTTYPE.CONTENT_FEED); nativeAdUnit.setContextSubType(NativeAdUnit.CONTEXTSUBTYPE.GENERAL_SOCIAL); ArrayList<NativeEventTracker.EVENT_TRACKING_METHOD> methods = new ArrayList<>(); methods.add(NativeEventTracker.EVENT_TRACKING_METHOD.IMAGE); try { NativeEventTracker tracker = new NativeEventTracker(NativeEventTracker.EVENT_TYPE.IMPRESSION, methods); nativeAdUnit.addEventTracker(tracker); } catch (Exception e) { e.printStackTrace(); } NativeTitleAsset title = new NativeTitleAsset(); title.setLength(90); title.setRequired(true); nativeAdUnit.addAsset(title); NativeImageAsset icon = new NativeImageAsset(); icon.setImageType(NativeImageAsset.IMAGE_TYPE.ICON); icon.setWMin(20); icon.setHMin(20); icon.setRequired(true); nativeAdUnit.addAsset(icon); NativeImageAsset image = new NativeImageAsset(); image.setImageType(NativeImageAsset.IMAGE_TYPE.MAIN); image.setHMin(200); image.setWMin(200); image.setRequired(true); nativeAdUnit.addAsset(image); NativeDataAsset data = new NativeDataAsset(); data.setLen(90); data.setDataType(NativeDataAsset.DATA_TYPE.SPONSORED); data.setRequired(true); nativeAdUnit.addAsset(data); NativeDataAsset body = new NativeDataAsset(); body.setRequired(true); body.setDataType(NativeDataAsset.DATA_TYPE.DESC); nativeAdUnit.addAsset(body); NativeDataAsset cta = new NativeDataAsset(); cta.setRequired(true); cta.setDataType(NativeDataAsset.DATA_TYPE.CTATEXT); nativeAdUnit.addAsset(cta); int millis = getIntent().getIntExtra(Constants.AUTO_REFRESH_NAME, 0); nativeAdUnit.setAutoRefreshPeriodMillis(millis); nativeAdUnit.fetchDemand(request, new OnCompleteListener() { @Override public void onComplete(ResultCode resultCode) { DemoActivity.this.resultCode = resultCode; nativeAdView.loadAd(request); DemoActivity.this.request = request; refreshCount++; } }); }
Example 6
Source File: DemoActivity.java From prebid-mobile-android with Apache License 2.0 | 4 votes |
private void setupAMBanner(int width, int height, String adUnitId) { amBanner = new PublisherAdView(this); amBanner.setAdUnitId(adUnitId); amBanner.setAdSizes(new AdSize(width, height)); }