Esempio n. 1
0
        public AdLoaderClient(AdLoaderClientArgs clientArgs)
        {
            this.adLoaderClientPtr = (IntPtr)GCHandle.Alloc(this);
            this.TemplateIds       = clientArgs.TemplateIds;
            string[] templateIdsArray = new string[TemplateIds.Keys.Count];
            TemplateIds.Keys.ToList().CopyTo(templateIdsArray);

            this.adTypes = new NativeAdTypes();
            bool configureReturnUrlsForImageAssets = false;

            if (clientArgs.AdTypes.Contains(NativeAdType.CustomTemplate))
            {
                configureReturnUrlsForImageAssets = false;
                adTypes.CustomTemplateAd          = 1;
            }
            this.AdLoaderPtr = Externs.GADUCreateAdLoader(
                this.adLoaderClientPtr,
                clientArgs.AdUnitId,
                templateIdsArray,
                templateIdsArray.Length,
                ref adTypes,
                configureReturnUrlsForImageAssets);

            Externs.GADUSetAdLoaderCallbacks(
                this.AdLoaderPtr,
                AdLoaderDidReceiveNativeCustomTemplateAdCallback,
                AdLoaderDidFailToReceiveAdWithErrorCallback);
        }
Esempio n. 2
0
        public AdLoaderClient(AdLoaderClientArgs args) : base(Utils.UnityAdLoaderListenerClassName)
        {
            AndroidJavaClass  playerClass = new AndroidJavaClass(Utils.UnityActivityClassName);
            AndroidJavaObject activity    =
                playerClass.GetStatic <AndroidJavaObject>("currentActivity");

            adLoader = new AndroidJavaObject(Utils.NativeAdLoaderClassName, activity,
                                             args.AdUnitId, this);

            bool supportsRequestImageAssetUrls = false;

            if (args.AdTypes.Contains(NativeAdType.CustomTemplate))
            {
                supportsRequestImageAssetUrls = false;
                foreach (var keyValuePair in args.TemplateIds)
                {
                    string templateID = keyValuePair.Key;
                    bool   hasHandler = keyValuePair.Value;
                    adLoader.Call("configureCustomNativeTemplateAd", templateID,
                                  hasHandler);
                }
            }
            if (supportsRequestImageAssetUrls)
            {
                adLoader.Call("configureReturnUrlsForImageAssets");
            }
            adLoader.Call("create");
        }
Esempio n. 3
0
 public IAdLoaderClient BuildAdLoaderClient(AdLoaderClientArgs args)
 {
     if (Application.platform == RuntimePlatform.Android)
     {
         return(new GoogleMobileAds.Android.AdLoaderClient(args));
     }
     return(new GoogleMobileAds.Common.DummyClient());
 }
Esempio 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 = 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);
                }
            };
        }
 public static IAdLoaderClient BuildAdLoaderClient(AdLoaderClientArgs args)
 {
     return(new GoogleMobileAds.iOS.AdLoaderClient(args));
 }