Esempio n. 1
0
 public MyGridView()
 {
     myNativeAdsManager                = new NativeAdsManagerV2(myAppId, myAdUnitId);
     myNativeAdsManager.AdReady       += MyNativeAd_AdReady;
     myNativeAdsManager.ErrorOccurred += MyNativeAdsManager_ErrorOccurred;
     myNativeAdsManager.RequestAd();
 }
Esempio n. 2
0
        private void PrepareAds()
        {
            NativeAdsManagerV2 myNativeAdsManager = new NativeAdsManagerV2(AppId, AdUnitId);

            myNativeAdsManager.AdReady       += MyNativeAd_AdReady;
            myNativeAdsManager.ErrorOccurred += MyNativeAdsManager_ErrorOccurred;
            myNativeAdsManager.RequestAd();
        }
        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();
        }
Esempio n. 4
0
        public NativeAdPage()
        {
            this.InitializeComponent();

            myNativeAdsManager                = new NativeAdsManagerV2(myAppId, myAdUnitId);
            myNativeAdsManager.AdReady       += MyNativeAd_AdReady;
            myNativeAdsManager.ErrorOccurred += MyNativeAdsManager_ErrorOccurred;

            myNativeAdsManager.RequestAd();
        }
Esempio n. 5
0
        //</Variables>

        public MainPage()
        {
            this.InitializeComponent();

            //<ConfigureNativeAd>
            myNativeAdsManager                = new NativeAdsManagerV2(myAppId, myAdUnitId);
            myNativeAdsManager.AdReady       += MyNativeAd_AdReady;
            myNativeAdsManager.ErrorOccurred += MyNativeAdsManager_ErrorOccurred;
            //</ConfigureNativeAd>

            //<RequestAd>
            myNativeAdsManager.RequestAd();
            //</RequestAd>
        }
        private void MyAdContainer_Loaded(object sender, RoutedEventArgs e)
        {
            // test AdID
            //string myAppId = "d25517cb-12d4-4699-8bdc-52040c712cab";
            //string myAdUnitId = "test";

            // ad info passed with DataContext
            var myAppId    = (DataContext as MyItem)?.AdUnitId;
            var myAdUnitId = (DataContext as MyItem)?.AdUnitId;

            if (string.IsNullOrEmpty(myAppId) || string.IsNullOrEmpty(myAdUnitId))
            {
                return;
            }

            _myNativeAdsManager                = new NativeAdsManagerV2(myAppId, myAdUnitId);
            _myNativeAdsManager.AdReady       += MyNativeAd_AdReady;
            _myNativeAdsManager.ErrorOccurred += MyNativeAdsManager_ErrorOccurred;

            _myNativeAdsManager.RequestAd();

            TitleTextBlock.Text = "Ad requested, waiting...";
        }
Esempio n. 7
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;
                }
            };
        }