Ejemplo n.º 1
0
        public RewardedAd(string adUnitId)
        {
            this.client = MobileAds.GetClientFactory().BuildRewardedAdClient();
            client.CreateRewardedAd(adUnitId);

            this.client.OnAdLoaded += (sender, args) =>
            {
                if (this.OnAdLoaded != null)
                {
                    this.OnAdLoaded(this, args);
                }
            };

            this.client.OnAdFailedToLoad += (sender, args) =>
            {
                if (this.OnAdFailedToLoad != null)
                {
                    this.OnAdFailedToLoad(this, args);
                }
            };

            this.client.OnAdFailedToShow += (sender, args) =>
            {
                if (this.OnAdFailedToShow != null)
                {
                    this.OnAdFailedToShow(this, args);
                }
            };

            this.client.OnAdOpening += (sender, args) =>
            {
                if (this.OnAdOpening != null)
                {
                    this.OnAdOpening(this, args);
                }
            };

            this.client.OnAdClosed += (sender, args) =>
            {
                if (this.OnAdClosed != null)
                {
                    this.OnAdClosed(this, args);
                }
            };

            this.client.OnUserEarnedReward += (sender, args) =>
            {
                if (this.OnUserEarnedReward != null)
                {
                    this.OnUserEarnedReward(this, args);
                }
            };

            this.client.OnPaidEvent += (sender, args) =>
            {
                if (this.OnPaidEvent != null)
                {
                    this.OnPaidEvent(this, args);
                }
            };
        }
Ejemplo n.º 2
0
        // Creates a Singleton RewardBasedVideoAd.
        private RewardBasedVideoAd()
        {
            this.client = MobileAds.GetClientFactory().BuildRewardBasedVideoAdClient();
            client.CreateRewardBasedVideoAd();

            this.client.OnAdLoaded += (sender, args) =>
            {
                if (this.OnAdLoaded != null)
                {
                    this.OnAdLoaded(this, args);
                }
            };

            this.client.OnAdFailedToLoad += (sender, args) =>
            {
                if (this.OnAdFailedToLoad != null)
                {
                    this.OnAdFailedToLoad(this, args);
                }
            };

            this.client.OnAdOpening += (sender, args) =>
            {
                if (this.OnAdOpening != null)
                {
                    this.OnAdOpening(this, args);
                }
            };

            this.client.OnAdStarted += (sender, args) =>
            {
                if (this.OnAdStarted != null)
                {
                    this.OnAdStarted(this, args);
                }
            };

            this.client.OnAdClosed += (sender, args) =>
            {
                if (this.OnAdClosed != null)
                {
                    this.OnAdClosed(this, args);
                }
            };

            this.client.OnAdLeavingApplication += (sender, args) =>
            {
                if (this.OnAdLeavingApplication != null)
                {
                    this.OnAdLeavingApplication(this, args);
                }
            };

            this.client.OnAdRewarded += (sender, args) =>
            {
                if (this.OnAdRewarded != null)
                {
                    this.OnAdRewarded(this, args);
                }
            };

            this.client.OnAdCompleted += (sender, args) =>
            {
                if (this.OnAdCompleted != null)
                {
                    this.OnAdCompleted(this, args);
                }
            };
        }
Ejemplo n.º 3
0
        public RewardedAd(string adUnitId)
        {
            this.client   = MobileAds.GetClientFactory().BuildRewardedAdClient();
            this.adUnitId = adUnitId;
            this.isLoaded = false;
            client.CreateRewardedAd();

            this.client.OnAdLoaded += (sender, args) =>
            {
                this.isLoaded = true;
                if (this.OnAdLoaded != null)
                {
                    this.OnAdLoaded(this, args);
                }
            };

            this.client.OnAdFailedToLoad += (sender, args) =>
            {
                if (this.OnAdFailedToLoad != null)
                {
                    LoadAdError loadAdError = new LoadAdError(args.LoadAdErrorClient);
                    this.OnAdFailedToLoad(this, new AdFailedToLoadEventArgs()
                    {
                        LoadAdError = loadAdError
                    });
                }
            };

            this.client.OnAdFailedToPresentFullScreenContent += (sender, args) =>
            {
                if (this.OnAdFailedToShow != null)
                {
                    AdError adError = new AdError(args.AdErrorClient);

                    this.OnAdFailedToShow(this, new AdErrorEventArgs()
                    {
                        AdError = adError
                    });
                }
            };

            this.client.OnAdDidPresentFullScreenContent += (sender, args) =>
            {
                if (this.OnAdOpening != null)
                {
                    this.OnAdOpening(this, args);
                }
            };

            this.client.OnAdDidDismissFullScreenContent += (sender, args) =>
            {
                if (this.OnAdClosed != null)
                {
                    this.OnAdClosed(this, args);
                }
            };

            this.client.OnAdFailedToPresentFullScreenContent += (sender, args) =>
            {
                if (this.OnAdFailedToShow != null)
                {
                    AdError adError = new AdError(args.AdErrorClient);
                    this.OnAdFailedToShow(this, new AdErrorEventArgs()
                    {
                        AdError = adError
                    });
                }
            };

            this.client.OnAdDidRecordImpression += (sender, args) =>
            {
                if (this.OnAdDidRecordImpression != null)
                {
                    this.OnAdDidRecordImpression(this, args);
                }
            };

            this.client.OnUserEarnedReward += (sender, args) =>
            {
                if (this.OnUserEarnedReward != null)
                {
                    this.OnUserEarnedReward(this, args);
                }
            };

            this.client.OnPaidEvent += (sender, args) =>
            {
                if (this.OnPaidEvent != null)
                {
                    this.OnPaidEvent(this, args);
                }
            };
        }
Ejemplo n.º 4
0
        private AdLoader(Builder builder)
        {
            this.AdUnitId = string.Copy(builder.AdUnitId);
            this.CustomNativeTemplateClickHandlers =
                new Dictionary <string, Action <CustomNativeTemplateAd, string> >(
                    builder.CustomNativeTemplateClickHandlers);
            this.TemplateIds = new HashSet <string>(builder.TemplateIds);
            this.AdTypes     = new HashSet <NativeAdType>(builder.AdTypes);

            Dictionary <string, bool> templateIdsDictionary = new Dictionary <string, bool>();

            foreach (string templateId in TemplateIds)
            {
                templateIdsDictionary[templateId] = false;
            }
            foreach (var keyValuePair in this.CustomNativeTemplateClickHandlers)
            {
                templateIdsDictionary[keyValuePair.Key] = true;
            }
            AdLoaderClientArgs clientArgs = new AdLoaderClientArgs()
            {
                AdUnitId    = this.AdUnitId,
                AdTypes     = this.AdTypes,
                TemplateIds = templateIdsDictionary
            };

            this.adLoaderClient = MobileAds.GetClientFactory().BuildAdLoaderClient(clientArgs);

            Utils.CheckInitialization();

            this.adLoaderClient.OnCustomNativeTemplateAdLoaded +=
                delegate(object sender, CustomNativeClientEventArgs args)
            {
                CustomNativeTemplateAd nativeAd    = new CustomNativeTemplateAd(args.nativeAdClient);
                CustomNativeEventArgs  adEventArgs = new CustomNativeEventArgs()
                {
                    nativeAd = nativeAd
                };
                this.OnCustomNativeTemplateAdLoaded(this, adEventArgs);
            };
            this.adLoaderClient.OnCustomNativeTemplateAdClicked +=
                delegate(object sender, CustomNativeClientEventArgs args)
            {
                CustomNativeTemplateAd nativeAd = new CustomNativeTemplateAd(args.nativeAdClient);
                if (this.CustomNativeTemplateClickHandlers.ContainsKey(nativeAd.GetCustomTemplateId()))
                {
                    this.CustomNativeTemplateClickHandlers[nativeAd.GetCustomTemplateId()](nativeAd, args.assetName);
                }
            };
            this.adLoaderClient.OnAdFailedToLoad += delegate(
                object sender, LoadAdErrorClientEventArgs args)
            {
                if (this.OnAdFailedToLoad != null)
                {
                    LoadAdError loadAdError = new LoadAdError(args.LoadAdErrorClient);
                    this.OnAdFailedToLoad(this, new AdFailedToLoadEventArgs()
                    {
                        LoadAdError = loadAdError,
                        Message     = loadAdError.GetMessage()
                    });
                }
            };
        }
Ejemplo n.º 5
0
        public RewardedAd(string adUnitId)
        {
            this.client = MobileAds.GetClientFactory().BuildRewardedAdClient();
            client.CreateRewardedAd(adUnitId);

            this.client.OnAdLoaded += (sender, args) =>
            {
                if (this.OnAdLoaded != null)
                {
                    this.OnAdLoaded(this, args);
                }
            };

            this.client.OnAdFailedToLoad += (sender, args) =>
            {
                if (this.OnAdFailedToLoad != null)
                {
                    LoadAdError loadAdError = new LoadAdError(args.LoadAdErrorClient);
                    this.OnAdFailedToLoad(this, new AdFailedToLoadEventArgs()
                    {
                        LoadAdError = loadAdError,
                        Message     = loadAdError.GetMessage()
                    });
                }
            };

            this.client.OnAdFailedToShow += (sender, args) =>
            {
                if (this.OnAdFailedToShow != null)
                {
                    AdError adError = new AdError(args.AdErrorClient);

                    this.OnAdFailedToShow(this, new AdErrorEventArgs()
                    {
                        AdError = adError,
                        Message = adError.GetMessage()
                    });
                }
            };

            this.client.OnAdOpening += (sender, args) =>
            {
                if (this.OnAdOpening != null)
                {
                    this.OnAdOpening(this, args);
                }
            };

            this.client.OnAdClosed += (sender, args) =>
            {
                if (this.OnAdClosed != null)
                {
                    this.OnAdClosed(this, args);
                }
            };

            this.client.OnUserEarnedReward += (sender, args) =>
            {
                if (this.OnUserEarnedReward != null)
                {
                    this.OnUserEarnedReward(this, args);
                }
            };

            this.client.OnPaidEvent += (sender, args) =>
            {
                if (this.OnPaidEvent != null)
                {
                    this.OnPaidEvent(this, args);
                }
            };
        }