Skip to content

Commit b5a8158

Browse files
committed
Updating TrivialQuest to not extend BaseGameActivity.
Completed refactoring of showActivityResultError
1 parent ad115b8 commit b5a8158

3 files changed

Lines changed: 10 additions & 43 deletions

File tree

BasicSamples/TrivialQuest/src/main/java/com/google/example/games/tq/MainActivity.java

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,14 @@
1616
package com.google.example.games.tq;
1717

1818
import android.app.Activity;
19-
import android.app.Dialog;
2019
import android.content.Intent;
2120
import android.os.Bundle;
2221
import android.util.Log;
2322
import android.view.View;
2423

2524
import com.google.android.gms.common.ConnectionResult;
26-
import com.google.android.gms.common.GooglePlayServicesUtil;
2725
import com.google.android.gms.common.api.GoogleApiClient;
2826
import com.google.android.gms.games.Games;
29-
import com.google.android.gms.games.GamesActivityResultCodes;
3027
import com.google.android.gms.plus.Plus;
3128
import com.google.example.games.basegameutils.BaseGameUtils;
3229

@@ -185,35 +182,8 @@ protected void onActivityResult(int requestCode, int responseCode, Intent intent
185182
if (responseCode == RESULT_OK) {
186183
mGoogleApiClient.connect();
187184
} else {
188-
Dialog errorDialog;
189-
int stringId = 0;
190-
switch (responseCode) {
191-
case GamesActivityResultCodes.RESULT_APP_MISCONFIGURED:
192-
stringId = R.string.result_app_misconfigured;
193-
break;
194-
case GamesActivityResultCodes.RESULT_SIGN_IN_FAILED:
195-
stringId = R.string.result_sign_in_failed;
196-
break;
197-
case GamesActivityResultCodes.RESULT_LICENSE_FAILED:
198-
stringId = R.string.result_license_failed;
199-
break;
200-
}
201-
if (stringId != 0) {
202-
errorDialog = BaseGameUtils.makeSimpleDialog(this, getString(stringId));
203-
} else {
204-
// No meaningful Activity response code, so generate default Google
205-
// Play services dialog
206-
errorDialog = GooglePlayServicesUtil.getErrorDialog(responseCode,
207-
this, requestCode, null);
208-
if (errorDialog == null) {
209-
// get fallback dialog
210-
Log.e(TAG,
211-
"No standard error dialog available. Making fallback dialog.");
212-
errorDialog = BaseGameUtils.makeSimpleDialog(this,
213-
getString(R.string.signin_failure) + " " + getString(R.string.signin_other_error));
214-
}
215-
}
216-
errorDialog.show();
185+
BaseGameUtils.showActivityResultError(this,requestCode,responseCode,
186+
R.string.signin_failure, R.string.signin_other_error);
217187
}
218188
}
219189
}

BasicSamples/TrivialQuest/src/main/res/values/strings.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,4 @@
2727
<string name="you_won">OK! You won!</string>
2828
<string name="signin_failure">Unable to sign in. Check your internet connection and try again later.</string>
2929
<string name="signin_other_error">There was an issue with sign in. Please try again later.</string>
30-
<string name="result_app_misconfigured">The application is incorrectly configured. Check that the package name and signing certificate match the client ID created in Developer Console. Also, if the application is not yet published, check that the account you are trying to sign in with is listed as a tester account. See logs for more information.</string>
31-
<string name="result_sign_in_failed">Failed to sign in. Please check your network connection and try again.</string>
32-
<string name="result_license_failed">License check failed.</string>
3330
</resources>

BasicSamples/libraries/BaseGameUtils/src/main/java/com/google/example/games/basegameutils/BaseGameUtils.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,20 @@ public static void showActivityResultError(Activity activity, int requestCode, i
9090
Log.e("BaseGameUtils", "*** No Activity. Can't show failure dialog!");
9191
return;
9292
}
93-
Dialog errorDialog = null;
93+
Dialog errorDialog;
9494

9595
switch (actResp) {
9696
case GamesActivityResultCodes.RESULT_APP_MISCONFIGURED:
97-
errorDialog = makeSimpleDialog(activity, GameHelperUtils_old.getString(
98-
activity, GameHelperUtils_old.R_APP_MISCONFIGURED));
97+
errorDialog = makeSimpleDialog(activity,
98+
activity.getString(R.string.gamehelper_app_misconfigured));
9999
break;
100100
case GamesActivityResultCodes.RESULT_SIGN_IN_FAILED:
101-
errorDialog = makeSimpleDialog(activity, GameHelperUtils_old.getString(
102-
activity, GameHelperUtils_old.R_SIGN_IN_FAILED));
101+
errorDialog = makeSimpleDialog(activity,
102+
activity.getString(R.string.gamehelper_sign_in_failed));
103103
break;
104104
case GamesActivityResultCodes.RESULT_LICENSE_FAILED:
105-
errorDialog = makeSimpleDialog(activity, GameHelperUtils_old.getString(
106-
activity, GameHelperUtils_old.R_LICENSE_FAILED));
105+
errorDialog = makeSimpleDialog(activity,
106+
activity.getString(R.string.gamehelper_license_failed));
107107
break;
108108
default:
109109
// No meaningful Activity response code, so generate default Google
@@ -112,7 +112,7 @@ public static void showActivityResultError(Activity activity, int requestCode, i
112112
activity, requestCode, null);
113113
if (errorDialog == null) {
114114
// get fallback dialog
115-
Log.e("GameHelper",
115+
Log.e("BaseGamesUtils",
116116
"No standard error dialog available. Making fallback dialog.");
117117
errorDialog = makeSimpleDialog(
118118
activity,

0 commit comments

Comments
 (0)