Skip to content

Commit d9e7b9d

Browse files
committed
removed BaseGameUtils
inlined makeSimpleDialog reduced repetitive code in CollectAllTheStars.MainActivity.onClick changed verifySampleSetup to checkPlaceholderIds Change-Id: I1aea6b4854c4601ceaa9c5546b0b276d2f31c918
1 parent 8d0c698 commit d9e7b9d

File tree

15 files changed

+194
-211
lines changed

15 files changed

+194
-211
lines changed

BasicSamples/ButtonClicker/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ dependencies {
3030
implementation "com.android.support:support-v4:${support_library_version}"
3131
implementation "com.google.android.gms:play-services-games:${gms_library_version}"
3232
implementation "com.google.android.gms:play-services-auth:${gms_library_version}"
33-
implementation project(':libraries:BaseGameUtils')
3433
}
3534

3635
buildscript {

BasicSamples/ButtonClicker/src/main/java/com/google/example/games/bc/MainActivity.java

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
import com.google.android.gms.tasks.OnFailureListener;
5656
import com.google.android.gms.tasks.OnSuccessListener;
5757
import com.google.android.gms.tasks.Task;
58-
import com.google.example.games.basegameutils.BaseGameUtils;
5958

6059
import java.util.ArrayList;
6160
import java.util.HashMap;
@@ -147,6 +146,38 @@ public void onCreate(Bundle savedInstanceState) {
147146
}
148147

149148
switchToMainScreen();
149+
checkPlaceholderIds();
150+
}
151+
152+
// Check the sample to ensure all placeholder ids are are updated with real-world values.
153+
// This is strictly for the purpose of the samples; you don't need this in a production
154+
// application.
155+
private void checkPlaceholderIds() {
156+
StringBuilder problems = new StringBuilder();
157+
158+
if (getPackageName().startsWith("com.google.")) {
159+
problems.append("- Package name start with com.google.*\n");
160+
}
161+
162+
for (Integer id : new Integer[]{R.string.app_id}) {
163+
164+
String value = getString(id);
165+
166+
if (value.startsWith("YOUR_")) {
167+
// needs replacing
168+
problems.append("- Placeholders(YOUR_*) in ids.xml need updating\n");
169+
break;
170+
}
171+
}
172+
173+
if (problems.length() > 0) {
174+
problems.insert(0, "The following problems were found:\n\n");
175+
176+
problems.append("\nThese problems may prevent the app from working properly.");
177+
problems.append("\n\nSee the TODO window in Android Studio for more information");
178+
(new AlertDialog.Builder(this)).setMessage(problems.toString())
179+
.setNeutralButton(android.R.string.ok, null).create().show();
180+
}
150181
}
151182

152183
@Override
@@ -179,14 +210,6 @@ public void onClick(View v) {
179210
startGame(false);
180211
break;
181212
case R.id.button_sign_in:
182-
// user wants to sign in
183-
// Check to see the developer who's running this sample code read the instructions :-)
184-
// NOTE: this check is here only because this is a sample! Don't include this
185-
// check in your actual production app.
186-
if (!BaseGameUtils.verifySampleSetup(this, R.string.app_id)) {
187-
Log.w(TAG, "*** Warning: setup problems detected. Sign in may not work!");
188-
}
189-
190213
// start the sign-in flow
191214
Log.d(TAG, "Sign-in button clicked");
192215
startSignInIntent();
@@ -750,7 +773,10 @@ public void onPeersDisconnected(Room room, @NonNull List<String> peers) {
750773

751774
// Show error message about game being cancelled and return to main screen.
752775
void showGameError() {
753-
BaseGameUtils.makeSimpleDialog(this, getString(R.string.game_problem));
776+
new AlertDialog.Builder(this)
777+
.setMessage(getString(R.string.game_problem))
778+
.setNeutralButton(android.R.string.ok, null).create();
779+
754780
switchToMainScreen();
755781
}
756782

BasicSamples/CollectAllTheStars2/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ dependencies {
3030
implementation "com.android.support:support-v4:${support_library_version}"
3131
implementation "com.google.android.gms:play-services-games:${gms_library_version}"
3232
implementation "com.google.android.gms:play-services-auth:${gms_library_version}"
33-
implementation project(':libraries:BaseGameUtils')
3433
}
3534

3635
buildscript {

BasicSamples/CollectAllTheStars2/src/main/java/com/google/example/games/catt2/MainActivity.java

Lines changed: 81 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import com.google.android.gms.tasks.OnFailureListener;
5353
import com.google.android.gms.tasks.OnSuccessListener;
5454
import com.google.android.gms.tasks.Task;
55-
import com.google.example.games.basegameutils.BaseGameUtils;
5655

5756
import java.io.IOException;
5857
import java.util.ArrayList;
@@ -320,6 +319,38 @@ protected void onCreate(Bundle savedInstanceState) {
320319
((RatingBar) findViewById(R.id.gameplay_rating)).setOnRatingBarChangeListener(this);
321320
mSaveGame = new SaveGame();
322321
updateUi();
322+
checkPlaceholderIds();
323+
}
324+
325+
// Check the sample to ensure all placeholder ids are are updated with real-world values.
326+
// This is strictly for the purpose of the samples; you don't need this in a production
327+
// application.
328+
private void checkPlaceholderIds() {
329+
StringBuilder problems = new StringBuilder();
330+
331+
if (getPackageName().startsWith("com.google.")) {
332+
problems.append("- Package name start with com.google.*\n");
333+
}
334+
335+
for (Integer id : new Integer[]{R.string.app_id}) {
336+
337+
String value = getString(id);
338+
339+
if (value.startsWith("YOUR_")) {
340+
// needs replacing
341+
problems.append("- Placeholders(YOUR_*) in ids.xml need updating\n");
342+
break;
343+
}
344+
}
345+
346+
if (problems.length() > 0) {
347+
problems.insert(0, "The following problems were found:\n\n");
348+
349+
problems.append("\nThese problems may prevent the app from working properly.");
350+
problems.append("\n\nSee the TODO window in Android Studio for more information");
351+
(new AlertDialog.Builder(this)).setMessage(problems.toString())
352+
.setNeutralButton(android.R.string.ok, null).create().show();
353+
}
323354
}
324355

325356
@Override
@@ -358,8 +389,40 @@ public boolean onOptionsItemSelected(MenuItem item) {
358389
protected void onStart() {
359390
updateUi();
360391
super.onStart();
392+
393+
checkPlaceholderIds();
361394
}
362395

396+
public static boolean verifySampleSetup(Activity activity, int... resIds) {
397+
StringBuilder problems = new StringBuilder();
398+
boolean problemFound = false;
399+
problems.append("The following set up problems were found:\n\n");
400+
401+
// Did the developer forget to change the package name?
402+
if (activity.getPackageName().startsWith("com.google.example.games")) {
403+
problemFound = true;
404+
problems.append("- Package name cannot be com.google.*. You need to change the "
405+
+ "sample's package name to your own package.").append("\n");
406+
}
407+
408+
for (int i : resIds) {
409+
if (activity.getString(i).startsWith("YOUR_")) {
410+
problemFound = true;
411+
problems.append("- You must replace `YOUR_*`" +
412+
"placeholder IDs in the ids.xml file by your project's IDs.").append("\n");
413+
break;
414+
}
415+
}
416+
417+
if (problemFound) {
418+
problems.append("\n\nThese problems may prevent the app from working properly.");
419+
(new AlertDialog.Builder(activity)).setMessage(problems.toString())
420+
.setNeutralButton(android.R.string.ok, null).create().show();
421+
return false;
422+
}
423+
424+
return true;
425+
}
363426

364427
@Override
365428
protected void onStop() {
@@ -433,49 +496,45 @@ public void onBackPressed() {
433496
public void onClick(View view) {
434497
switch (view.getId()) {
435498
case R.id.button_sign_in:
436-
// Check to see the developer who's running this sample code read the instructions :-)
437-
// NOTE: this check is here only because this is a sample! Don't include this
438-
// check in your actual production app.
439-
if (!BaseGameUtils.verifySampleSetup(this, R.string.app_id)) {
440-
Log.w(TAG, "*** Warning: setup problems detected. Sign in may not work!");
441-
}
442-
443499
// start the sign-in flow
444500
Log.d(TAG, "Sign-in button clicked");
445501
startSignInIntent();
446-
break;
502+
return;
503+
447504
case R.id.button_sign_out:
448505
// sign out.
449506
signOut();
450507
showSignInBar();
451508
mSaveGame = new SaveGame();
452509
updateUi();
453-
break;
510+
return;
511+
}
512+
513+
if (!isSignedIn()) {
514+
// All other buttons force the user to sign in.
515+
new AlertDialog.Builder(this)
516+
.setMessage(getString(R.string.please_sign_in))
517+
.setNeutralButton(android.R.string.ok, null)
518+
.create()
519+
.show();
520+
521+
return;
522+
}
523+
524+
switch (view.getId()) {
454525
case R.id.button_next_world:
455-
if (!isSignedIn()) {
456-
BaseGameUtils.makeSimpleDialog(this, getString(R.string.please_sign_in)).show();
457-
return;
458-
}
459526
if (mWorld < WORLD_MAX) {
460527
mWorld++;
461528
updateUi();
462529
}
463530
break;
464531
case R.id.button_prev_world:
465-
if (!isSignedIn()) {
466-
BaseGameUtils.makeSimpleDialog(this, getString(R.string.please_sign_in)).show();
467-
return;
468-
}
469532
if (mWorld > WORLD_MIN) {
470533
mWorld--;
471534
updateUi();
472535
}
473536
break;
474537
default:
475-
if (!isSignedIn()) {
476-
BaseGameUtils.makeSimpleDialog(this, getString(R.string.please_sign_in)).show();
477-
return;
478-
}
479538
for (int i = 0; i < LEVEL_BUTTON_IDS.length; ++i) {
480539
if (view.getId() == LEVEL_BUTTON_IDS[i]) {
481540
launchLevel(i + 1);

BasicSamples/SkeletonTbmp/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ dependencies {
2929
implementation "com.android.support:support-v4:${support_library_version}"
3030
implementation "com.google.android.gms:play-services-games:${gms_library_version}"
3131
implementation "com.google.android.gms:play-services-auth:${gms_library_version}"
32-
implementation project(':libraries:BaseGameUtils')
3332
}
3433

3534
buildscript {

BasicSamples/SkeletonTbmp/src/main/java/com/google/example/games/tbmpskeleton/SkeletonActivity.java

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
3434
import com.google.android.gms.common.api.ApiException;
3535
import com.google.android.gms.games.Games;
36-
import com.google.android.gms.games.GamesActivityResultCodes;
3736
import com.google.android.gms.games.GamesCallbackStatusCodes;
3837
import com.google.android.gms.games.GamesClient;
3938
import com.google.android.gms.games.GamesClientStatusCodes;
@@ -51,7 +50,6 @@
5150
import com.google.android.gms.tasks.OnFailureListener;
5251
import com.google.android.gms.tasks.OnSuccessListener;
5352
import com.google.android.gms.tasks.Task;
54-
import com.google.example.games.basegameutils.BaseGameUtils;
5553

5654
import java.util.ArrayList;
5755

@@ -124,6 +122,38 @@ protected void onCreate(Bundle savedInstanceState) {
124122

125123
mDataView = findViewById(R.id.data_view);
126124
mTurnTextView = findViewById(R.id.turn_counter_view);
125+
checkPlaceholderIds();
126+
}
127+
128+
// Check the sample to ensure all placeholder ids are are updated with real-world values.
129+
// This is strictly for the purpose of the samples; you don't need this in a production
130+
// application.
131+
private void checkPlaceholderIds() {
132+
StringBuilder problems = new StringBuilder();
133+
134+
if (getPackageName().startsWith("com.google.")) {
135+
problems.append("- Package name start with com.google.*\n");
136+
}
137+
138+
for (Integer id : new Integer[]{R.string.app_id}) {
139+
140+
String value = getString(id);
141+
142+
if (value.startsWith("YOUR_")) {
143+
// needs replacing
144+
problems.append("- Placeholders(YOUR_*) in ids.xml need updating\n");
145+
break;
146+
}
147+
}
148+
149+
if (problems.length() > 0) {
150+
problems.insert(0, "The following problems were found:\n\n");
151+
152+
problems.append("\nThese problems may prevent the app from working properly.");
153+
problems.append("\n\nSee the TODO window in Android Studio for more information");
154+
(new AlertDialog.Builder(this)).setMessage(problems.toString())
155+
.setNeutralButton(android.R.string.ok, null).create().show();
156+
}
127157
}
128158

129159
@Override
@@ -892,12 +922,6 @@ private boolean checkStatusCode(int statusCode) {
892922
public void onClick(View v) {
893923
switch (v.getId()) {
894924
case R.id.sign_in_button:
895-
// Check to see the developer who's running this sample code read the instructions :-)
896-
// NOTE: this check is here only because this is a sample! Don't include this
897-
// check in your actual production app.
898-
if (!BaseGameUtils.verifySampleSetup(this, R.string.app_id)) {
899-
Log.w(TAG, "*** Warning: setup problems detected. Sign in may not work!");
900-
}
901925
mMatch = null;
902926
findViewById(R.id.sign_in_button).setVisibility(View.GONE);
903927
startSignInIntent();

BasicSamples/TypeANumber/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ dependencies {
3030
implementation "com.android.support:support-v4:${support_library_version}"
3131
implementation "com.google.android.gms:play-services-games:${gms_library_version}"
3232
implementation "com.google.android.gms:play-services-auth:${gms_library_version}"
33-
implementation project(':libraries:BaseGameUtils')
3433
}
3534

3635
buildscript {

0 commit comments

Comments
 (0)