com.google.android.gms.games.Player Java Examples

The following examples show how to use com.google.android.gms.games.Player. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PlayGamesPlugin.java    From play_games with MIT License 6 votes vote down vote up
private void handleSuccess(GoogleSignInAccount acc) {
    currentAccount = acc;
    PlayersClient playersClient = Games.getPlayersClient(registrar.activity(), currentAccount);
    playersClient.getCurrentPlayer().addOnSuccessListener(new OnSuccessListener<Player>() {
        @Override
        public void onSuccess(Player player) {
            Map<String, Object> successMap = new HashMap<>();
            successMap.put("type", "SUCCESS");
            successMap.put("id", player.getPlayerId());
            successMap.put("email", currentAccount.getEmail());
            successMap.put("displayName", player.getDisplayName());
            successMap.put("hiResImageUri", player.getHiResImageUri().toString());
            successMap.put("iconImageUri", player.getIconImageUri().toString());
            result(successMap);
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(Exception e) {
            error("ERROR_FETCH_PLAYER_PROFILE", e);
        }
    });
}
 
Example #2
Source File: ExtensionContext.java    From ANE-Google-Play-Game-Services with Apache License 2.0 6 votes vote down vote up
private String scoresToJsonString( LeaderboardScoreBuffer scores ) {

        int scoresNb = scores.getCount();
        JSONArray jsonScores = new JSONArray();
        for ( int i = 0; i < scoresNb; ++i ) {
            LeaderboardScore score = scores.get(i);
            JSONObject jsonScore = new JSONObject();
            try {
                jsonScore.put("value", score.getRawScore());
                jsonScore.put("rank", score.getRank());

                Player player = score.getScoreHolder();
                JSONObject jsonPlayer = new JSONObject();
                jsonPlayer.put("id", player.getPlayerId());
                jsonPlayer.put("displayName", player.getDisplayName());
                jsonPlayer.put("picture", player.getIconImageUri());

                jsonScore.put("player", jsonPlayer);

                jsonScores.put( jsonScore );

            } catch( JSONException e ) {}
        }
        return jsonScores.toString();

    }
 
Example #3
Source File: AirGooglePlayGamesGetActivePlayerName.java    From ANE-Google-Play-Game-Services with Apache License 2.0 6 votes vote down vote up
@Override
public FREObject call(FREContext arg0, FREObject[] arg1) {
	
	Extension.context.createHelperIfNeeded(arg0.getActivity());
	Player player = Games.Players.getCurrentPlayer(Extension.context.getApiClient());
	
	FREObject playerName = null;
	if (player != null)
	{
		try {
			playerName = FREObject.newObject(player.getDisplayName());
		} catch (FREWrongThreadException e) {
			e.printStackTrace();
		}
	}
	
	return playerName;
}
 
Example #4
Source File: Request.java    From play_games with MIT License 5 votes vote down vote up
public void getHiResImage() {
    PlayersClient playersClient = Games.getPlayersClient(registrar.activity(), currentAccount);
    playersClient.getCurrentPlayer().addOnSuccessListener(new OnSuccessListener<Player>() {
        @Override
        public void onSuccess(Player player) {
            readImage(player.getHiResImageUri());
        }
    });
}
 
Example #5
Source File: Request.java    From play_games with MIT License 5 votes vote down vote up
public void getIconImage() {
    PlayersClient playersClient = Games.getPlayersClient(registrar.activity(), currentAccount);
    playersClient.getCurrentPlayer().addOnSuccessListener(new OnSuccessListener<Player>() {
        @Override
        public void onSuccess(Player player) {
            readImage(player.getHiResImageUri());
        }
    });
}
 
Example #6
Source File: MainActivity.java    From android with Apache License 2.0 5 votes vote down vote up
@Override public void onSuccess(GoogleApiConnectionResult connectionResult) {
  signInButton.setVisibility(View.GONE);
  Player player = connectionResult.getPlayer();
  if (player == null) {
    Log.w(TAG, "gamesClient.getCurrentPlayer() is NULL!");
    displayName = "???";
  } else {
    displayName = player.getDisplayName();
  }
  Snackbar.make(mainContent, "Welcome, " + displayName, Snackbar.LENGTH_SHORT).show();
}
 
Example #7
Source File: MainMenuActivity.java    From tedroid with Apache License 2.0 5 votes vote down vote up
@Override
public void onSignInSucceeded() {
    super.onSignInSucceeded();
    signInLayout.setVisibility(View.GONE);
    achievementsButton.setVisibility(View.VISIBLE);
    leaderboardsButton.setVisibility(View.VISIBLE);
    signedUserLayout.setVisibility(View.VISIBLE);
    Player currentPlayer = Games.Players.getCurrentPlayer(getApiClient());
    signOutAlertDialog.setMessage(getString(R.string.sign_out_message, currentPlayer.getDisplayName()));
    signedUserTextView.setText(currentPlayer.getDisplayName());
    if (!isUserPhoto(signedUserImageView.getDrawable())) ImageManager.create(this).loadImage(signedUserImageView, currentPlayer.getIconImageUri());
}
 
Example #8
Source File: MainActivity.java    From android-basic-samples with Apache License 2.0 4 votes vote down vote up
private void onConnected(GoogleSignInAccount googleSignInAccount) {
  Log.d(TAG, "onConnected(): connected to Google APIs");

  mAchievementsClient = Games.getAchievementsClient(this, googleSignInAccount);
  mLeaderboardsClient = Games.getLeaderboardsClient(this, googleSignInAccount);
  mEventsClient = Games.getEventsClient(this, googleSignInAccount);
  mPlayersClient = Games.getPlayersClient(this, googleSignInAccount);

  // Show sign-out button on main menu
  mMainMenuFragment.setShowSignInButton(false);

  // Show "you are signed in" message on win screen, with no sign in button.
  mWinFragment.setShowSignInButton(false);

  // Set the greeting appropriately on main menu
  mPlayersClient.getCurrentPlayer()
      .addOnCompleteListener(new OnCompleteListener<Player>() {
        @Override
        public void onComplete(@NonNull Task<Player> task) {
          String displayName;
          if (task.isSuccessful()) {
            displayName = task.getResult().getDisplayName();
          } else {
            Exception e = task.getException();
            handleException(e, getString(R.string.players_exception));
            displayName = "???";
          }
          mMainMenuFragment.setGreeting("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();
  }

  loadAndPrintEvents();
}
 
Example #9
Source File: MainActivity.java    From android-basic-samples with Apache License 2.0 4 votes vote down vote up
private void onConnected(GoogleSignInAccount googleSignInAccount) {
  Log.d(TAG, "onConnected(): connected to Google APIs");
  if (mSignedInAccount != googleSignInAccount) {

    mSignedInAccount = googleSignInAccount;

    // update the clients
    mRealTimeMultiplayerClient = Games.getRealTimeMultiplayerClient(this, googleSignInAccount);
    mInvitationsClient = Games.getInvitationsClient(MainActivity.this, googleSignInAccount);

    // get the playerId from the PlayersClient
    PlayersClient playersClient = Games.getPlayersClient(this, googleSignInAccount);
    playersClient.getCurrentPlayer()
        .addOnSuccessListener(new OnSuccessListener<Player>() {
          @Override
          public void onSuccess(Player player) {
            mPlayerId = player.getPlayerId();

            switchToMainScreen();
          }
        })
        .addOnFailureListener(createFailureListener("There was a problem getting the player id!"));
  }

  // register listener so we are notified if we receive an invitation to play
  // while we are in the game
  mInvitationsClient.registerInvitationCallback(mInvitationCallback);

  // get the invitation from the connection hint
  // Retrieve the TurnBasedMatch from the connectionHint
  GamesClient gamesClient = Games.getGamesClient(MainActivity.this, googleSignInAccount);
  gamesClient.getActivationHint()
      .addOnSuccessListener(new OnSuccessListener<Bundle>() {
        @Override
        public void onSuccess(Bundle hint) {
          if (hint != null) {
            Invitation invitation =
                hint.getParcelable(Multiplayer.EXTRA_INVITATION);

            if (invitation != null && invitation.getInvitationId() != null) {
              // retrieve and cache the invitation ID
              Log.d(TAG, "onConnected: connection hint has a room invite!");
              acceptInviteToRoom(invitation.getInvitationId());
            }
          }
        }
      })
      .addOnFailureListener(createFailureListener("There was a problem getting the activation hint!"));
}
 
Example #10
Source File: SkeletonActivity.java    From android-basic-samples with Apache License 2.0 4 votes vote down vote up
private void onConnected(GoogleSignInAccount googleSignInAccount) {
  Log.d(TAG, "onConnected(): connected to Google APIs");

  mTurnBasedMultiplayerClient = Games.getTurnBasedMultiplayerClient(this, googleSignInAccount);
  mInvitationsClient = Games.getInvitationsClient(this, googleSignInAccount);

  Games.getPlayersClient(this, googleSignInAccount)
      .getCurrentPlayer()
      .addOnSuccessListener(
          new OnSuccessListener<Player>() {
            @Override
            public void onSuccess(Player player) {
              mDisplayName = player.getDisplayName();
              mPlayerId = player.getPlayerId();

              setViewVisibility();
            }
          }
      )
      .addOnFailureListener(createFailureListener("There was a problem getting the player!"));

  Log.d(TAG, "onConnected(): Connection successful");

  // Retrieve the TurnBasedMatch from the connectionHint
  GamesClient gamesClient = Games.getGamesClient(this, googleSignInAccount);
  gamesClient.getActivationHint()
      .addOnSuccessListener(new OnSuccessListener<Bundle>() {
        @Override
        public void onSuccess(Bundle hint) {
          if (hint != null) {
            TurnBasedMatch match = hint.getParcelable(Multiplayer.EXTRA_TURN_BASED_MATCH);

            if (match != null) {
              updateMatch(match);
            }
          }
        }
      })
      .addOnFailureListener(createFailureListener(
          "There was a problem getting the activation hint!"));

  setViewVisibility();

  // As a demonstration, we are registering this activity as a handler for
  // invitation and match events.

  // This is *NOT* required; if you do not register a handler for
  // invitation events, you will get standard notifications instead.
  // Standard notifications may be preferable behavior in many cases.
  mInvitationsClient.registerInvitationCallback(mInvitationCallback);

  // Likewise, we are registering the optional MatchUpdateListener, which
  // will replace notifications you would get otherwise. You do *NOT* have
  // to register a MatchUpdateListener.
  mTurnBasedMultiplayerClient.registerTurnBasedMatchUpdateCallback(mMatchUpdateCallback);
}