Skip to content

Commit 296d6d6

Browse files
committed
Initial samples for SDK
0 parents  commit 296d6d6

110 files changed

Lines changed: 17093 additions & 0 deletions

File tree

Some content is hidden

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

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Google Play Games C++ SDK Samples
2+
=================================
3+
4+
To use these samples, you will need the Play Games C++ SDK, which you
5+
can download from:
6+
7+
[https://developers.google.com/games/services/downloads/](https://developers.google.com/games/services/downloads/)
8+
9+
Unzip the archive you download into this directory.
10+
11+
Then follow the instructions you can find here:
12+
13+
[https://developers.google.com/games/services/cpp/GettingStartedNativeClient](https://developers.google.com/games/services/cpp/GettingStartedNativeClient)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="src" path="gen"/>
5+
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
6+
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
7+
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
8+
<classpathentry kind="output" path="bin/classes"/>
9+
</classpath>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>MinimalistActivity</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.jdt.core.javabuilder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
</buildSpec>
29+
<natures>
30+
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
31+
<nature>org.eclipse.jdt.core.javanature</nature>
32+
</natures>
33+
</projectDescription>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- BEGIN_INCLUDE(manifest) -->
3+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
4+
package="com.wolff.native_activity"
5+
android:versionCode="1"
6+
android:versionName="1.0">
7+
8+
<uses-sdk android:minSdkVersion="10" />
9+
10+
<!-- This .apk has no Java code itself, so set hasCode to false. -->
11+
<application android:label="@string/app_name" >
12+
13+
<meta-data android:name="com.google.android.gms.games.APP_ID"
14+
android:value="@string/app_id" />
15+
<meta-data android:name="com.google.android.gms.version"
16+
android:value="@integer/google_play_services_version"/>
17+
18+
19+
<!-- Our activity is the built-in NativeActivity framework class.
20+
This will take care of integrating with our NDK code. -->
21+
<activity android:name="android.app.NativeActivity"
22+
android:label="@string/app_name"
23+
android:configChanges="orientation|keyboardHidden">
24+
<!-- Tell NativeActivity the name of or .so -->
25+
<meta-data android:name="android.app.lib_name"
26+
android:value="native-activity" />
27+
<intent-filter>
28+
<action android:name="android.intent.action.MAIN" />
29+
<category android:name="android.intent.category.LAUNCHER" />
30+
</intent-filter>
31+
</activity>
32+
</application>
33+
34+
</manifest>
35+
<!-- END_INCLUDE(manifest) -->
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright (C) 2010 The Android Open Source Project
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+
LOCAL_PATH := $(call my-dir)
16+
17+
include $(CLEAR_VARS)
18+
19+
LOCAL_C_INCLUDES := $(LOCAL_PATH)/.. $(LOCAL_PATH)/../../../gpg-cpp-sdk/android/include
20+
21+
LOCAL_MODULE := native-activity
22+
LOCAL_SRC_FILES := main.cpp StateManager.cpp
23+
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv1_CM -lz
24+
LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../../../gpg-cpp-sdk/android/lib/$(TARGET_ARCH_ABI) -lgpg
25+
LOCAL_LDFLAGS += -L$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/libs/$(TARGET_ARCH_ABI) -lgnustl_static
26+
LOCAL_STATIC_LIBRARIES := android_native_app_glue
27+
28+
include $(BUILD_SHARED_LIBRARY)
29+
30+
$(call import-module,android/native_app_glue)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
APP_STL := gnustl_static
2+
APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -Wno-deprecated-declarations -Wno-multichar -Wno-literal-suffix
3+
APP_ABI := armeabi armeabi-v7a x86
4+
NDK_TOOLCHAIN_VERSION := 4.8
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// Copyright (c) 2014 Google Inc.
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+
16+
#include "jni/StateManager.h"
17+
18+
#ifdef __APPLE__
19+
// Logging for CoreFoundation
20+
#include <CoreFoundation/CoreFoundation.h>
21+
22+
extern "C" void NSLog(CFStringRef format, ...);
23+
const int32_t BUFFER_SIZE = 256;
24+
25+
// Wrap macro in do/while to ensure ;
26+
#define LOGI(...) do { \
27+
char c[BUFFER_SIZE]; \
28+
snprintf(c, BUFFER_SIZE, __VA_ARGS__); \
29+
CFStringRef str = CFStringCreateWithCString(kCFAllocatorDefault, c, \
30+
kCFStringEncodingMacRoman); \
31+
NSLog(str); \
32+
CFRelease(str); \
33+
} while (false)
34+
35+
#else
36+
37+
#include "android/Log.h"
38+
#define DEBUG_TAG "TeapotNativeActivity"
39+
#define LOGI(...) \
40+
((void)__android_log_print(ANDROID_LOG_INFO, DEBUG_TAG, __VA_ARGS__))
41+
42+
#endif
43+
44+
#include "gpg/achievement_manager.h"
45+
bool StateManager::is_auth_in_progress_ = false;
46+
std::unique_ptr<gpg::GameServices> StateManager::game_services_;
47+
48+
void OnAuthActionFinished(gpg::AuthOperation op, gpg::AuthStatus status) {
49+
LOGI("OnAuthActionFinished");
50+
}
51+
52+
void OnAuthActionStarted(gpg::AuthOperation op) {
53+
LOGI("OnAuthActionStarted");
54+
switch ( op ) {
55+
case gpg::AuthOperation::SIGN_IN:
56+
LOGI("Signing In");
57+
break;
58+
case gpg::AuthOperation::SIGN_OUT:
59+
LOGI("Signing Out");
60+
break;
61+
}
62+
}
63+
64+
gpg::GameServices *StateManager::GetGameServices() {
65+
return game_services_.get();
66+
}
67+
68+
void StateManager::BeginUserInitiatedSignIn() {
69+
if (!game_services_->IsAuthorized()) {
70+
LOGI("StartAuthorizationUI");
71+
game_services_->StartAuthorizationUI();
72+
}
73+
}
74+
75+
void StateManager::SignOut() {
76+
if (game_services_->IsAuthorized()) {
77+
LOGI("SignOut");
78+
game_services_->SignOut();
79+
}
80+
}
81+
82+
void StateManager::UnlockAchievement(char const *achievement_id) {
83+
if (game_services_->IsAuthorized()) {
84+
LOGI("Achievement unlocked");
85+
game_services_->Achievements().Unlock(achievement_id);
86+
}
87+
}
88+
89+
void StateManager::SubmitHighScore(char const *leaderboard_id, uint64_t score) {
90+
if (game_services_->IsAuthorized()) {
91+
LOGI("High score submitted");
92+
game_services_->Leaderboards().SubmitScore(leaderboard_id, score);
93+
}
94+
}
95+
96+
void StateManager::ShowAchievements() {
97+
if (game_services_->IsAuthorized()) {
98+
LOGI("Show achievement");
99+
game_services_->Achievements().ShowAllUI();
100+
}
101+
}
102+
103+
void StateManager::ShowLeaderboard(char const *leaderboard_id) {
104+
if (game_services_->IsAuthorized()) {
105+
LOGI("Show achievement");
106+
game_services_->Leaderboards().ShowUI(leaderboard_id);
107+
}
108+
}
109+
110+
111+
void StateManager::InitServices(
112+
gpg::PlatformConfiguration const &pc,
113+
gpg::GameServices::Builder::OnAuthActionStartedCallback started_callback,
114+
gpg::GameServices::Builder::OnAuthActionFinishedCallback
115+
finished_callback) {
116+
LOGI("Initializing Services");
117+
if (!game_services_) {
118+
LOGI("Uninitialized services, so creating");
119+
game_services_ = gpg::GameServices::Builder()
120+
.SetLogging(gpg::DEFAULT_ON_LOG, gpg::LogLevel::VERBOSE)
121+
.SetOnAuthActionStarted([started_callback](gpg::AuthOperation op) {
122+
is_auth_in_progress_ = true;
123+
started_callback(op);
124+
})
125+
.SetOnAuthActionFinished([finished_callback](gpg::AuthOperation op,
126+
gpg::AuthStatus status) {
127+
LOGI("Sign in finished with a result of %d", status);
128+
is_auth_in_progress_ = false;
129+
finished_callback(op, status);
130+
LOGI("Fetching all blocking");
131+
gpg::AchievementManager::FetchAllResponse fetchResponse = game_services_->Achievements().FetchAllBlocking(std::chrono::milliseconds(1000));
132+
LOGI("--------------------------------------------------------------");
133+
134+
LOGI("Fetching all nonblocking");
135+
game_services_->Achievements().FetchAll(gpg::DataSource::CACHE_OR_NETWORK, [] (gpg::AchievementManager::FetchAllResponse response) {LOGI("Achievement response status: %d", response.status);});
136+
LOGI("--------------------------------------------------------------");
137+
138+
})
139+
.Create(pc);
140+
}
141+
LOGI("Created");
142+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#ifndef TEAPOT_JNI_STATE_MANAGER_H
2+
#define TEAPOT_JNI_STATE_MANAGER_H
3+
4+
#ifdef __OBJC__
5+
#include <objc/NSObjCRuntime.h>
6+
#endif
7+
8+
#include "gpg/achievement.h"
9+
#include "gpg/achievement_manager.h"
10+
#include "gpg/builder.h"
11+
#include "gpg/debug.h"
12+
#include "gpg/default_callbacks.h"
13+
#include "gpg/game_services.h"
14+
#include "gpg/leaderboard.h"
15+
#include "gpg/leaderboard_manager.h"
16+
#include "gpg/platform_configuration.h"
17+
#include "gpg/player_manager.h"
18+
#include "gpg/score_page.h"
19+
#include "gpg/types.h"
20+
21+
class StateManager {
22+
public:
23+
static void InitServices(
24+
gpg::PlatformConfiguration const &pc,
25+
gpg::GameServices::Builder::OnAuthActionStartedCallback started_callback,
26+
gpg::GameServices::Builder::OnAuthActionFinishedCallback
27+
finished_callback);
28+
static gpg::GameServices *GetGameServices();
29+
static void BeginUserInitiatedSignIn();
30+
static void SignOut();
31+
static void UnlockAchievement(const char *achievementId);
32+
static void SubmitHighScore(const char *leaderboardId, uint64_t score);
33+
static void ShowAchievements();
34+
static void ShowLeaderboard(const char *leaderboardId);
35+
static bool IsAuthInProgress() {
36+
return is_auth_in_progress_;
37+
}
38+
39+
private:
40+
static bool is_auth_in_progress_;
41+
static std::unique_ptr<gpg::GameServices> game_services_;
42+
};
43+
44+
#endif // TEAPOT_JNI_STATE_MANAGER_H

0 commit comments

Comments
 (0)