15
15
#include " firebase/admob.h"
16
16
#include " firebase/admob/banner_view.h"
17
17
#include " firebase/admob/interstitial_ad.h"
18
+ #include " firebase/admob/native_express_ad_view.h"
18
19
#include " firebase/admob/rewarded_video.h"
19
20
#include " firebase/admob/types.h"
20
21
#include " firebase/app.h"
@@ -53,6 +54,27 @@ class LoggingInterstitialAdListener
53
54
}
54
55
};
55
56
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
+
56
78
// A simple listener that logs changes to rewarded video state.
57
79
class LoggingRewardedVideoListener
58
80
: public firebase::admob::rewarded_video::Listener {
@@ -79,17 +101,23 @@ const char* kAdMobAppID = "ca-app-pub-3940256099942544~1458002511";
79
101
#if defined(__ANDROID__)
80
102
const char * kBannerAdUnit = " ca-app-pub-3940256099942544/6300978111" ;
81
103
const char * kInterstitialAdUnit = " ca-app-pub-3940256099942544/1033173712" ;
104
+ const char * kNativeExpressAdUnit = " ca-app-pub-3940256099942544/1072772517" ;
82
105
const char * kRewardedVideoAdUnit = " YOUR_REWARDED_VIDEO_AD_UNIT_ID" ;
83
106
#else
84
107
const char * kBannerAdUnit = " ca-app-pub-3940256099942544/2934735716" ;
85
108
const char * kInterstitialAdUnit = " ca-app-pub-3940256099942544/4411468910" ;
109
+ const char * kNativeExpressAdUnit = " ca-app-pub-3940256099942544/2562852117" ;
86
110
const char * kRewardedVideoAdUnit = " YOUR_REWARDED_VIDEO_AD_UNIT_ID" ;
87
111
#endif
88
112
89
113
// Standard mobile banner size is 320x50.
90
114
static const int kBannerWidth = 320 ;
91
115
static const int kBannerHeight = 50 ;
92
116
117
+ // The native express ad's width and height.
118
+ static const int kNativeExpressAdWidth = 320 ;
119
+ static const int kNativeExpressAdHeight = 220 ;
120
+
93
121
// Sample keywords to use in making the request.
94
122
static const char * kKeywords [] = {" AdMob" , " C++" , " Fun" };
95
123
@@ -121,10 +149,9 @@ extern "C" int common_main(int argc, const char* argv[]) {
121
149
LogMessage (" Initializing the AdMob library." );
122
150
123
151
#if defined(__ANDROID__)
124
- app =
125
- firebase::App::Create (firebase::AppOptions (), GetJniEnv (), GetActivity ());
152
+ app = ::firebase::App::Create (GetJniEnv (), GetActivity ());
126
153
#else
127
- app = firebase::App::Create (firebase::AppOptions () );
154
+ app = :: firebase::App::Create ();
128
155
#endif // defined(__ANDROID__)
129
156
130
157
LogMessage (" Created the Firebase App %x." ,
@@ -174,33 +201,33 @@ extern "C" int common_main(int argc, const char* argv[]) {
174
201
request.test_device_ids = kTestDeviceIDs ;
175
202
176
203
// 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 ;
181
208
182
209
LogMessage (" Creating the BannerView." );
183
210
firebase::admob::BannerView* banner = new firebase::admob::BannerView ();
184
- banner->Initialize (GetWindowContext (), kBannerAdUnit , ad_size );
211
+ banner->Initialize (GetWindowContext (), kBannerAdUnit , banner_ad_size );
185
212
186
213
WaitForFutureCompletion (banner->InitializeLastResult ());
187
214
188
215
// Set the listener.
189
216
LoggingBannerViewListener banner_listener;
190
217
banner->SetListener (&banner_listener);
191
218
219
+ // Load the banner ad.
220
+ LogMessage (" Loading a banner ad." );
221
+ banner->LoadAd (request);
222
+
223
+ WaitForFutureCompletion (banner->LoadAdLastResult ());
224
+
192
225
// Make the BannerView visible.
193
226
LogMessage (" Showing the banner ad." );
194
227
banner->Show ();
195
228
196
229
WaitForFutureCompletion (banner->ShowLastResult ());
197
230
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
-
204
231
// Move to each of the six pre-defined positions.
205
232
LogMessage (" Moving the banner ad to top-center." );
206
233
banner->MoveTo (firebase::admob::BannerView::kPositionTop );
@@ -301,6 +328,110 @@ extern "C" int common_main(int argc, const char* argv[]) {
301
328
ProcessEvents (1000 );
302
329
}
303
330
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
+
304
435
// Start up rewarded video ads and associated mediation adapters.
305
436
LogMessage (" Initializing rewarded video." );
306
437
namespace rewarded_video = firebase::admob::rewarded_video;
@@ -355,6 +486,7 @@ extern "C" int common_main(int argc, const char* argv[]) {
355
486
356
487
delete banner;
357
488
delete interstitial;
489
+ delete native_express_ad;
358
490
rewarded_video::Destroy ();
359
491
firebase::admob::Terminate ();
360
492
delete app;
0 commit comments