// Creates a BannerView with a custom position. public BannerView(string adUnitId, AdSize adSize, int x, int y) { this.client = MobileAds.GetClientFactory().BuildBannerClient(); client.CreateBannerView(adUnitId, adSize, x, y); ConfigureBannerEvents(); }
// Loads a new rewarded interstitial ad. public static void LoadAd(string adUnitID, AdRequest request, Action <RewardedInterstitialAd, AdFailedToLoadEventArgs> adLoadCallback) { IRewardedInterstitialAdClient client = MobileAds.GetClientFactory().BuildRewardedInterstitialAdClient(); loadingClients.Add(client); client.CreateRewardedInterstitialAd(); client.OnAdLoaded += (sender, args) => { if (adLoadCallback != null) { adLoadCallback(new RewardedInterstitialAd(client), null); loadingClients.Remove(client); } }; client.OnAdFailedToLoad += (sender, args) => { if (adLoadCallback != null) { LoadAdError loadAdError = new LoadAdError(args.LoadAdErrorClient); adLoadCallback(null, new AdFailedToLoadEventArgs() { LoadAdError = loadAdError }); loadingClients.Remove(client); } }; client.LoadAd(adUnitID, request); }
// Creates a BannerView and adds it to the view hierarchy. public BannerView(string adUnitId, AdSize adSize, AdPosition position) { this.client = MobileAds.GetClientFactory().BuildBannerClient(); client.CreateBannerView(adUnitId, adSize, position); ConfigureBannerEvents(); }
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, AdFailedToLoadEventArgs args) { if (this.OnAdFailedToLoad != null) { this.OnAdFailedToLoad(this, args); } }; }
// Creates an InterstitialAd. public InterstitialAd(string adUnitId) { this.client = MobileAds.GetClientFactory().BuildInterstitialClient(); client.CreateInterstitialAd(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.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.OnAdLeavingApplication += (sender, args) => { if (this.OnAdLeavingApplication != null) { this.OnAdLeavingApplication(this, args); } }; this.client.OnPaidEvent += (sender, args) => { if (this.OnPaidEvent != null) { this.OnPaidEvent(this, args); } }; }
// Creates an InterstitialAd. public InterstitialAd(string adUnitId) { this.client = MobileAds.GetClientFactory().BuildInterstitialClient(); client.CreateInterstitialAd(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.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.OnAdLeavingApplication += (sender, args) => { if (this.OnAdLeavingApplication != null) { this.OnAdLeavingApplication(this, args); } }; this.client.OnPaidEvent += (sender, args) => { if (this.OnPaidEvent != null) { this.OnPaidEvent(this, args); } }; }
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); } }; }
// 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); } }; }
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); } }; }
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); } }; }