public void PopulateUnifiedNativeAdView(UnifiedNativeAd nativeAd) { try { NativeAdView = (UnifiedNativeAdView)FindViewById(Resource.Id.native_ad_view); // Set the media view. NativeAdView.MediaView = NativeAdView.FindViewById <MediaView>(Resource.Id.ad_media); // Set other ad assets. NativeAdView.HeadlineView = NativeAdView.FindViewById(Resource.Id.ad_headline); NativeAdView.BodyView = NativeAdView.FindViewById(Resource.Id.ad_body); NativeAdView.CallToActionView = NativeAdView.FindViewById(Resource.Id.ad_call_to_action); NativeAdView.IconView = NativeAdView.FindViewById(Resource.Id.ad_app_icon); NativeAdView.PriceView = NativeAdView.FindViewById(Resource.Id.ad_price); //NativeAdView.StarRatingView=NativeAdView.FindViewById(Resource.Id.ad_stars); NativeAdView.StoreView = NativeAdView.FindViewById(Resource.Id.ad_store); NativeAdView.AdvertiserView = NativeAdView.FindViewById(Resource.Id.ad_advertiser); // The headline and mediaContent are guaranteed to be in every UnifiedNativeAd. ((TextView)NativeAdView.HeadlineView).Text = nativeAd.Headline; //NativeAdView.MediaView.MediaContent(nativeAd.MediaContent); // These assets aren't guaranteed to be in every UnifiedNativeAd, so it's important to // check before trying to display them. if (string.IsNullOrEmpty(nativeAd.Body)) { NativeAdView.BodyView.Visibility = ViewStates.Gone; } else { NativeAdView.BodyView.Visibility = ViewStates.Visible; ((TextView)NativeAdView.BodyView).Text = nativeAd.Body; } if (string.IsNullOrEmpty(nativeAd.CallToAction)) { NativeAdView.CallToActionView.Visibility = ViewStates.Gone; } else { NativeAdView.CallToActionView.Visibility = ViewStates.Visible; ((Button)NativeAdView.CallToActionView).Text = nativeAd.CallToAction; } if (nativeAd.Icon == null) { NativeAdView.IconView.Visibility = ViewStates.Gone; } else { ((ImageView)NativeAdView.IconView).SetImageDrawable(nativeAd.Icon.Drawable); NativeAdView.IconView.Visibility = ViewStates.Visible; } if (string.IsNullOrEmpty(nativeAd.Price)) { NativeAdView.PriceView.Visibility = ViewStates.Gone; } else { NativeAdView.PriceView.Visibility = ViewStates.Visible; ((TextView)NativeAdView.PriceView).Text = nativeAd.Price; } if (string.IsNullOrEmpty(nativeAd.Store)) { NativeAdView.StoreView.Visibility = ViewStates.Gone; } else { NativeAdView.StoreView.Visibility = ViewStates.Visible; ((TextView)NativeAdView.StoreView).Text = nativeAd.Store; } //if (nativeAd.StarRating == null) //{ // NativeAdView.StarRatingView.Visibility = ViewStates.Gone; //} //else //{ // ((RatingBar)NativeAdView.StarRatingView).Rating=nativeAd.StarRating.FloatValue(); // NativeAdView.StarRatingView.Visibility = ViewStates.Gone; //} if (string.IsNullOrEmpty(nativeAd.Advertiser)) { NativeAdView.AdvertiserView.Visibility = ViewStates.Gone; } else { ((TextView)NativeAdView.AdvertiserView).Text = nativeAd.Advertiser; NativeAdView.AdvertiserView.Visibility = ViewStates.Visible; } // This method tells the Google Mobile Ads SDK that you have finished populating your // native ad view with this native ad. NativeAdView.SetNativeAd(nativeAd); // Get the video controller for the ad. One will always be provided, even if the ad doesn't // have a video asset. VideoController vc = nativeAd.VideoController; // Updates the UI to say whether or not this ad has a video asset. if (vc.HasVideoContent) { //"Video status: Ad contains a %.2f:1 video asset." // Create a new VideoLifecycleCallbacks object and pass it to the VideoController. The // VideoController will call methods on this object when events occur in the video // lifecycle. vc.SetVideoLifecycleCallbacks(new VideoController.VideoLifecycleCallbacks()); } else { //"Video status: Ad does not contain a video asset." } } catch (Exception e) { Console.WriteLine(e); } }
public void NativeContentAdView(UnifiedNativeAd nativeAd) { try { NativeAdView = (UnifiedNativeAdView)FindViewById(Resource.Id.nativeAdView); // Set other ad assets. NativeAdView.HeadlineView = NativeAdView.FindViewById(Resource.Id.contentad_headline); NativeAdView.BodyView = NativeAdView.FindViewById(Resource.Id.contentad_body); NativeAdView.CallToActionView = NativeAdView.FindViewById(Resource.Id.contentad_call_to_action); NativeAdView.IconView = NativeAdView.FindViewById(Resource.Id.contentad_logo); NativeAdView.AdvertiserView = NativeAdView.FindViewById(Resource.Id.contentad_advertiser); NativeAdView.ImageView = NativeAdView.FindViewById(Resource.Id.contentad_image); // The headline and mediaContent are guaranteed to be in every UnifiedNativeAd. ((TextView)NativeAdView.HeadlineView).Text = nativeAd.Headline; // These assets aren't guaranteed to be in every UnifiedNativeAd, so it's important to // check before trying to display them. if (string.IsNullOrEmpty(nativeAd.Body)) { NativeAdView.BodyView.Visibility = ViewStates.Gone; } else { NativeAdView.BodyView.Visibility = ViewStates.Visible; ((TextView)NativeAdView.BodyView).Text = nativeAd.Body; } if (string.IsNullOrEmpty(nativeAd.CallToAction)) { NativeAdView.CallToActionView.Visibility = ViewStates.Gone; } else { NativeAdView.CallToActionView.Visibility = ViewStates.Visible; ((Button)NativeAdView.CallToActionView).Text = nativeAd.CallToAction; } if (nativeAd.Icon == null) { NativeAdView.IconView.Visibility = ViewStates.Gone; } else { ((ImageView)NativeAdView.IconView).SetImageDrawable(nativeAd.Icon.Drawable); NativeAdView.IconView.Visibility = ViewStates.Visible; } if (nativeAd.Images?.Count == 0) { NativeAdView.IconView.Visibility = ViewStates.Gone; } else { if (nativeAd.Images != null) { ((ImageView)NativeAdView.ImageView).SetImageDrawable(nativeAd.Images[0].Drawable); } NativeAdView.ImageView.Visibility = ViewStates.Visible; } if (string.IsNullOrEmpty(nativeAd.Advertiser)) { NativeAdView.AdvertiserView.Visibility = ViewStates.Gone; } else { ((TextView)NativeAdView.AdvertiserView).Text = nativeAd.Advertiser; NativeAdView.AdvertiserView.Visibility = ViewStates.Visible; } // This method tells the Google Mobile Ads SDK that you have finished populating your // native ad view with this native ad. NativeAdView.SetNativeAd(nativeAd); // Get the video controller for the ad. One will always be provided, even if the ad doesn't // have a video asset. VideoController vc = nativeAd.VideoController; // Updates the UI to say whether or not this ad has a video asset. if (vc.HasVideoContent) { //"Video status: Ad contains a %.2f:1 video asset." // Create a new VideoLifecycleCallbacks object and pass it to the VideoController. The // VideoController will call methods on this object when events occur in the video // lifecycle. vc.SetVideoLifecycleCallbacks(new VideoController.VideoLifecycleCallbacks()); } else { //"Video status: Ad does not contain a video asset." } } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
public void NativeAppInstallAdView(UnifiedNativeAd nativeAppInstallAd) { try { NativeAdView = (UnifiedNativeAdView)FindViewById(Resource.Id.nativeInstallAdView); VideoController videoController = nativeAppInstallAd.VideoController; videoController.SetVideoLifecycleCallbacks(new VideoController.VideoLifecycleCallbacks()); NativeAdView.HeadlineView = NativeAdView.FindViewById(Resource.Id.appinstall_headline); NativeAdView.BodyView = NativeAdView.FindViewById(Resource.Id.appinstall_body); NativeAdView.CallToActionView = NativeAdView.FindViewById(Resource.Id.appinstall_call_to_action); NativeAdView.IconView = NativeAdView.FindViewById(Resource.Id.appinstall_app_icon); NativeAdView.PriceView = NativeAdView.FindViewById(Resource.Id.appinstall_price); NativeAdView.StarRatingView = NativeAdView.FindViewById(Resource.Id.appinstall_stars); NativeAdView.StoreView = NativeAdView.FindViewById(Resource.Id.appinstall_store); ((TextView)NativeAdView.HeadlineView).Text = nativeAppInstallAd.Headline; ((TextView)NativeAdView.BodyView).Text = nativeAppInstallAd.Body; ((Button)NativeAdView.CallToActionView).Text = nativeAppInstallAd.CallToAction; if (nativeAppInstallAd.Icon.Drawable != null) { ((ImageView)NativeAdView.IconView).SetImageDrawable(nativeAppInstallAd.Icon.Drawable); } MediaView mediaView = (MediaView)NativeAdView.FindViewById(Resource.Id.appinstall_media); ImageView imageView = (ImageView)NativeAdView.FindViewById(Resource.Id.appinstall_image); if (videoController.HasVideoContent) { NativeAdView.MediaView = (mediaView); imageView.Visibility = ViewStates.Gone; } else { NativeAdView.ImageView = (imageView); mediaView.Visibility = ViewStates.Gone; var images = nativeAppInstallAd.Images; if (images != null && images.Count > 0) { imageView.SetImageDrawable(images[0].Drawable); } } if (nativeAppInstallAd.Price == null) { NativeAdView.PriceView.Visibility = ViewStates.Invisible; } else { NativeAdView.PriceView.Visibility = ViewStates.Visible; ((TextView)NativeAdView.PriceView).Text = (nativeAppInstallAd.Price); } if (nativeAppInstallAd.Store == null) { NativeAdView.StoreView.Visibility = ViewStates.Invisible; } else { NativeAdView.StoreView.Visibility = ViewStates.Visible; ((TextView)NativeAdView.StoreView).Text = (nativeAppInstallAd.Store); } //if (nativeAppInstallAd.StarRating == null) //{ // NativeAdView.StarRatingView.Visibility = ViewStates.Gone; //} //else //{ // ((RatingBar) NativeAdView.StarRatingView).Rating = nativeAppInstallAd.StarRating.FloatValue; // NativeAdView.StarRatingView.Visibility = ViewStates.Visible; //} NativeAdView.SetNativeAd(nativeAppInstallAd); } catch (Exception e) { Console.WriteLine(e); } }
private void populateUnifiedNativeAdView(UnifiedNativeAd nativeAd, UnifiedNativeAdView adView) { // Find View Ctrl primaryView = adView.FindViewById <TextView>(Resource.Id.ad_primary); secondaryView = adView.FindViewById <TextView>(Resource.Id.ad_secondary); //tertiaryView = adView.FindViewById<TextView>(Resource.Id.ad_body); ratingBar = adView.FindViewById <RatingBar>(Resource.Id.ad_rating); ratingBar.Enabled = false; callToActionView = adView.FindViewById <Android.Widget.Button>(Resource.Id.ad_call_to_action); iconView = adView.FindViewById <ImageView>(Resource.Id.ad_icon); // Ad data string store = nativeAd.Store; string advertiser = nativeAd.Advertiser; string headline = nativeAd.Headline; string cta = nativeAd.CallToAction; float starRating = nativeAd.StarRating?.FloatValue() ?? 0.0f; Drawable icon = nativeAd.Icon?.Drawable ?? null; Drawable image = nativeAd.Images.Count > 0 ? nativeAd.Images[0].Drawable : null; // dynamic string secondaryText; // Set value in view adView.CallToActionView = callToActionView; adView.HeadlineView = primaryView; secondaryView.Visibility = ViewStates.Visible; if (AdHasOnlyStore(nativeAd)) { adView.StoreView = secondaryView; secondaryText = store; } else if (!string.IsNullOrEmpty(advertiser)) { adView.AdvertiserView = secondaryView; secondaryText = advertiser; } else { secondaryText = ""; } primaryView.Text = headline; // CallToActionView callToActionView.Text = cta; callToActionView.SetBackgroundColor(ButtonColor); // Set the secondary view to be the star rating if available. if (starRating > 0) { secondaryView.Visibility = ViewStates.Gone; ratingBar.Visibility = ViewStates.Visible; ratingBar.Max = 5; ratingBar.Rating = starRating; ratingBar.StepSize = 0.1f; adView.StarRatingView = ratingBar; } else { secondaryView.Text = secondaryText; secondaryView.Visibility = ViewStates.Visible; ratingBar.Visibility = ViewStates.Gone; } if (image != null) { iconView.Visibility = ViewStates.Visible; iconView.SetImageDrawable(image); } else if (icon != null) { iconView.Visibility = ViewStates.Visible; iconView.SetImageDrawable(icon); } else { iconView.Visibility = ViewStates.Gone; } adView.SetNativeAd(nativeAd); }