コード例 #1
0
        /// <summary>
        /// Register and populate a native ad material view.
        /// </summary>
        /// <param name="globalNativeAd"></param>
        /// <param name="nativeView"></param>
        private void InitNativeView(NativeAd nativeAd, INativeView nativeView)
        {
            View mNativeView = (View)nativeView;

            // Register a native ad material view.
            nativeView.TitleView        = mNativeView.FindViewById(Resource.Id.ad_title);
            nativeView.MediaView        = (MediaView)mNativeView.FindViewById(Resource.Id.ad_media);
            nativeView.AdSourceView     = mNativeView.FindViewById(Resource.Id.ad_source);
            nativeView.CallToActionView = mNativeView.FindViewById(Resource.Id.ad_call_to_action);

            // Populate a native ad material view.
            ((TextView)nativeView.TitleView).Text = nativeAd.Title;

            nativeView.MediaView.SetMediaContent(nativeAd.MediaContent);

            if (nativeAd.AdSource != null)
            {
                ((TextView)nativeView.AdSourceView).Text = nativeAd.AdSource;
                Log.Info(TAG, "AdSource: " + nativeAd.AdSource);
            }
            nativeView.AdSourceView.Visibility = (nativeAd.AdSource != null ? ViewStates.Visible : ViewStates.Invisible);

            if (nativeAd.CallToAction != null)
            {
                ((Button)nativeView.CallToActionView).Text = nativeAd.CallToAction;
                Log.Info(TAG, "CallToAction: " + nativeAd.CallToAction);
            }
            nativeView.CallToActionView.Visibility = (nativeAd.CallToAction != null ? ViewStates.Visible : ViewStates.Invisible);

            // Obtain a video controller
            IVideoOperator videoOperator = nativeAd.VideoOperator;

            Log.Info(TAG, "VideoOperator: " + nativeAd.VideoOperator);
            // Check whether a native ad contains video materials.
            if (videoOperator.HasVideo)
            {
                // Add a video lifecycle event listener.
                videoOperator.VideoLifecycleListener = new VideoOperatorListener(this);
            }

            // Register a native ad object.
            nativeView.SetNativeAd(nativeAd);
            Log.Info(TAG, "NativeView.SetNativeAd called successfully");
        }
コード例 #2
0
        /// <summary>
        /// Display native ad.
        /// </summary>
        /// <param name="nativeAd"></param>
        private void ShowNativeAd(NativeAd nativeAd)
        {
            // Destroy the original native ad.
            if (globalNativeAd != null)
            {
                globalNativeAd.Destroy();
            }
            globalNativeAd = nativeAd;

            // Obtain NativeView
            INativeView nativeView = (INativeView)LayoutInflater.Inflate(layoutId, null);

            // Register and populate a native ad material view.
            InitNativeView(globalNativeAd, nativeView);

            // Add NativeView to the app UI.

            adScrollView.RemoveAllViews();
            adScrollView.AddView((View)nativeView);
        }
コード例 #3
0
 void ISetView.SetView(INativeView v)
 {
     myView = v;
 }