public void onCustomTemplateAdLoaded(AndroidJavaObject ad) { CustomNativeEventArgs args = new CustomNativeEventArgs() { nativeAd = new CustomNativeTemplateAd(new CustomNativeTemplateClient(ad)) }; OnCustomNativeTemplateAdLoaded(this, args); }
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 = GoogleMobileAdsClientFactory.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); } }; }
private static void AdLoaderDidReceiveNativeCustomTemplateAdCallback( IntPtr adLoader, IntPtr nativeCustomTemplateAd, string templateID) { AdLoaderClient client = IntPtrToAdLoaderClient(adLoader); Action<CustomNativeTemplateAd, string> clickHandler = client.customNativeTemplateCallbacks.ContainsKey(templateID) ? client.customNativeTemplateCallbacks[templateID] : null; CustomNativeEventArgs args = new CustomNativeEventArgs() { nativeAd = new CustomNativeTemplateAd(new CustomNativeTemplateClient( nativeCustomTemplateAd, clickHandler)) }; client.OnCustomNativeTemplateAdLoaded(client, args); }