1515#include " firebase/admob.h"
1616#include " firebase/admob/banner_view.h"
1717#include " firebase/admob/interstitial_ad.h"
18+ #include " firebase/admob/native_express_ad_view.h"
1819#include " firebase/admob/rewarded_video.h"
1920#include " firebase/admob/types.h"
2021#include " firebase/app.h"
@@ -53,6 +54,27 @@ class LoggingInterstitialAdListener
5354 }
5455};
5556
57+ // A simple listener that logs changes to a NativeExpressAdView.
58+ class LoggingNativeExpressAdViewListener
59+ : public firebase::admob::NativeExpressAdView::Listener {
60+ public:
61+ LoggingNativeExpressAdViewListener () {}
62+ void OnPresentationStateChanged (
63+ firebase::admob::NativeExpressAdView* native_express_ad_view,
64+ firebase::admob::NativeExpressAdView::PresentationState state) override {
65+ ::LogMessage (" NativeExpressAdView PresentationState has changed to %d." ,
66+ state);
67+ }
68+ void OnBoundingBoxChanged (
69+ firebase::admob::NativeExpressAdView* native_express_ad_view,
70+ firebase::admob::BoundingBox box) override {
71+ ::LogMessage (
72+ " NativeExpressAdView BoundingBox has changed to (x: %d, y: %d, width: "
73+ " %d, height %d)." ,
74+ box.x, box.y, box.width, box.height);
75+ }
76+ };
77+
5678// A simple listener that logs changes to rewarded video state.
5779class LoggingRewardedVideoListener
5880 : public firebase::admob::rewarded_video::Listener {
@@ -79,17 +101,23 @@ const char* kAdMobAppID = "ca-app-pub-3940256099942544~1458002511";
79101#if defined(__ANDROID__)
80102const char * kBannerAdUnit = " ca-app-pub-3940256099942544/6300978111" ;
81103const char * kInterstitialAdUnit = " ca-app-pub-3940256099942544/1033173712" ;
104+ const char * kNativeExpressAdUnit = " ca-app-pub-3940256099942544/1072772517" ;
82105const char * kRewardedVideoAdUnit = " YOUR_REWARDED_VIDEO_AD_UNIT_ID" ;
83106#else
84107const char * kBannerAdUnit = " ca-app-pub-3940256099942544/2934735716" ;
85108const char * kInterstitialAdUnit = " ca-app-pub-3940256099942544/4411468910" ;
109+ const char * kNativeExpressAdUnit = " ca-app-pub-3940256099942544/2562852117" ;
86110const char * kRewardedVideoAdUnit = " YOUR_REWARDED_VIDEO_AD_UNIT_ID" ;
87111#endif
88112
89113// Standard mobile banner size is 320x50.
90114static const int kBannerWidth = 320 ;
91115static const int kBannerHeight = 50 ;
92116
117+ // The native express ad's width and height.
118+ static const int kNativeExpressAdWidth = 320 ;
119+ static const int kNativeExpressAdHeight = 220 ;
120+
93121// Sample keywords to use in making the request.
94122static const char * kKeywords [] = {" AdMob" , " C++" , " Fun" };
95123
@@ -121,10 +149,9 @@ extern "C" int common_main(int argc, const char* argv[]) {
121149 LogMessage (" Initializing the AdMob library." );
122150
123151#if defined(__ANDROID__)
124- app =
125- firebase::App::Create (firebase::AppOptions (), GetJniEnv (), GetActivity ());
152+ app = ::firebase::App::Create (GetJniEnv (), GetActivity ());
126153#else
127- app = firebase::App::Create (firebase::AppOptions () );
154+ app = :: firebase::App::Create ();
128155#endif // defined(__ANDROID__)
129156
130157 LogMessage (" Created the Firebase App %x." ,
@@ -174,33 +201,33 @@ extern "C" int common_main(int argc, const char* argv[]) {
174201 request.test_device_ids = kTestDeviceIDs ;
175202
176203 // Create an ad size for the BannerView.
177- firebase::admob::AdSize ad_size ;
178- ad_size .ad_size_type = firebase::admob::kAdSizeStandard ;
179- ad_size .width = kBannerWidth ;
180- ad_size .height = kBannerHeight ;
204+ firebase::admob::AdSize banner_ad_size ;
205+ banner_ad_size .ad_size_type = firebase::admob::kAdSizeStandard ;
206+ banner_ad_size .width = kBannerWidth ;
207+ banner_ad_size .height = kBannerHeight ;
181208
182209 LogMessage (" Creating the BannerView." );
183210 firebase::admob::BannerView* banner = new firebase::admob::BannerView ();
184- banner->Initialize (GetWindowContext (), kBannerAdUnit , ad_size );
211+ banner->Initialize (GetWindowContext (), kBannerAdUnit , banner_ad_size );
185212
186213 WaitForFutureCompletion (banner->InitializeLastResult ());
187214
188215 // Set the listener.
189216 LoggingBannerViewListener banner_listener;
190217 banner->SetListener (&banner_listener);
191218
219+ // Load the banner ad.
220+ LogMessage (" Loading a banner ad." );
221+ banner->LoadAd (request);
222+
223+ WaitForFutureCompletion (banner->LoadAdLastResult ());
224+
192225 // Make the BannerView visible.
193226 LogMessage (" Showing the banner ad." );
194227 banner->Show ();
195228
196229 WaitForFutureCompletion (banner->ShowLastResult ());
197230
198- // When the BannerView is visible, load an ad into it.
199- LogMessage (" Loading a banner ad." );
200- banner->LoadAd (request);
201-
202- WaitForFutureCompletion (banner->LoadAdLastResult ());
203-
204231 // Move to each of the six pre-defined positions.
205232 LogMessage (" Moving the banner ad to top-center." );
206233 banner->MoveTo (firebase::admob::BannerView::kPositionTop );
@@ -301,6 +328,110 @@ extern "C" int common_main(int argc, const char* argv[]) {
301328 ProcessEvents (1000 );
302329 }
303330
331+ // Create an ad size for the NativeExpressAdView.
332+ firebase::admob::AdSize native_express_ad_size;
333+ native_express_ad_size.ad_size_type = firebase::admob::kAdSizeStandard ;
334+ native_express_ad_size.width = kNativeExpressAdWidth ;
335+ native_express_ad_size.height = kNativeExpressAdHeight ;
336+
337+ LogMessage (" Creating the NativeExpressAdView." );
338+ firebase::admob::NativeExpressAdView* native_express_ad =
339+ new firebase::admob::NativeExpressAdView ();
340+ native_express_ad->Initialize (GetWindowContext (), kNativeExpressAdUnit ,
341+ native_express_ad_size);
342+
343+ WaitForFutureCompletion (native_express_ad->InitializeLastResult ());
344+
345+ // Set the listener.
346+ LoggingNativeExpressAdViewListener native_express_ad_listener;
347+ native_express_ad->SetListener (&native_express_ad_listener);
348+
349+ // Load the native express ad.
350+ LogMessage (" Loading a native express ad." );
351+ native_express_ad->LoadAd (request);
352+
353+ WaitForFutureCompletion (native_express_ad->LoadAdLastResult ());
354+
355+ // Make the NativeExpressAdView visible.
356+ LogMessage (" Showing the native express ad." );
357+ native_express_ad->Show ();
358+
359+ WaitForFutureCompletion (native_express_ad->ShowLastResult ());
360+
361+ // Move to each of the six pre-defined positions.
362+ LogMessage (" Moving the native express ad to top-center." );
363+ native_express_ad->MoveTo (firebase::admob::NativeExpressAdView::kPositionTop );
364+
365+ WaitForFutureCompletion (native_express_ad->MoveToLastResult ());
366+
367+ LogMessage (" Moving the native express ad to top-left." );
368+ native_express_ad->MoveTo (
369+ firebase::admob::NativeExpressAdView::kPositionTopLeft );
370+
371+ WaitForFutureCompletion (native_express_ad->MoveToLastResult ());
372+
373+ LogMessage (" Moving the native express ad to top-right." );
374+ native_express_ad->MoveTo (
375+ firebase::admob::NativeExpressAdView::kPositionTopRight );
376+
377+ WaitForFutureCompletion (native_express_ad->MoveToLastResult ());
378+
379+ LogMessage (" Moving the native express ad to bottom-center." );
380+ native_express_ad->MoveTo (
381+ firebase::admob::NativeExpressAdView::kPositionBottom );
382+
383+ WaitForFutureCompletion (native_express_ad->MoveToLastResult ());
384+
385+ LogMessage (" Moving the native express ad to bottom-left." );
386+ native_express_ad->MoveTo (
387+ firebase::admob::NativeExpressAdView::kPositionBottomLeft );
388+
389+ WaitForFutureCompletion (native_express_ad->MoveToLastResult ());
390+
391+ LogMessage (" Moving the native express ad to bottom-right." );
392+ native_express_ad->MoveTo (
393+ firebase::admob::NativeExpressAdView::kPositionBottomRight );
394+
395+ WaitForFutureCompletion (native_express_ad->MoveToLastResult ());
396+
397+ // Try some coordinate moves.
398+ LogMessage (" Moving the native express ad to (100, 300)." );
399+ native_express_ad->MoveTo (100 , 300 );
400+
401+ WaitForFutureCompletion (native_express_ad->MoveToLastResult ());
402+
403+ LogMessage (" Moving the native express ad to (100, 400)." );
404+ native_express_ad->MoveTo (100 , 400 );
405+
406+ WaitForFutureCompletion (native_express_ad->MoveToLastResult ());
407+
408+ // Try hiding and showing the NativeExpressAdView.
409+ LogMessage (" Hiding the native express ad." );
410+ native_express_ad->Hide ();
411+
412+ WaitForFutureCompletion (native_express_ad->HideLastResult ());
413+
414+ LogMessage (" Showing the native express ad." );
415+ native_express_ad->Show ();
416+
417+ WaitForFutureCompletion (native_express_ad->ShowLastResult ());
418+
419+ // A few last moves after showing it again.
420+ LogMessage (" Moving the native express ad to (100, 300)." );
421+ native_express_ad->MoveTo (100 , 300 );
422+
423+ WaitForFutureCompletion (native_express_ad->MoveToLastResult ());
424+
425+ LogMessage (" Moving the native express ad to (100, 400)." );
426+ native_express_ad->MoveTo (100 , 400 );
427+
428+ WaitForFutureCompletion (native_express_ad->MoveToLastResult ());
429+
430+ LogMessage (" Hiding the native express ad now that we're done with it." );
431+ native_express_ad->Hide ();
432+
433+ WaitForFutureCompletion (native_express_ad->HideLastResult ());
434+
304435 // Start up rewarded video ads and associated mediation adapters.
305436 LogMessage (" Initializing rewarded video." );
306437 namespace rewarded_video = firebase::admob::rewarded_video;
@@ -355,6 +486,7 @@ extern "C" int common_main(int argc, const char* argv[]) {
355486
356487 delete banner;
357488 delete interstitial;
489+ delete native_express_ad;
358490 rewarded_video::Destroy ();
359491 firebase::admob::Terminate ();
360492 delete app;
0 commit comments