Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.os.Bundle;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.backends.android.AndroidApplication;
- import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
- import com.buckriderstudio.numbergame.ActionResolver;
- import com.buckriderstudio.numbergame.NumberGame;
- import com.buckriderstudio.numbergame.android.R;
- import com.google.android.gms.common.ConnectionResult;
- import com.google.android.gms.common.api.GoogleApiClient;
- import com.google.android.gms.games.Games;
- import com.google.android.gms.games.Player;
- import com.google.android.gms.plus.Plus;
- import com.google.example.games.basegameutils.BaseGameUtils;
- public class AndroidLauncher extends AndroidApplication
- implements ActionResolver,
- GoogleApiClient.ConnectionCallbacks,
- GoogleApiClient.OnConnectionFailedListener {
- // Client used to interact with Google APIs
- private GoogleApiClient mGoogleApiClient;
- // Are we currently resolving a connection failure?
- private boolean mResolvingConnectionFailure = false;
- // Has the user clicked the sign-in button?
- private boolean mSignInClicked = false;
- // Automatically start the sign-in flow when the Activity starts
- private boolean mAutoStartSignInFlow = true;
- // request codes we use when invoking an external activity
- private static final int RC_RESOLVE = 5000;
- private static final int RC_UNUSED = 5001;
- private static final int RC_SIGN_IN = 9001;
- // tag for debug logging
- final boolean ENABLE_DEBUG = true;
- final String TAG = "MainActivity";
- // achievements and scores we're pending to push to the cloud
- // (waiting for the user to sign in, for instance)
- //AccomplishmentsOutbox mOutbox = new AccomplishmentsOutbox();
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
- initialize(new NumberGame(this), config);
- mGoogleApiClient = new GoogleApiClient.Builder(this)
- .addConnectionCallbacks(this)
- .addOnConnectionFailedListener(this)
- .addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
- .addApi(Games.API).addScope(Games.SCOPE_GAMES)
- .build();
- }
- private boolean isSignedIn()
- {
- return (mGoogleApiClient != null && mGoogleApiClient.isConnected());
- }
- @Override
- public void onStart()
- {
- super.onStart();
- Gdx.app.log(TAG, "onStart(): connecting");
- mGoogleApiClient.connect();
- }
- @Override
- protected void onStop() {
- super.onStop();
- Gdx.app.log(TAG, "onStop(): disconnecting");
- }
- @Override
- public void onConnected(Bundle bundle) {
- Gdx.app.log(TAG, "onConnected(): connected to Google APIs");
- // Show sign-out button on main menu
- // Show "you are signed in" message on win screen, with no sign in button.
- // Set the greeting appropriately on main menu
- Player p = Games.Players.getCurrentPlayer(mGoogleApiClient);
- String displayName;
- if (p == null) {
- Gdx.app.log(TAG, "mGamesClient.getCurrentPlayer() is NULL!");
- displayName = "???";
- } else {
- displayName = p.getDisplayName();
- }
- Gdx.app.log(TAG, "Hello, " + displayName);
- // if we have accomplishments to push, push them
- /*
- if (!mOutbox.isEmpty()) {
- pushAccomplishments();
- Toast.makeText(this, getString(R.string.your_progress_will_be_uploaded),
- Toast.LENGTH_LONG).show();
- }
- */
- }
- @Override
- public void onConnectionSuspended(int i) {
- Gdx.app.log(TAG, "onConnectionSuspended(): attempting to connect");
- mGoogleApiClient.connect();
- }
- @Override
- public void onConnectionFailed(ConnectionResult connectionResult) {
- Gdx.app.log(TAG, "onConnectionFailed(): attempting to resolve");
- if (mResolvingConnectionFailure) {
- Gdx.app.log(TAG, "onConnectionFailed(): already resolving");
- return;
- }
- if (mSignInClicked || mAutoStartSignInFlow) {
- mAutoStartSignInFlow = false;
- mSignInClicked = false;
- mResolvingConnectionFailure = true;
- if (!BaseGameUtils.resolveConnectionFailure(this, mGoogleApiClient, connectionResult,
- RC_SIGN_IN, getString(R.string.signin_other_error))) {
- mResolvingConnectionFailure = false;
- }
- }
- // Sign-in failed, so show sign-in button on main menu
- Gdx.app.log(TAG, getString(R.string.signed_out_greeting));
- }
- //-----------------ActionResolver Methods----------------
- @Override
- public boolean getSignedInGPGS() {
- return isSignedIn();
- }
- @Override
- public void loginGPGS() {
- }
- @Override
- public void submitScoreGPGS(int score) {
- }
- @Override
- public void unlockAchievementGPGS(String achievementId) {
- }
- @Override
- public void getLeaderboardGPGS() {
- }
- @Override
- public void getAchievementsGPGS() {
- }
- 4482-4482/com.buckriderstudio.numbergame.android I/MainActivity﹕ onStop(): disconnecting
- 4482-4482/com.buckriderstudio.numbergame.android I/MainActivity﹕ onStart(): connecting
- 4482-4482/com.buckriderstudio.numbergame.android I/MainActivity﹕ onConnectionFailed(): attempting to resolve
- 4482-4482/com.buckriderstudio.numbergame.android I/MainActivity﹕ onConnectionFailed(): already resolving
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement