@@ -28,12 +28,11 @@ class LoggingBannerViewListener : public firebase::admob::BannerView::Listener {
2828 LoggingBannerViewListener () {}
2929 void OnPresentationStateChanged (
3030 firebase::admob::BannerView* banner_view,
31- firebase::admob::BannerView::PresentationState new_state) {
31+ firebase::admob::BannerView::PresentationState new_state) override {
3232 ::LogMessage (" BannerView PresentationState has changed to %d." , new_state);
3333 }
34-
3534 void OnBoundingBoxChanged (firebase::admob::BannerView* banner_view,
36- firebase::admob::BoundingBox new_box) {
35+ firebase::admob::BoundingBox new_box) override {
3736 ::LogMessage (
3837 " BannerView BoundingBox has changed to (x: %d, y: %d, width: %d, "
3938 " height %d)." ,
@@ -48,7 +47,7 @@ class LoggingInterstitialAdListener
4847 LoggingInterstitialAdListener () {}
4948 void OnPresentationStateChanged (
5049 firebase::admob::InterstitialAd* interstitial_ad,
51- firebase::admob::InterstitialAd::PresentationState new_state) {
50+ firebase::admob::InterstitialAd::PresentationState new_state) override {
5251 ::LogMessage (" InterstitialAd PresentationState has changed to %d." ,
5352 new_state);
5453 }
@@ -81,44 +80,36 @@ static const int kBirthdayYear = 1976;
8180
8281static void WaitForFutureCompletion (firebase::FutureBase future) {
8382 while (!ProcessEvents (1000 )) {
84- if (future.Status () != :: firebase::kFutureStatusPending ) {
83+ if (future.Status () != firebase::kFutureStatusPending ) {
8584 break ;
8685 }
8786 }
8887
89- if (future.Error () != :: firebase::admob::kAdMobErrorNone ) {
88+ if (future.Error () != firebase::admob::kAdMobErrorNone ) {
9089 LogMessage (" Action failed with error code %d and message \" %s\" ." ,
9190 future.Error (), future.ErrorMessage ());
9291 }
9392}
9493
9594// Execute all methods of the C++ admob API.
9695extern " C" int common_main (int argc, const char * argv[]) {
97- namespace admob = ::firebase::admob;
98- ::firebase::App* app;
96+ firebase::App* app;
9997 LogMessage (" Initializing the AdMob library." );
100- do {
98+
10199#if defined(__ANDROID__)
102- app = :: firebase::App::Create (:: firebase::AppOptions (), GetJniEnv (),
103- GetActivity ());
100+ app =
101+ firebase::App::Create ( firebase::AppOptions (), GetJniEnv (), GetActivity ());
104102#else
105- app = :: firebase::App::Create (:: firebase::AppOptions ());
103+ app = firebase::App::Create (firebase::AppOptions ());
106104#endif // defined(__ANDROID__)
107105
108- if (app == nullptr ) {
109- LogMessage (" Couldn't create firebase app, try again." );
110- // Wait a few moments, and try to create app again.
111- ProcessEvents (1000 );
112- }
113- } while (app == nullptr );
114-
115106 LogMessage (" Created the Firebase App %x." ,
116107 static_cast <int >(reinterpret_cast <intptr_t >(app)));
117108
118109 LogMessage (" Initializing the AdMob with Firebase API." );
119- admob::Initialize (*app);
110+ firebase:: admob::Initialize (*app);
120111
121- :: firebase::admob::AdRequest request;
112+ firebase::admob::AdRequest request;
122113 // If the app is aware of the user's gender, it can be added to the targeting
123114 // information. Otherwise, "unknown" should be used.
124115 request.gender = firebase::admob::kGenderUnknown ;
@@ -141,7 +132,7 @@ extern "C" int common_main(int argc, const char* argv[]) {
141132
142133 // "Extra" key value pairs can be added to the request as well. Typically
143134 // these are used when testing new features.
144- static const :: firebase::admob::KeyValuePair kRequestExtras [] = {
135+ static const firebase::admob::KeyValuePair kRequestExtras [] = {
145136 {" the_name_of_an_extra" , " the_value_for_that_extra" }};
146137 request.extras_count = sizeof (kRequestExtras ) / sizeof (kRequestExtras [0 ]);
147138 request.extras = kRequestExtras ;
@@ -155,18 +146,18 @@ extern "C" int common_main(int argc, const char* argv[]) {
155146 // Device IDs can be obtained by checking the logcat or the Xcode log while
156147 // debugging. They appear as a long string of hex characters.
157148 request.test_device_id_count =
158- sizeof (kTestDeviceIDs ) / sizeof (kTestDeviceIDs );
149+ sizeof (kTestDeviceIDs ) / sizeof (kTestDeviceIDs [ 0 ] );
159150 request.test_device_ids = kTestDeviceIDs ;
160151
161152 // Create an ad size for the BannerView.
162- admob::AdSize ad_size;
163- ad_size.ad_size_type = admob::kAdSizeStandard ;
153+ firebase:: admob::AdSize ad_size;
154+ ad_size.ad_size_type = firebase:: admob::kAdSizeStandard ;
164155 ad_size.width = kBannerWidth ;
165156 ad_size.height = kBannerHeight ;
166157
167158 LogMessage (" Creating the BannerView." );
168159 LoggingBannerViewListener banner_listener;
169- :: firebase::admob::BannerView* banner = new admob::BannerView ();
160+ firebase::admob::BannerView* banner = new firebase:: admob::BannerView ();
170161 banner->SetListener (&banner_listener);
171162 banner->Initialize (GetWindowContext (), kBannerAdUnit , ad_size);
172163
@@ -186,32 +177,32 @@ extern "C" int common_main(int argc, const char* argv[]) {
186177
187178 // Move to each of the six pre-defined positions.
188179 LogMessage (" Moving the banner ad to top-center." );
189- banner->MoveTo (admob::BannerView::kPositionTop );
180+ banner->MoveTo (firebase:: admob::BannerView::kPositionTop );
190181
191182 WaitForFutureCompletion (banner->MoveToLastResult ());
192183
193184 LogMessage (" Moving the banner ad to top-left." );
194- banner->MoveTo (admob::BannerView::kPositionTopLeft );
185+ banner->MoveTo (firebase:: admob::BannerView::kPositionTopLeft );
195186
196187 WaitForFutureCompletion (banner->MoveToLastResult ());
197188
198189 LogMessage (" Moving the banner ad to top-right." );
199- banner->MoveTo (admob::BannerView::kPositionTopRight );
190+ banner->MoveTo (firebase:: admob::BannerView::kPositionTopRight );
200191
201192 WaitForFutureCompletion (banner->MoveToLastResult ());
202193
203194 LogMessage (" Moving the banner ad to bottom-center." );
204- banner->MoveTo (admob::BannerView::kPositionBottom );
195+ banner->MoveTo (firebase:: admob::BannerView::kPositionBottom );
205196
206197 WaitForFutureCompletion (banner->MoveToLastResult ());
207198
208199 LogMessage (" Moving the banner ad to bottom-left." );
209- banner->MoveTo (admob::BannerView::kPositionBottomLeft );
200+ banner->MoveTo (firebase:: admob::BannerView::kPositionBottomLeft );
210201
211202 WaitForFutureCompletion (banner->MoveToLastResult ());
212203
213204 LogMessage (" Moving the banner ad to bottom-right." );
214- banner->MoveTo (admob::BannerView::kPositionBottomRight );
205+ banner->MoveTo (firebase:: admob::BannerView::kPositionBottomRight );
215206
216207 WaitForFutureCompletion (banner->MoveToLastResult ());
217208
@@ -248,10 +239,16 @@ extern "C" int common_main(int argc, const char* argv[]) {
248239
249240 WaitForFutureCompletion (banner->MoveToLastResult ());
250241
242+ LogMessage (" Hiding the banner ad now that we're done with it." );
243+ banner->Hide ();
244+
245+ WaitForFutureCompletion (banner->HideLastResult ());
246+
251247 // Create and test InterstitialAd.
252248 LogMessage (" Creating the InterstitialAd." );
253249 LoggingInterstitialAdListener interstitial_listener;
254- ::firebase::admob::InterstitialAd* interstitial = new admob::InterstitialAd ();
250+ firebase::admob::InterstitialAd* interstitial =
251+ new firebase::admob::InterstitialAd ();
255252 interstitial->SetListener (&interstitial_listener);
256253 interstitial->Initialize (GetWindowContext (), kInterstitialAdUnit );
257254
@@ -267,13 +264,24 @@ extern "C" int common_main(int argc, const char* argv[]) {
267264 LogMessage (" Showing the interstitial ad." );
268265 interstitial->Show ();
269266
267+ WaitForFutureCompletion (interstitial->ShowLastResult ());
268+
269+ // Wait for the user to close the interstitial.
270+ while (interstitial->GetPresentationState () !=
271+ firebase::admob::InterstitialAd::PresentationState::
272+ kPresentationStateHidden ) {
273+ ProcessEvents (1000 );
274+ }
275+
276+ LogMessage (" Done!" );
277+
270278 // Wait until the user kills the app.
271279 while (!ProcessEvents (1000 )) {
272280 }
273281
274- delete interstitial;
275282 delete banner;
276- admob::Terminate ();
283+ delete interstitial;
284+ firebase::admob::Terminate ();
277285 delete app;
278286
279287 return 0 ;
0 commit comments