Skip to content

Commit 1986182

Browse files
committed
ADD: play service start implementation
1 parent 5ff9537 commit 1986182

17 files changed

+1899
-4
lines changed

BaseGameUtils/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/bin/
2+
/build/
3+
/gen/

BaseGameUtils/build.gradle

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
apply plugin: 'com.android.library'
2+
3+
buildscript {
4+
repositories {
5+
jcenter()
6+
}
7+
8+
dependencies {
9+
classpath 'com.android.tools.build:gradle:1.3.1'
10+
}
11+
}
12+
13+
dependencies {
14+
// Set defaults so that BaseGameUtils can be used outside of BasicSamples
15+
if (!project.hasProperty('appcompat_library_version')) {
16+
ext.appcompat_library_version = '20.0.+'
17+
}
18+
if (!project.hasProperty('support_library_version')) {
19+
ext.support_library_version = '20.0.+'
20+
}
21+
if (!project.hasProperty('gms_library_version')) {
22+
ext.gms_library_version = '8.4.0'
23+
}
24+
25+
compile "com.android.support:appcompat-v7:${appcompat_library_version}"
26+
compile "com.android.support:support-v4:${support_library_version}"
27+
compile "com.google.android.gms:play-services-games:${gms_library_version}"
28+
compile "com.google.android.gms:play-services-plus:${gms_library_version}"
29+
}
30+
31+
android {
32+
// Set defaults so that BaseGameUtils can be used outside of BasicSamples
33+
if (!project.hasProperty('android_compile_version')) {
34+
ext.android_compile_version = 23
35+
}
36+
if (!project.hasProperty('android_min_version')) {
37+
ext.android_min_version = 15
38+
}
39+
if (!project.hasProperty('android_version')) {
40+
ext.build_tools_version = "23.0.2"
41+
}
42+
43+
compileSdkVersion android_compile_version
44+
buildToolsVersion build_tools_version
45+
46+
defaultConfig {
47+
minSdkVersion android_min_version
48+
targetSdkVersion android_compile_version
49+
}
50+
}
51+
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright (C) 2013 Google Inc.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
18+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
19+
package="com.google.example.games.basegameutils"
20+
android:versionCode="1"
21+
android:versionName="1.0" >
22+
23+
24+
<application>
25+
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
26+
</application>
27+
28+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/*
2+
* Copyright (C) 2013 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.example.games.basegameutils;
18+
19+
import android.content.Intent;
20+
import android.os.Bundle;
21+
import android.support.v4.app.FragmentActivity;
22+
import android.util.Log;
23+
24+
import com.google.android.gms.common.api.GoogleApiClient;
25+
26+
/**
27+
* Example base class for games. This implementation takes care of setting up
28+
* the API client object and managing its lifecycle. Subclasses only need to
29+
* override the @link{#onSignInSucceeded} and @link{#onSignInFailed} abstract
30+
* methods. To initiate the sign-in flow when the user clicks the sign-in
31+
* button, subclasses should call @link{#beginUserInitiatedSignIn}. By default,
32+
* this class only instantiates the GoogleApiClient object. If the PlusClient
33+
* is also wanted, call the BaseGameActivity(int)
34+
* constructor and specify the requested clients. For example, to request
35+
* PlusClient and GamesClient, use BaseGameActivity(CLIENT_GAMES | CLIENT_PLUS).
36+
* To request all available clients, use BaseGameActivity(CLIENT_ALL).
37+
* Alternatively, you can also specify the requested clients via
38+
* @link{#setRequestedClients}, but you must do so before @link{#onCreate}
39+
* gets called, otherwise the call will have no effect.
40+
*
41+
* @author Bruno Oliveira (Google)
42+
*/
43+
public abstract class BaseGameActivity extends FragmentActivity implements
44+
GameHelper.GameHelperListener {
45+
46+
// The game helper object. This class is mainly a wrapper around this object.
47+
protected GameHelper mHelper;
48+
49+
// We expose these constants here because we don't want users of this class
50+
// to have to know about GameHelper at all.
51+
public static final int CLIENT_GAMES = GameHelper.CLIENT_GAMES;
52+
public static final int CLIENT_PLUS = GameHelper.CLIENT_PLUS;
53+
public static final int CLIENT_ALL = GameHelper.CLIENT_ALL;
54+
55+
// Requested clients. By default, that's just the games client.
56+
protected int mRequestedClients = CLIENT_GAMES;
57+
58+
private final static String TAG = "BaseGameActivity";
59+
protected boolean mDebugLog = false;
60+
61+
/** Constructs a BaseGameActivity with default client (GamesClient). */
62+
protected BaseGameActivity() {
63+
super();
64+
}
65+
66+
/**
67+
* Constructs a BaseGameActivity with the requested clients.
68+
* @param requestedClients The requested clients (a combination of CLIENT_GAMES,
69+
* CLIENT_PLUS).
70+
*/
71+
protected BaseGameActivity(int requestedClients) {
72+
super();
73+
setRequestedClients(requestedClients);
74+
}
75+
76+
/**
77+
* Sets the requested clients. The preferred way to set the requested clients is
78+
* via the constructor, but this method is available if for some reason your code
79+
* cannot do this in the constructor. This must be called before onCreate or getGameHelper()
80+
* in order to have any effect. If called after onCreate()/getGameHelper(), this method
81+
* is a no-op.
82+
*
83+
* @param requestedClients A combination of the flags CLIENT_GAMES, CLIENT_PLUS
84+
* or CLIENT_ALL to request all available clients.
85+
*/
86+
protected void setRequestedClients(int requestedClients) {
87+
mRequestedClients = requestedClients;
88+
}
89+
90+
public GameHelper getGameHelper() {
91+
if (mHelper == null) {
92+
mHelper = new GameHelper(this, mRequestedClients);
93+
mHelper.enableDebugLog(mDebugLog);
94+
}
95+
return mHelper;
96+
}
97+
98+
@Override
99+
protected void onCreate(Bundle b) {
100+
super.onCreate(b);
101+
if (mHelper == null) {
102+
getGameHelper();
103+
}
104+
mHelper.setup(this);
105+
}
106+
107+
@Override
108+
protected void onStart() {
109+
super.onStart();
110+
mHelper.onStart(this);
111+
}
112+
113+
@Override
114+
protected void onStop() {
115+
super.onStop();
116+
mHelper.onStop();
117+
}
118+
119+
@Override
120+
protected void onActivityResult(int request, int response, Intent data) {
121+
super.onActivityResult(request, response, data);
122+
mHelper.onActivityResult(request, response, data);
123+
}
124+
125+
protected GoogleApiClient getApiClient() {
126+
return mHelper.getApiClient();
127+
}
128+
129+
protected boolean isSignedIn() {
130+
return mHelper.isSignedIn();
131+
}
132+
133+
protected void beginUserInitiatedSignIn() {
134+
mHelper.beginUserInitiatedSignIn();
135+
}
136+
137+
protected void signOut() {
138+
mHelper.signOut();
139+
}
140+
141+
protected void showAlert(String message) {
142+
mHelper.makeSimpleDialog(message).show();
143+
}
144+
145+
protected void showAlert(String title, String message) {
146+
mHelper.makeSimpleDialog(title, message).show();
147+
}
148+
149+
protected void enableDebugLog(boolean enabled) {
150+
mDebugLog = true;
151+
if (mHelper != null) {
152+
mHelper.enableDebugLog(enabled);
153+
}
154+
}
155+
156+
@Deprecated
157+
protected void enableDebugLog(boolean enabled, String tag) {
158+
Log.w(TAG, "BaseGameActivity.enabledDebugLog(bool,String) is " +
159+
"deprecated. Use enableDebugLog(boolean)");
160+
enableDebugLog(enabled);
161+
}
162+
163+
protected String getInvitationId() {
164+
return mHelper.getInvitationId();
165+
}
166+
167+
protected void reconnectClient() {
168+
mHelper.reconnectClient();
169+
}
170+
171+
protected boolean hasSignInError() {
172+
return mHelper.hasSignInError();
173+
}
174+
175+
protected GameHelper.SignInFailureReason getSignInError() {
176+
return mHelper.getSignInError();
177+
}
178+
}

0 commit comments

Comments
 (0)