Skip to content

Commit 57c4d46

Browse files
committed
Initial support for Firebase Messaging.
Displays the message from the menu, and can be used to grant a bonus through the XP system. Change-Id: I892017fe30ff3e16f6b1448745399e7380b10974
1 parent 5c0b64e commit 57c4d46

12 files changed

+332
-55
lines changed

AndroidManifest.xml

+25
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ limitations under the License.
1919
android:versionCode="16"
2020
android:versionName="1.1">
2121

22+
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
23+
<permission
24+
android:name="com.google.fpl.zooshi.permission.C2D_MESSAGE"
25+
android:protectionLevel="signature" />
26+
<uses-permission
27+
android:name="com.google.fpl.zooshi.permission.C2D_MESSAGE" />
28+
2229
<!-- This .apk has no Java code itself, so set hasCode to false. -->
2330
<application android:label="@string/app_name"
2431
android:icon="@drawable/ic_launcher"
@@ -84,6 +91,24 @@ limitations under the License.
8491
android:value="@string/app_id" />
8592
<meta-data android:name="com.google.android.gms.version"
8693
android:value="@integer/google_play_services_version"/>
94+
95+
<service android:name="com.google.firebase.messaging.cpp.ListenerService"
96+
android:exported="false" >
97+
<intent-filter>
98+
<action android:name="com.google.firebase.MESSAGING_EVENT" />
99+
</intent-filter>
100+
</service>
101+
102+
<service android:name="com.google.firebase.messaging.cpp.FcmInstanceIDListenerService"
103+
android:exported="false" >
104+
<intent-filter>
105+
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
106+
</intent-filter>
107+
</service>
108+
109+
<service android:name="com.google.firebase.messaging.cpp.RegistrationIntentService"
110+
android:exported="false" >
111+
</service>
87112
</application>
88113

89114
<!-- Minimum for SDL -->

CMakeLists.txt

+8
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,11 @@ set(zooshi_SRCS
222222
src/inputcontrollers/onscreen_controller.h
223223
src/inputcontrollers/mouse_controller.cpp
224224
src/inputcontrollers/mouse_controller.h
225+
src/invites.cpp
226+
src/invites.h
225227
src/main.cpp
228+
src/messaging.cpp
229+
src/messaging.h
226230
src/modules/attributes.cpp
227231
src/modules/attributes.h
228232
src/modules/gpg.cpp
@@ -357,6 +361,9 @@ set_target_properties(firebase_analytics PROPERTIES
357361
add_library(firebase_invites STATIC IMPORTED)
358362
set_target_properties(firebase_invites PROPERTIES
359363
IMPORTED_LOCATION ${firebase_dir}/libs/${platform_type}/libinvites.a)
364+
add_library(firebase_messaging STATIC IMPORTED)
365+
set_target_properties(firebase_messaging PROPERTIES
366+
IMPORTED_LOCATION ${firebase_dir}/libs/${platform_type}/libmessaging.a)
360367

361368
# Dependencies for the executable target.
362369
add_dependencies(zooshi zooshi_generated_includes assets)
@@ -373,6 +380,7 @@ target_link_libraries(zooshi
373380
pindrop
374381
firebase_analytics
375382
firebase_invites
383+
firebase_messaging
376384
firebase_app
377385
)
378386

build.gradle

+6
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ dependencies {
7373
compile 'com.google.android.gms:play-services-base:10.0.1'
7474
compile 'com.google.android.gms:play-services-games:10.0.1'
7575
compile 'com.google.firebase:firebase-invites:10.0.1'
76+
compile 'com.google.firebase:firebase-messaging:10.0.1'
7677
compile 'com.android.support:support-v4:23.0+'
7778
}
7879

@@ -91,4 +92,9 @@ task copyFplbase(type: Copy) {
9192
project.afterEvaluate {
9293
preBuild.dependsOn(copyCardboard)
9394
preBuild.dependsOn(copyFplbase)
95+
}
96+
97+
dependencies {
98+
// TODO(amaurice) Make this inclusion more generic, as it currently assumes the internal layout.
99+
compile files(new File('../../../../prebuilts/cpp-firebase/firebase_cpp_sdk/libs/android/libmessaging_java.jar'))
94100
}

google-services.json

+12-21
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
{
22
"project_info": {
3-
"project_id": "zooshi-9b1ae",
43
"project_number": "358673201274",
5-
"name": "Zooshi",
64
"firebase_url": "https://zooshi-9b1ae.firebaseio.com",
7-
"storage_bucket": "zooshi-9b1ae.storage.firebase.com"
5+
"project_id": "zooshi-9b1ae",
6+
"storage_bucket": "zooshi-9b1ae.appspot.com"
87
},
98
"client": [
109
{
1110
"client_info": {
1211
"mobilesdk_app_id": "1:358673201274:android:d5ad37b71583d0fc",
13-
"client_id": "android:com.google.fpl.zooshi",
14-
"client_type": 1,
1512
"android_client_info": {
16-
"package_name": "com.google.fpl.zooshi",
17-
"certificate_hash": []
13+
"package_name": "com.google.fpl.zooshi"
1814
}
1915
},
2016
"oauth_client": [
@@ -40,25 +36,20 @@
4036
"analytics_service": {
4137
"status": 1
4238
},
43-
"cloud_messaging_service": {
44-
"status": 1,
45-
"apns_config": []
46-
},
4739
"appinvite_service": {
48-
"status": 1,
49-
"other_platform_oauth_client": []
50-
},
51-
"google_signin_service": {
52-
"status": 1
40+
"status": 2,
41+
"other_platform_oauth_client": [
42+
{
43+
"client_id": "358673201274-qpi8n9phv3jdrr49u88vjn16hr9l7nri.apps.googleusercontent.com",
44+
"client_type": 3
45+
}
46+
]
5347
},
5448
"ads_service": {
55-
"status": 2,
56-
"test_banner_ad_unit_id": "ca-app-pub-3940256099942544/6300978111",
57-
"test_interstitial_ad_unit_id": "ca-app-pub-3940256099942544/1033173712"
49+
"status": 2
5850
}
5951
}
6052
}
6153
],
62-
"client_info": [],
63-
"ARTIFACT_VERSION": "1"
54+
"configuration_version": "1"
6455
}

jni/libs/src/Android.mk

+7
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ LOCAL_MODULE := libfirebase_invites
6969
LOCAL_SRC_FILES := $(FIREBASE_LIBRARY_PATH)/libinvites.a
7070
include $(PREBUILT_STATIC_LIBRARY)
7171

72+
include $(CLEAR_VARS)
73+
LOCAL_MODULE := libfirebase_messaging
74+
LOCAL_SRC_FILES := $(FIREBASE_LIBRARY_PATH)/libmessaging.a
75+
include $(PREBUILT_STATIC_LIBRARY)
76+
7277
include $(CLEAR_VARS)
7378

7479
LOCAL_MODULE := main
@@ -124,6 +129,7 @@ LOCAL_SRC_FILES := \
124129
src/inputcontrollers/onscreen_controller.cpp \
125130
src/invites.cpp \
126131
src/main.cpp \
132+
src/messaging.cpp \
127133
src/modules/attributes.cpp \
128134
src/modules/gpg.cpp \
129135
src/modules/patron.cpp \
@@ -221,6 +227,7 @@ LOCAL_STATIC_LIBRARIES := \
221227
libbullet \
222228
libfirebase_analytics \
223229
libfirebase_invites \
230+
libfirebase_messaging \
224231
libfirebase_app
225232

226233
LOCAL_SHARED_LIBRARIES :=

src/gui.cpp

+57-32
Original file line numberDiff line numberDiff line change
@@ -637,13 +637,9 @@ void GameMenuState::OptionMenuLevel() {
637637
flatui::EndGroup();
638638
}
639639

640-
MenuState GameMenuState::ScoreReviewMenu(fplbase::AssetManager& assetman,
641-
flatui::FontManager& fontman,
642-
fplbase::InputSystem& input) {
643-
MenuState next_state = kMenuStateScoreReview;
644-
645-
PushDebugMarker("ScoreReviewMenu");
646-
640+
void GameMenuState::EmptyMenuBackground(
641+
fplbase::AssetManager& assetman, flatui::FontManager& fontman,
642+
fplbase::InputSystem& input, const std::function<void()>& gui_definition) {
647643
flatui::Run(assetman, fontman, input, [&]() {
648644
flatui::StartGroup(flatui::kLayoutOverlay, 0);
649645
flatui::StartGroup(flatui::kLayoutHorizontalTop, 0);
@@ -655,6 +651,32 @@ MenuState GameMenuState::ScoreReviewMenu(fplbase::AssetManager& assetman,
655651
flatui::Image(*background_options_, 1400);
656652
flatui::EndGroup();
657653

654+
gui_definition();
655+
656+
flatui::EndGroup();
657+
flatui::EndGroup();
658+
});
659+
}
660+
661+
bool GameMenuState::DisplayMessageBackButton() {
662+
flatui::StartGroup(flatui::kLayoutHorizontalBottom, 150);
663+
flatui::PositionGroup(flatui::kAlignCenter, flatui::kAlignBottom,
664+
mathfu::vec2(0, -125));
665+
flatui::SetTextColor(kColorLightBrown);
666+
auto event = ImageButtonWithLabel(*button_back_, 60,
667+
flatui::Margin(60, 35, 40, 50), "Back");
668+
flatui::EndGroup();
669+
return event & flatui::kEventWentUp;
670+
}
671+
672+
MenuState GameMenuState::ScoreReviewMenu(fplbase::AssetManager& assetman,
673+
flatui::FontManager& fontman,
674+
fplbase::InputSystem& input) {
675+
MenuState next_state = kMenuStateScoreReview;
676+
677+
PushDebugMarker("ScoreReviewMenu");
678+
679+
EmptyMenuBackground(assetman, fontman, input, [&]() {
658680
// Display the game end values, along with the score.
659681
flatui::SetTextColor(kColorBrown);
660682
flatui::StartGroup(flatui::kLayoutVerticalRight, 10);
@@ -715,9 +737,6 @@ MenuState GameMenuState::ScoreReviewMenu(fplbase::AssetManager& assetman,
715737
next_state = kMenuStateFinished;
716738
}
717739
flatui::EndGroup();
718-
719-
flatui::EndGroup();
720-
flatui::EndGroup();
721740
});
722741

723742
PopDebugMarker(); // ScoreReviewMenu
@@ -732,18 +751,8 @@ MenuState GameMenuState::ReceivedInviteMenu(fplbase::AssetManager& assetman,
732751

733752
PushDebugMarker("ReceivedInviteMenu");
734753

735-
flatui::Run(assetman, fontman, input, [&]() {
736-
flatui::StartGroup(flatui::kLayoutOverlay, 0);
737-
flatui::StartGroup(flatui::kLayoutHorizontalTop, 0);
738-
// Background image.
739-
flatui::StartGroup(flatui::kLayoutVerticalCenter, 0);
740-
// Positioning the UI slightly above of the center.
741-
flatui::PositionGroup(flatui::kAlignCenter, flatui::kAlignCenter,
742-
mathfu::vec2(0, -150));
743-
flatui::Image(*background_options_, 1400);
744-
flatui::EndGroup();
745-
746-
// Display the game end values, along with the score.
754+
EmptyMenuBackground(assetman, fontman, input, [&]() {
755+
// Display a message indicating an invite was received.
747756
flatui::SetTextColor(kColorBrown);
748757
flatui::StartGroup(flatui::kLayoutVerticalCenter, 10);
749758
flatui::PositionGroup(flatui::kAlignCenter, flatui::kAlignCenter,
@@ -758,22 +767,38 @@ MenuState GameMenuState::ReceivedInviteMenu(fplbase::AssetManager& assetman,
758767
}
759768
flatui::EndGroup();
760769

761-
flatui::StartGroup(flatui::kLayoutHorizontalBottom, 150);
762-
flatui::PositionGroup(flatui::kAlignCenter, flatui::kAlignBottom,
763-
mathfu::vec2(0, -125));
764-
flatui::SetTextColor(kColorLightBrown);
765-
auto event = ImageButtonWithLabel(*button_back_, 60,
766-
flatui::Margin(60, 35, 40, 50), "Back");
767-
if (event & flatui::kEventWentUp) {
770+
if (DisplayMessageBackButton()) {
768771
next_state = kMenuStateStart;
769772
}
770-
flatui::EndGroup();
773+
});
771774

775+
PopDebugMarker(); // ReceivedInviteMenu
776+
777+
return next_state;
778+
}
779+
780+
MenuState GameMenuState::ReceivedMessageMenu(fplbase::AssetManager& assetman,
781+
flatui::FontManager& fontman,
782+
fplbase::InputSystem& input) {
783+
MenuState next_state = kMenuStateReceivedMessage;
784+
785+
PushDebugMarker("ReceivedMessageMenu");
786+
787+
EmptyMenuBackground(assetman, fontman, input, [&]() {
788+
// Display the message that was received.
789+
flatui::SetTextColor(kColorBrown);
790+
flatui::StartGroup(flatui::kLayoutVerticalCenter, 10);
791+
flatui::PositionGroup(flatui::kAlignCenter, flatui::kAlignCenter,
792+
mathfu::kZeros2f);
793+
flatui::Label(received_message_.c_str(), kButtonSize);
772794
flatui::EndGroup();
773-
flatui::EndGroup();
795+
796+
if (DisplayMessageBackButton()) {
797+
next_state = kMenuStateStart;
798+
}
774799
});
775800

776-
PopDebugMarker(); // ReceivedInviteMenu
801+
PopDebugMarker(); // ReceivedMessageMenu
777802

778803
return next_state;
779804
}

0 commit comments

Comments
 (0)