Beispiel #1
0
            /// <summary>
            /// Ad loaded callback
            /// </summary>
            /// <param name="ad"></param>
            public void OnAdLoaded(IAd ad)
            {
                try
                {
                    if (NativeAd == null || NativeAd != ad)
                    {
                        // Race condition, load() called again before last ad was displayed
                        return;
                    }

                    if (NativeAdLayout == null)
                    {
                        return;
                    }

                    Activity.RunOnUiThread(() =>
                    {
                        try
                        {
                            NativeAdLayout.Visibility = ViewStates.Visible;

                            // Unregister last ad
                            NativeAd.UnregisterView();

                            if (NativeAdChoicesContainer != null)
                            {
                                var adOptionsView = new AdOptionsView(Activity, NativeAd, NativeAdLayout);
                                NativeAdChoicesContainer.RemoveAllViews();
                                NativeAdChoicesContainer.AddView(adOptionsView, 0);
                            }

                            InflateAd(NativeAd, NativeAdLayout);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }
                    });
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
Beispiel #2
0
        private static void LoadAd(Activity activity, AdHolder holder, NativeAd nativeAd, NativeAdLayout adView)
        {
            try
            {
                adView.Visibility = ViewStates.Visible;

                if (holder.NativeAdChoicesContainer != null)
                {
                    var adOptionsView = new AdOptionsView(activity, nativeAd, adView);
                    holder.NativeAdChoicesContainer.RemoveAllViews();
                    holder.NativeAdChoicesContainer.AddView(adOptionsView, 0);
                }

                // Setting the Text
                holder.NativeAdSocialContext.Text      = nativeAd.AdSocialContext;
                holder.NativeAdCallToAction.Text       = nativeAd.AdCallToAction;
                holder.NativeAdCallToAction.Visibility = nativeAd.HasCallToAction ? ViewStates.Visible : ViewStates.Invisible;
                holder.NativeAdTitle.Text  = nativeAd.AdvertiserName;
                holder.NativeAdBody.Text   = nativeAd.AdBodyText;
                holder.SponsoredLabel.Text = activity.GetText(Resource.String.sponsored);

                // You can use the following to specify the clickable areas.
                List <View> clickableViews = new List <View> {
                    holder.NativeAdIcon, holder.NativeAdMedia, holder.NativeAdCallToAction
                };

                nativeAd.RegisterViewForInteraction(adView, holder.NativeAdMedia, holder.NativeAdIcon, clickableViews);

                // Optional: tag views
                NativeAdBase.NativeComponentTag.TagView(holder.NativeAdIcon, NativeAdBase.NativeComponentTag.AdIcon);
                NativeAdBase.NativeComponentTag.TagView(holder.NativeAdTitle, NativeAdBase.NativeComponentTag.AdTitle);
                NativeAdBase.NativeComponentTag.TagView(holder.NativeAdBody, NativeAdBase.NativeComponentTag.AdBody);
                NativeAdBase.NativeComponentTag.TagView(holder.NativeAdSocialContext, NativeAdBase.NativeComponentTag.AdSocialContext);
                NativeAdBase.NativeComponentTag.TagView(holder.NativeAdCallToAction, NativeAdBase.NativeComponentTag.AdCallToAction);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }