Skip to content

Commit b9133b3

Browse files
committed
Integrate Latest @ 133875437
Changes to all: - Update Firebase C++ samples to use Firebase version 9.6.0 on Android. - Use ModuleInitializer to initialize Firebase C++ modules which require Play services. Changes to admob/testapp ... - Add publisher-provided AdMob App ID to Initialize call. - Add Rewarded Video to the AdMob C++ testapp. Changes to auth/testapp ... - Suppress error on Delete() in invalid case. - Add sample code for email verification functions. Changes to invites/testapp ... - Modify Firebase Invites C++ sample to support iOS 10. Changes to messaging/testapp ... - Add sample code for retrieving the notification payload. Changes to remote_config/testapp ... - Add sample code for GetKeysByPrefix. CL: 133875437
1 parent db3e949 commit b9133b3

File tree

18 files changed

+247
-188
lines changed

18 files changed

+247
-188
lines changed

admob/testapp/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ android {
8989

9090
dependencies {
9191
compile fileTree(dir: 'libs', include: ['*.jar'])
92-
compile 'com.google.firebase:firebase-ads:9.4.0'
93-
compile 'com.google.android.gms:play-services-base:9.4.0'
92+
compile 'com.google.firebase:firebase-ads:9.6.0'
93+
compile 'com.google.android.gms:play-services-base:9.6.0'
9494
}
9595

9696
apply plugin: 'com.google.gms.google-services'

admob/testapp/readme.md

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ Getting Started
5959
dismiss the interstitial ad to see the banner ad. The output of the app can
6060
be viewed via the console. To view the conscole in Xcode, select
6161
"View --> Debug Area --> Activate Console" from the menu.
62+
- For Rewarded Video, you must supply your own ad unit. Learn more in the
63+
[Rewarded Video C++ guide](http://firebase.google.com/docs/admob/cpp/rewarded-video).
6264
6365
### Android
6466
- Register your Android app with Firebase.
@@ -110,6 +112,8 @@ Getting Started
110112
- While this is happening, information from the device log will be written
111113
to an onscreen TextView.
112114
- Logcat can also be used as normal.
115+
- For Rewarded Video, you must supply your own ad unit. Learn more in the
116+
[Rewarded Video C++ guide](http://firebase.google.com/docs/admob/cpp/rewarded-video).
113117
114118
Support
115119
-------

admob/testapp/src/common_main.cc

+88-13
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "firebase/admob.h"
1616
#include "firebase/admob/banner_view.h"
1717
#include "firebase/admob/interstitial_ad.h"
18+
#include "firebase/admob/rewarded_video.h"
1819
#include "firebase/admob/types.h"
1920
#include "firebase/app.h"
2021
#include "firebase/future.h"
@@ -28,15 +29,15 @@ class LoggingBannerViewListener : public firebase::admob::BannerView::Listener {
2829
LoggingBannerViewListener() {}
2930
void OnPresentationStateChanged(
3031
firebase::admob::BannerView* banner_view,
31-
firebase::admob::BannerView::PresentationState new_state) override {
32-
::LogMessage("BannerView PresentationState has changed to %d.", new_state);
32+
firebase::admob::BannerView::PresentationState state) override {
33+
::LogMessage("BannerView PresentationState has changed to %d.", state);
3334
}
3435
void OnBoundingBoxChanged(firebase::admob::BannerView* banner_view,
35-
firebase::admob::BoundingBox new_box) override {
36+
firebase::admob::BoundingBox box) override {
3637
::LogMessage(
3738
"BannerView BoundingBox has changed to (x: %d, y: %d, width: %d, "
3839
"height %d).",
39-
new_box.x, new_box.y, new_box.width, new_box.height);
40+
box.x, box.y, box.width, box.height);
4041
}
4142
};
4243

@@ -47,19 +48,42 @@ class LoggingInterstitialAdListener
4748
LoggingInterstitialAdListener() {}
4849
void OnPresentationStateChanged(
4950
firebase::admob::InterstitialAd* interstitial_ad,
50-
firebase::admob::InterstitialAd::PresentationState new_state) override {
51-
::LogMessage("InterstitialAd PresentationState has changed to %d.",
52-
new_state);
51+
firebase::admob::InterstitialAd::PresentationState state) override {
52+
::LogMessage("InterstitialAd PresentationState has changed to %d.", state);
5353
}
5454
};
5555

56+
// A simple listener that logs changes to rewarded video state.
57+
class LoggingRewardedVideoListener
58+
: public firebase::admob::rewarded_video::Listener {
59+
public:
60+
LoggingRewardedVideoListener() {}
61+
void OnRewarded(firebase::admob::rewarded_video::RewardItem reward) override {
62+
::LogMessage("Rewarding user with %f %s.", reward.amount,
63+
reward.reward_type.c_str());
64+
}
65+
void OnPresentationStateChanged(
66+
firebase::admob::rewarded_video::PresentationState state) override {
67+
::LogMessage("Rewarded video PresentationState has changed to %d.", state);
68+
}
69+
};
70+
71+
// The AdMob app IDs for the test app.
72+
#if defined(__ANDROID__)
73+
const char* kAdMobAppID = "ca-app-pub-3940256099942544~3347511713";
74+
#else
75+
const char* kAdMobAppID = "ca-app-pub-3940256099942544~1458002511";
76+
#endif
77+
5678
// These ad units are configured to always serve test ads.
5779
#if defined(__ANDROID__)
5880
const char* kBannerAdUnit = "ca-app-pub-3940256099942544/6300978111";
5981
const char* kInterstitialAdUnit = "ca-app-pub-3940256099942544/1033173712";
82+
const char* kRewardedVideoAdUnit = "YOUR_REWARDED_VIDEO_AD_UNIT_ID";
6083
#else
6184
const char* kBannerAdUnit = "ca-app-pub-3940256099942544/2934735716";
6285
const char* kInterstitialAdUnit = "ca-app-pub-3940256099942544/4411468910";
86+
const char* kRewardedVideoAdUnit = "YOUR_REWARDED_VIDEO_AD_UNIT_ID";
6387
#endif
6488

6589
// Standard mobile banner size is 320x50.
@@ -86,7 +110,7 @@ static void WaitForFutureCompletion(firebase::FutureBase future) {
86110
}
87111

88112
if (future.Error() != firebase::admob::kAdMobErrorNone) {
89-
LogMessage("Action failed with error code %d and message \"%s\".",
113+
LogMessage("ERROR: Action failed with error code %d and message \"%s\".",
90114
future.Error(), future.ErrorMessage());
91115
}
92116
}
@@ -107,7 +131,7 @@ extern "C" int common_main(int argc, const char* argv[]) {
107131
static_cast<int>(reinterpret_cast<intptr_t>(app)));
108132

109133
LogMessage("Initializing the AdMob with Firebase API.");
110-
firebase::admob::Initialize(*app);
134+
firebase::admob::Initialize(*app, kAdMobAppID);
111135

112136
firebase::admob::AdRequest request;
113137
// If the app is aware of the user's gender, it can be added to the targeting
@@ -156,13 +180,15 @@ extern "C" int common_main(int argc, const char* argv[]) {
156180
ad_size.height = kBannerHeight;
157181

158182
LogMessage("Creating the BannerView.");
159-
LoggingBannerViewListener banner_listener;
160183
firebase::admob::BannerView* banner = new firebase::admob::BannerView();
161-
banner->SetListener(&banner_listener);
162184
banner->Initialize(GetWindowContext(), kBannerAdUnit, ad_size);
163185

164186
WaitForFutureCompletion(banner->InitializeLastResult());
165187

188+
// Set the listener.
189+
LoggingBannerViewListener banner_listener;
190+
banner->SetListener(&banner_listener);
191+
166192
// Make the BannerView visible.
167193
LogMessage("Showing the banner ad.");
168194
banner->Show();
@@ -246,14 +272,16 @@ extern "C" int common_main(int argc, const char* argv[]) {
246272

247273
// Create and test InterstitialAd.
248274
LogMessage("Creating the InterstitialAd.");
249-
LoggingInterstitialAdListener interstitial_listener;
250275
firebase::admob::InterstitialAd* interstitial =
251276
new firebase::admob::InterstitialAd();
252-
interstitial->SetListener(&interstitial_listener);
253277
interstitial->Initialize(GetWindowContext(), kInterstitialAdUnit);
254278

255279
WaitForFutureCompletion(interstitial->InitializeLastResult());
256280

281+
// Set the listener.
282+
LoggingInterstitialAdListener interstitial_listener;
283+
interstitial->SetListener(&interstitial_listener);
284+
257285
// When the InterstitialAd is initialized, load an ad.
258286
LogMessage("Loading an interstitial ad.");
259287
interstitial->LoadAd(request);
@@ -273,6 +301,52 @@ extern "C" int common_main(int argc, const char* argv[]) {
273301
ProcessEvents(1000);
274302
}
275303

304+
// Start up rewarded video ads and associated mediation adapters.
305+
LogMessage("Initializing rewarded video.");
306+
namespace rewarded_video = firebase::admob::rewarded_video;
307+
rewarded_video::Initialize();
308+
309+
WaitForFutureCompletion(rewarded_video::InitializeLastResult());
310+
311+
LogMessage("Setting rewarded video listener.");
312+
LoggingRewardedVideoListener rewarded_listener;
313+
rewarded_video::SetListener(&rewarded_listener);
314+
315+
LogMessage("Loading a rewarded video ad.");
316+
rewarded_video::LoadAd(kRewardedVideoAdUnit, request);
317+
318+
WaitForFutureCompletion(rewarded_video::LoadAdLastResult());
319+
320+
// If an ad has loaded, show it. If the user watches all the way through, the
321+
// LoggingRewardedVideoListener will log a reward!
322+
if (rewarded_video::LoadAdLastResult().Error() ==
323+
firebase::admob::kAdMobErrorNone) {
324+
LogMessage("Showing a rewarded video ad.");
325+
rewarded_video::Show(GetWindowContext());
326+
327+
WaitForFutureCompletion(rewarded_video::ShowLastResult());
328+
329+
// Normally Pause and Resume would be called in response to the app pausing
330+
// or losing focus. This is just a test.
331+
LogMessage("Pausing.");
332+
rewarded_video::Pause();
333+
334+
WaitForFutureCompletion(rewarded_video::PauseLastResult());
335+
336+
LogMessage("Resuming.");
337+
rewarded_video::Resume();
338+
339+
WaitForFutureCompletion(rewarded_video::ResumeLastResult());
340+
} else {
341+
// Rewarded Video returned an error. This might be because the
342+
// developer did not put their Rewarded Video ad unit into
343+
// kRewardedVideoAdUnit above.
344+
LogMessage("WARNING: Is your Rewarded Video ad unit ID correct?");
345+
LogMessage(
346+
"Ensure kRewardedVideoAdUnit is set to your own Rewarded Video ad unit "
347+
"ID in src/common_main.cc.");
348+
}
349+
276350
LogMessage("Done!");
277351

278352
// Wait until the user kills the app.
@@ -281,6 +355,7 @@ extern "C" int common_main(int argc, const char* argv[]) {
281355

282356
delete banner;
283357
delete interstitial;
358+
rewarded_video::Destroy();
284359
firebase::admob::Terminate();
285360
delete app;
286361

analytics/testapp/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ android {
9090

9191
dependencies {
9292
compile fileTree(dir: 'libs', include: ['*.jar'])
93-
compile 'com.google.firebase:firebase-analytics:9.4.0'
94-
compile 'com.google.android.gms:play-services-base:9.4.0'
93+
compile 'com.google.firebase:firebase-analytics:9.6.0'
94+
compile 'com.google.android.gms:play-services-base:9.6.0'
9595
}
9696

9797
apply plugin: 'com.google.gms.google-services'

analytics/testapp/src/android/java/com/google/firebase/example/LoggingUtils.java

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public static void initLogWindow(Activity activity) {
3333
LinearLayout linearLayout = new LinearLayout(activity);
3434
ScrollView scrollView = new ScrollView(activity);
3535
TextView textView = new TextView(activity);
36+
textView.setTag("Logger");
3637
linearLayout.addView(scrollView);
3738
scrollView.addView(textView);
3839
Window window = activity.getWindow();

analytics/testapp/src/ios/ios_main.mm

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ - (BOOL)application:(UIApplication*)application
101101

102102
g_text_view = [[UITextView alloc] initWithFrame:viewController.view.bounds];
103103

104+
g_text_view.accessibilityIdentifier = @"Logger";
104105
g_text_view.editable = NO;
105106
g_text_view.scrollEnabled = YES;
106107
g_text_view.userInteractionEnabled = YES;

auth/testapp/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ android {
9090

9191
dependencies {
9292
compile fileTree(dir: 'libs', include: ['*.jar'])
93-
compile 'com.google.firebase:firebase-auth:9.4.0'
94-
compile 'com.google.android.gms:play-services-base:9.4.0'
93+
compile 'com.google.firebase:firebase-auth:9.6.0'
94+
compile 'com.google.android.gms:play-services-base:9.6.0'
9595
}
9696

9797
apply plugin: 'com.google.gms.google-services'

auth/testapp/src/android/java/com/google/firebase/example/LoggingUtils.java

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public static void initLogWindow(Activity activity) {
3333
LinearLayout linearLayout = new LinearLayout(activity);
3434
ScrollView scrollView = new ScrollView(activity);
3535
TextView textView = new TextView(activity);
36+
textView.setTag("Logger");
3637
linearLayout.addView(scrollView);
3738
scrollView.addView(textView);
3839
Window window = activity.getWindow();

0 commit comments

Comments
 (0)