void RenderAd(NativeAdInfo ad)
        {
            if (IsDead(out var view))
            {
                return;
            }
            if (ad is null)
            {
                return;
            }

            CurrentAd     = ad;
            view.Ad.Value = ad;

            if (ad is FailedNativeAdInfo)
            {
                view.HeadLineView.Text     = ad.Headline;
                view.BodyView.Text         = ad.Body;
                view.CallToActionView.Text = ad.CallToAction;
                return;
            }
            else
            {
                NativeView.SetNativeAd(ad.Native);

                var vc = ad.Native.VideoController;
                if (vc.HasVideoContent)
                {
                    var callback = vc.GetVideoLifecycleCallbacks();
                    if (callback == null)
                    {
                        vc.SetVideoLifecycleCallbacks(VideoCallBack);
                    }
                }
            }
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
        public void SetNativeAd(UnifiedNativeAd nativeAd)
        {
            try
            {
                NativeAd = nativeAd;

                string store      = nativeAd.Store;
                string advertiser = nativeAd.Advertiser;
                string headline   = nativeAd.Headline;
                string body       = nativeAd.Body;
                //string cta = nativeAd.CallToAction;
                //int starRating = Convert.ToInt32(nativeAd.StarRating);
                NativeAd.Image icon = nativeAd.Icon;

                string secondaryText;

                //NativeAdView.CallToActionView=CallToActionView;
                NativeAdView.HeadlineView = PrimaryView;
                NativeAdView.MediaView    = MediaView;
                SecondaryView.Visibility  = ViewStates.Visible;
                if (AdHasOnlyStore(nativeAd))
                {
                    NativeAdView.StoreView = SecondaryView;
                    secondaryText          = store;
                }
                else if (!TextUtils.IsEmpty(advertiser))
                {
                    NativeAdView.AdvertiserView = SecondaryView;
                    secondaryText = advertiser;
                }
                else
                {
                    secondaryText = "";
                }

                PrimaryView.Text = headline;
                //CallToActionView.Text=cta;

                //  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;
                //    NativeAdView.StarRatingView=RatingBar;
                //}
                //else
                //{
                //    SecondaryView.Text=secondaryText;
                //    SecondaryView.Visibility = ViewStates.Visible;
                //    RatingBar.Visibility= ViewStates.Gone;
                //}

                if (string.IsNullOrEmpty(secondaryText))
                {
                    SecondaryView.Visibility = ViewStates.Gone;
                }
                else
                {
                    SecondaryView.Visibility = ViewStates.Visible;
                    SecondaryView.Text       = secondaryText;
                }

                if (icon != null)
                {
                    IconView.Visibility = ViewStates.Visible;
                    IconView.SetImageDrawable(icon.Drawable);
                }
                else
                {
                    IconView.Visibility = ViewStates.Gone;
                }

                if (TertiaryView != null && !string.IsNullOrEmpty(body))
                {
                    TertiaryView.Text     = body;
                    NativeAdView.BodyView = TertiaryView;
                }
                else if (TertiaryView != null)
                {
                    TertiaryView.Visibility = ViewStates.Gone;
                }

                NativeAdView.SetNativeAd(nativeAd);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Esempio n. 5
0
        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);
            }
        }
Esempio n. 6
0
        public void SetNativeAd(UnifiedNativeAd nativeAd)
        {
            PostInflate();

            this.nativeAd = nativeAd;

            nativeAdView.CallToActionView = callToActionView;
            nativeAdView.HeadlineView     = primaryView;
            nativeAdView.MediaView        = mediaView;

            string secondaryText = "";

            secondaryView.Visibility = ViewStates.Visible;
            if (AdHasOnlyStore(nativeAd))
            {
                nativeAdView.StoreView = secondaryView;
                secondaryText          = nativeAd.Store;
            }
            else if (!string.IsNullOrWhiteSpace(nativeAd.Advertiser))
            {
                nativeAdView.AdvertiserView = secondaryView;
                secondaryText = nativeAd.Advertiser;
            }

            primaryView.Text      = nativeAd.Headline;
            callToActionView.Text = nativeAd.CallToAction;

            if (nativeAd.StarRating != null && nativeAd.StarRating.DoubleValue() > 0.0)
            {
                secondaryView.Visibility    = ViewStates.Gone;
                ratingBar.Visibility        = ViewStates.Visible;
                ratingBar.Max               = 5;
                nativeAdView.StarRatingView = ratingBar;
            }
            else
            {
                secondaryView.Text       = secondaryText;
                secondaryView.Visibility = ViewStates.Visible;
                ratingBar.Visibility     = ViewStates.Gone;
            }

            if (nativeAd.Icon != null)
            {
                iconView.Visibility = ViewStates.Visible;
                iconView.SetImageDrawable(nativeAd.Icon.Drawable);
            }
            else
            {
                iconView.Visibility = ViewStates.Gone;
            }

            if (tertiaryView != null && !string.IsNullOrWhiteSpace(nativeAd.Body))
            {
                tertiaryView.Visibility = ViewStates.Visible;
                tertiaryView.Text       = nativeAd.Body;
                nativeAdView.BodyView   = tertiaryView;
            }
            else if (tertiaryView != null)
            {
                tertiaryView.Visibility = ViewStates.Gone;
            }

            nativeAdView.SetNativeAd(nativeAd);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        public void SetNativeAd(UnifiedNativeAd nativeAd)
        {
            this.nativeAd = nativeAd;

            string store      = nativeAd.Store;
            string advertiser = nativeAd.Advertiser;
            string headline   = nativeAd.Headline;
            string body       = nativeAd.Body;
            string cta        = nativeAd.CallToAction;
            int    starRating = Convert.ToInt32(nativeAd.StarRating);

            NativeAd.Image icon          = nativeAd.Icon;
            string         secondaryText = string.Empty;

            nativeAdView.CallToActionView = callToActionView;
            nativeAdView.HeadlineView     = primaryView;
            nativeAdView.MediaView        = mediaView;
            secondaryView.Visibility      = ViewStates.Visible;
            if (AdHasOnlyStore(nativeAd))
            {
                nativeAdView.StoreView = secondaryView;
                secondaryText          = store;
            }
            else if (!string.IsNullOrEmpty(advertiser))
            {
                nativeAdView.AdvertiserView = secondaryView;
                secondaryText = advertiser;
            }

            primaryView.Text      = headline;
            callToActionView.Text = cta;

            //  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;
                nativeAdView.StarRatingView = ratingBar;
            }
            else
            {
                secondaryView.Text       = secondaryText;
                secondaryView.Visibility = ViewStates.Visible;
                ratingBar.Visibility     = ViewStates.Gone;
            }

            if (icon != null)
            {
                iconView.Visibility = ViewStates.Visible;
                iconView.SetImageDrawable(icon.Drawable);
            }
            else
            {
                iconView.Visibility = ViewStates.Gone;
            }

            if (tertiaryView != null)
            {
                tertiaryView.Text     = body;
                nativeAdView.BodyView = tertiaryView;
            }

            nativeAdView.SetNativeAd(nativeAd);
        }