public void ShowAd(Activity context, TemplateView template = null)
            {
                try
                {
                    Context = context;

                    Template            = template ?? Context.FindViewById <TemplateView>(Resource.Id.my_template);
                    Template.Visibility = ViewStates.Gone;

                    if (AppSettings.ShowAdMobNative)
                    {
                        AdLoader.Builder builder = new AdLoader.Builder(Context, AppSettings.AdAdMobNativeKey);
                        builder.ForUnifiedNativeAd(this);
                        VideoOptions videoOptions = new VideoOptions.Builder()
                                                    .SetStartMuted(true)
                                                    .Build();
                        NativeAdOptions adOptions = new NativeAdOptions.Builder()
                                                    .SetVideoOptions(videoOptions)
                                                    .Build();

                        builder.WithNativeAdOptions(adOptions);

                        AdLoader adLoader = builder.WithAdListener(new AdListener()).Build();
                        adLoader.LoadAd(new AdRequest.Builder().Build());
                    }
                    else
                    {
                        Template.Visibility = ViewStates.Gone;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
Example #2
0
            public void ShowAd(Activity context, View view)
            {
                try
                {
                    View    = view;
                    Context = context;

                    if (View != null)
                    {
                        Template = View.FindViewById <TemplateView>(Resource.Id.my_template);
                    }
                    else
                    {
                        Template = Context.FindViewById <TemplateView>(Resource.Id.my_template);
                    }

                    Template.Visibility = ViewStates.Gone;

                    var isPro = ListUtils.MyUserInfo.FirstOrDefault()?.IsPro ?? "0";
                    if (isPro == "0" && AppSettings.ShowAdMobNative)
                    {
                        AdLoader.Builder builder = new AdLoader.Builder(Context, AppSettings.AdAdMobNativeKey);
                        builder.ForUnifiedNativeAd(this);
                        VideoOptions videoOptions = new VideoOptions.Builder()
                                                    .SetStartMuted(true)
                                                    .Build();
                        NativeAdOptions adOptions = new NativeAdOptions.Builder()
                                                    .SetVideoOptions(videoOptions)
                                                    .Build();

                        builder.WithNativeAdOptions(adOptions);

                        AdLoader adLoader = builder.WithAdListener(new AdListener()).Build();
                        adLoader.LoadAd(new AdRequest.Builder().Build());
                    }
                    else
                    {
                        Template.Visibility = ViewStates.Gone;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
Example #3
0
            public void ShowAd(Activity context, TemplateView template = null)
            {
                try
                {
                    Context = context;

                    Template = template ?? Context.FindViewById <TemplateView>(Resource.Id.my_template);
                    if (Template != null)
                    {
                        Template.Visibility = ViewStates.Gone;

                        switch (AppSettings.ShowAdMobNative)
                        {
                        case true:
                        {
                            AdLoader.Builder builder = new AdLoader.Builder(Context, AppSettings.AdAdMobNativeKey);
                            builder.ForUnifiedNativeAd(this);
                            VideoOptions videoOptions = new VideoOptions.Builder()
                                                        .SetStartMuted(true)
                                                        .Build();
                            NativeAdOptions adOptions = new NativeAdOptions.Builder()
                                                        .SetVideoOptions(videoOptions)
                                                        .Build();

                            builder.WithNativeAdOptions(adOptions);

                            AdLoader adLoader = builder.WithAdListener(new AdListener()).Build();
                            adLoader.LoadAd(new AdRequest.Builder().Build());
                            break;
                        }

                        default:
                            Template.Visibility = ViewStates.Gone;
                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    Methods.DisplayReportResultTrack(e);
                }
            }
Example #4
0
        public void Initialize()
        {
            if (Loader != null)
            {
                throw new InvalidOperationException("AdAgent.Initialize() should only be called once.");
            }

            var builder = new AdLoader.Builder(UIRuntime.CurrentActivity, UnitId);

            builder.ForUnifiedNativeAd(new UnifiedNativeAdListener(this));

            var adOptions = new NativeAdOptions.Builder()
                            .SetVideoOptions(new VideoOptions.Builder().SetStartMuted(true).Build())
                            .Build();

            builder.WithNativeAdOptions(adOptions);

            builder.WithAdListener(new ZebbleAdListener(this));

            Loader = builder.Build();
        }
Example #5
0
        void CreateAdLoader()
        {
            var view = Element as AdMobNativeView;

            if (view == null ||
                string.IsNullOrWhiteSpace(view.UnitId) ||
                view.AdMob == null)
            {
                return;
            }

            var nativeAdOptionsBuilder = new NativeAdOptions.Builder();

            var adLoaderBuilder = new AdLoader.Builder(Context, view.UnitId);

            adLoaderBuilder
            .ForUnifiedNativeAd(this)
            .WithAdListener(new MyAdListener(this))
            .WithNativeAdOptions(nativeAdOptionsBuilder.Build());

            adLoader = adLoaderBuilder.Build();
        }