Exemple #1
0
 private static WSANativeAd MapNativeAdV2ToWSANativeAd(NativeAdV2 nativeAdV2)
 {
     return(new WSANativeAd()
     {
         CallToActionText = nativeAdV2.CallToActionText,
         Description = nativeAdV2.Description,
         Price = nativeAdV2.Price,
         PrivacyUrl = nativeAdV2.PrivacyUrl,
         Rating = nativeAdV2.Rating,
         SponsoredBy = nativeAdV2.SponsoredBy,
         Title = nativeAdV2.Title,
         AdditionalAssets = nativeAdV2.AdditionalAssets.ToDictionary(x => x.Key, y => y.Value),
         IconImage = new WSANativeAdImage()
         {
             Height = nativeAdV2.IconImage.Height,
             Width = nativeAdV2.IconImage.Width,
             Url = nativeAdV2.IconImage.Url
         },
         MainImages = nativeAdV2.MainImages.Select(x => new WSANativeAdImage()
         {
             Height = nativeAdV2.IconImage.Height,
             Width = nativeAdV2.IconImage.Width,
             Url = nativeAdV2.IconImage.Url
         }).ToList()
     });
 }
Exemple #2
0
        private void SetAdUI(NativeAdV2 nativeAd)
        {
            if (nativeAd.AdIcon != null)
            {
                AdIconImage2.Source = nativeAd.AdIcon.Source;
            }

            // Show the ad title.
            TitleTextBlock.Text = nativeAd.Title;

            if (nativeAd.MainImages.Count > 0)
            {
                NativeImage mainImage   = nativeAd.MainImages[0];
                BitmapImage bitmapImage = new BitmapImage
                {
                    UriSource = new Uri(mainImage.Url)
                };
                AdIconImage.Source = bitmapImage;

                AdIconImage.Visibility = Visibility.Visible;
            }

            // Add the call to action string to the button.
            if (!string.IsNullOrEmpty(nativeAd.CallToActionText))
            {
                CallToActionButton.Content    = nativeAd.CallToActionText;
                CallToActionButton.Visibility = Visibility.Visible;
            }
            nativeAd.RegisterAdContainer(NativeAdContainer);
        }
Exemple #3
0
    private void MyNativeAd_AdReady(object sender, NativeAdReadyEventArgs e)
    {
        NativeAdV2 nativeAd = e.NativeAd;

        AdTitle.Text   = nativeAd.Title;
        Adimage.Source = nativeAd.AdIcon.Source;
        nativeAd.RegisterAdContainer(AdContainer);
    }
        public NativeAdData()
        {
            myNativeAdsManager = new NativeAdsManagerV2(myAppId, myAdUnitId);
            //this might cause memory leak because the event is not being unSubscribed.
            //Though not sure how to work around this.
            myNativeAdsManager.AdReady += (s, e) =>
            {
                nativeAd = e.NativeAd;

                // Show the ad icon.
                if (nativeAd.AdIcon != null)
                {
                    AdIcon = nativeAd.AdIcon.Source;
                }
                //Show the ad title.
                Title = nativeAd.Title;

                // Show the ad description.
                //if (!string.IsNullOrEmpty(nativeAd.Description))
                //{
                //    Description = nativeAd.Description;
                //}

                // Display the first main image for the ad. Note that the service
                // might provide multiple main images.
                if (nativeAd.MainImages.Count > 0)
                {
                    NativeImage mainImage   = nativeAd.MainImages[0];
                    BitmapImage bitmapImage = new BitmapImage
                    {
                        UriSource = new Uri(mainImage.Url)
                    };
                    MainImageUrl = bitmapImage;
                }

                // Add the call to action string to the button.
                //if (!string.IsNullOrEmpty(nativeAd.CallToActionText))
                //{
                //    CallToAction = nativeAd.CallToActionText;
                //}
                // Show the ad sponsored by value.
                //if (!string.IsNullOrEmpty(nativeAd.SponsoredBy))
                //{
                //    SponsoredBy = nativeAd.SponsoredBy;
                //}
                // Show the icon image for the ad.
                //if (nativeAd.IconImage != null)
                //{
                //    BitmapImage bitmapImage = new BitmapImage
                //    {
                //        UriSource = new Uri(nativeAd.IconImage.Url)
                //    };
                //}
                nativeAd?.RegisterAdContainer(parent);
            };
            myNativeAdsManager.ErrorOccurred += (s, e) => Title = "ErrorAds".GetLocalized();
        }
Exemple #5
0
        //<AdReady>
        void MyNativeAd_AdReady(object sender, NativeAdReadyEventArgs e)
        {
            NativeAdV2 nativeAd = e.NativeAd;

            // Show the ad icon.
            if (nativeAd.AdIcon != null)
            {
                AdIconImage.Source = nativeAd.AdIcon.Source;

                // Adjust the Image control to the height and width of the
                // provided ad icon.
                AdIconImage.Height = nativeAd.AdIcon.Height;
                AdIconImage.Width  = nativeAd.AdIcon.Width;
            }

            // Show the ad title.
            TitleTextBlock.Text = nativeAd.Title;

            // Show the ad description.
            if (!string.IsNullOrEmpty(nativeAd.Description))
            {
                DescriptionTextBlock.Text       = nativeAd.Description;
                DescriptionTextBlock.Visibility = Visibility.Visible;
            }

            // Display the first main image for the ad. Note that the service
            // might provide multiple main images.
            if (nativeAd.MainImages.Count > 0)
            {
                NativeImage mainImage   = nativeAd.MainImages[0];
                BitmapImage bitmapImage = new BitmapImage();
                bitmapImage.UriSource = new Uri(mainImage.Url);
                MainImageImage.Source = bitmapImage;

                // Adjust the Image control to the height and width of the
                // main image.
                MainImageImage.Height     = mainImage.Height;
                MainImageImage.Width      = mainImage.Width;
                MainImageImage.Visibility = Visibility.Visible;
            }

            // Add the call to action string to the button.
            if (!string.IsNullOrEmpty(nativeAd.CallToActionText))
            {
                CallToActionButton.Content    = nativeAd.CallToActionText;
                CallToActionButton.Visibility = Visibility.Visible;
            }

            // Show the ad sponsored by value.
            if (!string.IsNullOrEmpty(nativeAd.SponsoredBy))
            {
                SponsoredByTextBlock.Text       = nativeAd.SponsoredBy;
                SponsoredByTextBlock.Visibility = Visibility.Visible;
            }

            // Show the icon image for the ad.
            if (nativeAd.IconImage != null)
            {
                BitmapImage bitmapImage = new BitmapImage();
                bitmapImage.UriSource = new Uri(nativeAd.IconImage.Url);
                IconImageImage.Source = bitmapImage;

                // Adjust the Image control to the height and width of the
                // icon image.
                IconImageImage.Height     = nativeAd.IconImage.Height;
                IconImageImage.Width      = nativeAd.IconImage.Width;
                IconImageImage.Visibility = Visibility.Visible;
            }

            // Register the container of the controls that display
            // the native ad elements for clicks/impressions.
            nativeAd.RegisterAdContainer(NativeAdContainer);
        }
Exemple #6
0
        public static void Initialise(Grid grid)
        {
            _root = grid;

            _container = new StackPanel();

            WSANativeNativeAd._Request += (appId, adUnitId) =>
            {
                if (_nativeAdsManagerV2 == null)
                {
                    _nativeAdsManagerV2 = new NativeAdsManagerV2(appId, adUnitId);

                    _nativeAdsManagerV2.AdReady += (s, e) =>
                    {
                        _currentAd = e.NativeAd;

                        _isRegistered = false;

                        RaiseActionOnAppThread(WSANativeNativeAd.AdReady, MapNativeAdV2ToWSANativeAd(_currentAd));
                    };

                    _nativeAdsManagerV2.ErrorOccurred += (s, e) =>
                    {
                        RaiseActionOnAppThread(WSANativeNativeAd.ErrorOccurred, $"{e.ErrorCode} - {e.ErrorMessage}");
                    };
                }
                else
                {
                    _nativeAdsManagerV2.RequestAd();
                }
            };

            WSANativeNativeAd._Position += (x, y, width, height) =>
            {
                if (_nativeAdsManagerV2 != null && _currentAd != null)
                {
                    _container.Width  = width;
                    _container.Height = height;
                    _container.Margin = new Thickness(x, y, 0, 0);

                    if (!_root.Children.Contains(_container))
                    {
                        _root.Children.Add(_container);
                    }

                    if (!_isRegistered)
                    {
                        _currentAd.RegisterAdContainer(_container);

                        _isRegistered = true;
                    }
                }
            };

            WSANativeNativeAd._Destroy += () =>
            {
                if (_nativeAdsManagerV2 != null && _currentAd != null)
                {
                    if (_root.Children.Contains(_container))
                    {
                        _root.Children.Remove(_container);
                    }

                    _currentAd    = null;
                    _isRegistered = false;
                }
            };
        }