示例#1
0
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.View> e)
        {
            base.OnElementChanged(e);

            var adLoader = new AdLoader.Builder(Context, AppConfig.ADMOB_NATIVE_ADS_ID);

            var listener = new UnifiedNativeAdLoadedListener();

            listener.OnNativeAdLoaded += (s, ad) =>
            {
                // Load ad Completed
                try
                {
                    ButtonColor = (e.NewElement as AdmobSmallNativeAdsView).ButtonColor.ToAndroid();
                    nativeAd    = ad;
                    var root     = new UnifiedNativeAdView(Context);
                    var inflater = (LayoutInflater)Context.GetSystemService(Context.LayoutInflaterService);

                    var nativeAdView = (UnifiedNativeAdView)inflater.Inflate(Resource.Layout.gnt_small_template_view, root);

                    populateUnifiedNativeAdView(ad, nativeAdView);
                    SetNativeControl(nativeAdView);
                }
                catch
                {
                }
            };

            adLoader.ForUnifiedNativeAd(listener);
            var requestBuilder = new AdRequest.Builder();

            adLoader.Build().LoadAd(requestBuilder.Build());
        }
示例#2
0
            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)
                {
                    Methods.DisplayReportResultTrack(e);
                }
            }
示例#3
0
        private void BindAdMob(Holders.AdMobAdapterViewHolder holder)
        {
            try
            {
                Template = holder.MianAlert;

                AdLoader.Builder builder = new AdLoader.Builder(holder.MainView.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());
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
示例#4
0
            public void ShowAd(Activity context)
            {
                try
                {
                    Context             = context;
                    Template            = Context.FindViewById <TemplateView>(Resource.Id.my_template);
                    Template.Visibility = ViewStates.Gone;

                    var isPro = ListUtils.MyUserInfoList.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);
                }
            }
示例#5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            SetSupportActionBar(toolbar);
            ///Init ManagerAds
            adsMgr              = new AdsManager(ApplicationContext);
            txtStatusInter      = FindViewById <TextView>(Resource.Id.txtStateInterstitial);
            btnLoadInter        = FindViewById <Button>(Resource.Id.btnLoad);
            btnShowInter        = FindViewById <Button>(Resource.Id.btnShowInter);
            btnOpenActiveNative = FindViewById <Button>(Resource.Id.btnOpenNative);

            btnLoadInter.Click += BtnLoadInter_Click;
            btnShowInter.Click += BtnShowInter_Click;

            btnOpenActiveNative.Click += BtnOpenActiveNative_Click;

            //Implement Banner Ads
            var adview = FindViewById <AdView>(Resource.Id.adView);

            adsMgr.CreateAds(adview);

            var builder = new AdLoader.Builder(ApplicationContext, GetString(Resource.String.admobNative));
            var listen  = new AdsUnifiedLoadListening();

            listen.Ads_UnifiedNativeLoad += (obj, unifiedAds) =>
            {
                var          style = new NativeTemplateStyle.Builder().build();
                TemplateView view  = FindViewById <TemplateView>(Resource.Id.adviewTemplate);
                view.Visibility = ViewStates.Visible;
                view.SetStyles(style);
                view.SetNativeAd(unifiedAds);
            };
            builder.ForUnifiedNativeAd(listen);
            builder.WithAdListener(listen);
            builder.WithNativeAdOptions(new Android.Gms.Ads.Formats.NativeAdOptions.Builder().Build());

            AdLoader adloader = builder.Build();

            adloader.LoadAd(new AdRequest.Builder().Build());
            if (listen.Tag is null)
            {
                listen.Tag = adloader;
            }
        }
示例#6
0
        public void CreateUnifiedAds(int numAds, AdsUnifiedLoadListening listen)
        {
            if (listen == null)
            {
                throw new ValidatingException("Not Implemented listener Unified");
            }
            var builder = new AdLoader.Builder(context, context.GetString(Resource.String.admobNative));

            builder.ForUnifiedNativeAd(listen);
            builder.WithAdListener(listen);
            builder.WithNativeAdOptions(new Android.Gms.Ads.Formats.NativeAdOptions.Builder().SetAdChoicesPlacement(5).Build());

            AdLoader adloader = builder.Build();

            adloader.LoadAds(new AdRequest.Builder().Build(), numAds);
            if (listen.Tag is null)
            {
                listen.Tag = adloader;
            }
        }
示例#7
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();
        }
示例#8
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();
        }