Java Code Examples for com.google.android.gms.games.Games#getLeaderboardsClient()

The following examples show how to use com.google.android.gms.games.Games#getLeaderboardsClient() . 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: Request.java    From play_games with MIT License 6 votes vote down vote up
public void submitScore(String leaderboardId, Long score) {
    Log.i(TAG, "Submitting leaderboard, id: " + leaderboardId + "; score: " + score);
    LeaderboardsClient leaderboardsClient = Games.getLeaderboardsClient(this.registrar.activity(), currentAccount);
    leaderboardsClient.submitScoreImmediate(leaderboardId, score).addOnSuccessListener(new OnSuccessListener<ScoreSubmissionData>() {
        @Override
        public void onSuccess(ScoreSubmissionData data) {
            Map<String, Object> successMap = new HashMap<>();
            successMap.put("type", "SUCCESS");
            successMap.put("leaderboardId", data.getLeaderboardId());
            successMap.put("playerId", data.getPlayerId());
            successMap.put("scoreResultDaily", resultToMap(data.getScoreResult(LeaderboardVariant.TIME_SPAN_DAILY)));
            successMap.put("scoreResultWeekly", resultToMap(data.getScoreResult(LeaderboardVariant.TIME_SPAN_WEEKLY)));
            successMap.put("scoreResultAllTime", resultToMap(data.getScoreResult(LeaderboardVariant.TIME_SPAN_ALL_TIME)));
            result(successMap);
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            Log.e(TAG, "Could not submit leadderboard", e);
            error("LEADERBOARD_SUBMIT_FAILURE", e);
        }
    });
}
 
Example 2
Source File: Request.java    From play_games with MIT License 5 votes vote down vote up
public void loadPlayerCenteredScores(String leaderboardId, String timeSpan, String collectionType, int maxResults, boolean forceReload) {
    LeaderboardsClient leaderboardsClient = Games.getLeaderboardsClient(this.registrar.activity(), currentAccount);
    leaderboardsClient.loadPlayerCenteredScores(leaderboardId, convertTimeSpan(timeSpan), convertCollection(collectionType), maxResults, forceReload)
            .addOnSuccessListener(scoreSuccessHandler())
            .addOnFailureListener(new OnFailureListener() {
                                      @Override
                                      public void onFailure(@NonNull Exception e) {
                                          Log.e(TAG, "Could not fetch leaderboard player centered (retrieve failure)", e);
                                          error("LEADERBOARD_PLAYER_CENTERED_FAILURE", e);
                                      }
                                  }
            );
}
 
Example 3
Source File: Request.java    From play_games with MIT License 5 votes vote down vote up
public void loadTopScores(String leaderboardId, String timeSpan, String collectionType, int maxResults, boolean forceReload) {
    LeaderboardsClient leaderboardsClient = Games.getLeaderboardsClient(this.registrar.activity(), currentAccount);
    leaderboardsClient.loadTopScores(leaderboardId, convertTimeSpan(timeSpan), convertCollection(collectionType), maxResults, forceReload)
            .addOnSuccessListener(scoreSuccessHandler())
            .addOnFailureListener(new OnFailureListener() {
                                      @Override
                                      public void onFailure(@NonNull Exception e) {
                                          Log.e(TAG, "Could not fetch leaderboard top scores (retrieve failure)", e);
                                          error("LEADERBOARD_TOP_SCORES_FAILURE", e);
                                      }
                                  }
            );
}
 
Example 4
Source File: ShortyzActivity.java    From shortyz with GNU General Public License v3.0 5 votes vote down vote up
private void onConnected(GoogleSignInAccount googleSignInAccount) {
	Log.d(TAG, "onConnected(): connected to Google APIs");

	this.mAchievementsClient = Games.getAchievementsClient(this, googleSignInAccount);
	this.mLeaderboardsClient = Games.getLeaderboardsClient(this, googleSignInAccount);
	this.onSignInSucceeded();
}
 
Example 5
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();
}