Skip to content

Commit f18d9c1

Browse files
author
Stewart Miles
committed
Integrate Latest @ 158159565
- Update all build.gradle Firebase dependencies to 11.0.0. - Added phone auth to auth sample. - Added dynamic links sample. - Updated invites readme with additional required setup steps for the latest SDK release. CL: 158159565
1 parent 74f6038 commit f18d9c1

File tree

42 files changed

+2636
-37
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2636
-37
lines changed

admob/testapp/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ android {
8888
}
8989

9090
dependencies {
91-
compile 'com.google.firebase:firebase-ads:10.2.0'
92-
compile 'com.google.android.gms:play-services-base:10.2.0'
91+
compile 'com.google.firebase:firebase-ads:11.0.0'
92+
compile 'com.google.android.gms:play-services-base:11.0.0'
9393
}
9494

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

analytics/testapp/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ android {
8989
}
9090

9191
dependencies {
92-
compile 'com.google.firebase:firebase-analytics:10.2.0'
93-
compile 'com.google.android.gms:play-services-base:10.2.0'
92+
compile 'com.google.firebase:firebase-analytics:11.0.0'
93+
compile 'com.google.android.gms:play-services-base:11.0.0'
9494
}
9595

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

auth/testapp/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ android {
8989
}
9090

9191
dependencies {
92-
compile 'com.google.firebase:firebase-auth:10.2.0'
93-
compile 'com.google.android.gms:play-services-base:10.2.0'
92+
compile 'com.google.firebase:firebase-auth:11.0.0'
93+
compile 'com.google.android.gms:play-services-base:11.0.0'
9494
}
9595

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

auth/testapp/proguard.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
-keep,includedescriptorclasses public class com.google.firebase.example.LoggingUtils { *; }
2+
-keep,includedescriptorclasses public class com.google.firebase.example.TextEntryField { *; }

auth/testapp/src/android/android_main.cc

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,85 @@ class LoggingUtilsData {
148148

149149
LoggingUtilsData* g_logging_utils_data;
150150

151+
// Vars that we need available for reading text from the user.
152+
class TextEntryFieldData {
153+
public:
154+
TextEntryFieldData()
155+
: text_entry_field_class_(nullptr), text_entry_field_read_text_(0) {}
156+
157+
~TextEntryFieldData() {
158+
JNIEnv* env = GetJniEnv();
159+
assert(env);
160+
if (text_entry_field_class_) {
161+
env->DeleteGlobalRef(text_entry_field_class_);
162+
}
163+
}
164+
165+
void Init() {
166+
JNIEnv* env = GetJniEnv();
167+
assert(env);
168+
169+
jclass text_entry_field_class = FindClass(
170+
env, GetActivity(), "com/google/firebase/example/TextEntryField");
171+
assert(text_entry_field_class != 0);
172+
173+
// Need to store as global references so it don't get moved during garbage
174+
// collection.
175+
text_entry_field_class_ =
176+
static_cast<jclass>(env->NewGlobalRef(text_entry_field_class));
177+
env->DeleteLocalRef(text_entry_field_class);
178+
179+
static const JNINativeMethod kNativeMethods[] = {
180+
{"nativeSleep", "(I)Z", reinterpret_cast<void*>(ProcessEvents)}};
181+
env->RegisterNatives(text_entry_field_class_, kNativeMethods,
182+
sizeof(kNativeMethods) / sizeof(kNativeMethods[0]));
183+
text_entry_field_read_text_ = env->GetStaticMethodID(
184+
text_entry_field_class_, "readText",
185+
"(Landroid/app/Activity;Ljava/lang/String;Ljava/lang/String;"
186+
"Ljava/lang/String;)Ljava/lang/String;");
187+
}
188+
189+
// Call TextEntryField.readText(), which shows a text entry dialog and spins
190+
// until the user enters some text (or cancels). If the user cancels, returns
191+
// an empty string.
192+
std::string ReadText(const char* title, const char* message,
193+
const char* placeholder) {
194+
if (text_entry_field_class_ == 0) return ""; // haven't been initted yet
195+
JNIEnv* env = GetJniEnv();
196+
assert(env);
197+
jstring title_string = env->NewStringUTF(title);
198+
jstring message_string = env->NewStringUTF(message);
199+
jstring placeholder_string = env->NewStringUTF(placeholder);
200+
jobject result_string = env->CallStaticObjectMethod(
201+
text_entry_field_class_, text_entry_field_read_text_, GetActivity(),
202+
title_string, message_string, placeholder_string);
203+
env->DeleteLocalRef(title_string);
204+
env->DeleteLocalRef(message_string);
205+
env->DeleteLocalRef(placeholder_string);
206+
if (env->ExceptionCheck()) {
207+
env->ExceptionDescribe();
208+
env->ExceptionClear();
209+
}
210+
if (result_string == nullptr) {
211+
// Check if readText() returned null, which will be the case if an
212+
// exception occurred or if TextEntryField returned null for some reason.
213+
return "";
214+
}
215+
const char* result_buffer =
216+
env->GetStringUTFChars(static_cast<jstring>(result_string), 0);
217+
std::string result(result_buffer);
218+
env->ReleaseStringUTFChars(static_cast<jstring>(result_string),
219+
result_buffer);
220+
return result;
221+
}
222+
223+
private:
224+
jclass text_entry_field_class_;
225+
jmethodID text_entry_field_read_text_;
226+
};
227+
228+
TextEntryFieldData* g_text_entry_field_data;
229+
151230
// Checks if a JNI exception has happened, and if so, logs it to the console.
152231
void CheckJNIException() {
153232
JNIEnv* env = GetJniEnv();
@@ -208,6 +287,15 @@ JNIEnv* GetJniEnv() {
208287
return result == JNI_OK ? env : nullptr;
209288
}
210289

290+
// Use a Java class, TextEntryField, to prompt the user to enter some text.
291+
// This function blocks until text was entered or the dialog was canceled.
292+
// If the user cancels, returns an empty string.
293+
std::string ReadTextInput(const char* title, const char* message,
294+
const char* placeholder) {
295+
assert(g_text_entry_field_data);
296+
return g_text_entry_field_data->ReadText(title, message, placeholder);
297+
}
298+
211299
// Execute common_main(), flush pending events and finish the activity.
212300
extern "C" void android_main(struct android_app* state) {
213301
// native_app_glue spawns a new thread, calling android_main() when the
@@ -235,6 +323,10 @@ extern "C" void android_main(struct android_app* state) {
235323
g_logging_utils_data = new LoggingUtilsData();
236324
g_logging_utils_data->Init();
237325

326+
// Create the text entry dialog.
327+
g_text_entry_field_data = new TextEntryFieldData();
328+
g_text_entry_field_data->Init();
329+
238330
// Execute cross platform entry point.
239331
static const char* argv[] = {FIREBASE_TESTAPP_NAME};
240332
int return_value = common_main(1, argv);
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// Copyright 2016 Google Inc. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.firebase.example;
16+
17+
import android.app.Activity;
18+
import android.app.AlertDialog;
19+
import android.content.DialogInterface;
20+
import android.widget.EditText;
21+
22+
/**
23+
* A utility class, with a method to prompt the user to enter a line of text, and a native method to
24+
* sleep for a given number of milliseconds.
25+
*/
26+
public class TextEntryField {
27+
private static Object lock = new Object();
28+
private static String resultText = null;
29+
30+
/**
31+
* Prompt the user with a text field, blocking until the user fills it out, then returns the text
32+
* they entered. If the user cancels, returns an empty string.
33+
*/
34+
public static String readText(
35+
Activity activity, String title, String message, String placeholder) {
36+
resultText = null;
37+
// Show the alert dialog on the main thread.
38+
activity.runOnUiThread(
39+
new Runnable() {
40+
@Override
41+
public void run() {
42+
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(activity);
43+
alertBuilder.setTitle(title);
44+
alertBuilder.setMessage(message);
45+
46+
// Set up and add the text field.
47+
final EditText textField = new EditText(activity);
48+
textField.setHint(placeholder);
49+
alertBuilder.setView(textField);
50+
51+
alertBuilder.setPositiveButton(
52+
"OK",
53+
new DialogInterface.OnClickListener() {
54+
@Override
55+
public void onClick(DialogInterface dialog, int whichButton) {
56+
synchronized (lock) {
57+
resultText = textField.getText().toString();
58+
}
59+
}
60+
});
61+
62+
alertBuilder.setNegativeButton(
63+
"Cancel",
64+
new DialogInterface.OnClickListener() {
65+
@Override
66+
public void onClick(DialogInterface dialog, int whichButton) {
67+
synchronized (lock) {
68+
resultText = "";
69+
}
70+
}
71+
});
72+
73+
alertBuilder.setOnCancelListener(
74+
new DialogInterface.OnCancelListener() {
75+
@Override
76+
public void onCancel(DialogInterface dialog) {
77+
synchronized (lock) {
78+
resultText = "";
79+
}
80+
}
81+
});
82+
alertBuilder.show();
83+
}
84+
});
85+
86+
// In our original thread, wait for the dialog to finish, then return its result.
87+
while (true) {
88+
// Pause a second, waiting for the user to enter text.
89+
if (nativeSleep(1000)) {
90+
// If this returns true, an exit was requested.
91+
return "";
92+
}
93+
synchronized (lock) {
94+
if (resultText != null) {
95+
// resultText will be set to non-null when a dialog button is clicked, or the dialog
96+
// is canceled.
97+
String result = resultText;
98+
resultText = null; // Consume the result.
99+
return result;
100+
}
101+
}
102+
}
103+
}
104+
105+
private static native boolean nativeSleep(int milliseconds);
106+
}

0 commit comments

Comments
 (0)