com.google.android.gms.games.LeaderboardsClient Java Examples
The following examples show how to use
com.google.android.gms.games.LeaderboardsClient.
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 |
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 | 6 votes |
private OnSuccessListener<AnnotatedData<LeaderboardsClient.LeaderboardScores>> scoreSuccessHandler() { return new OnSuccessListener<AnnotatedData<LeaderboardsClient.LeaderboardScores>>() { @Override public void onSuccess(AnnotatedData<LeaderboardsClient.LeaderboardScores> data) { LeaderboardsClient.LeaderboardScores scores = data.get(); Map<String, Object> successMap = new HashMap<>(); successMap.put("type", "SUCCESS"); successMap.put("leaderboardDisplayName", scores.getLeaderboard().getDisplayName()); List<Map<String, Object>> list = new ArrayList<>(); Iterator<LeaderboardScore> it = scores.getScores().iterator(); while (it.hasNext()) { list.add(scoreToMap(it.next())); } successMap.put("scores", list); scores.release(); result(successMap); } }; }
Example #3
Source File: Request.java From play_games with MIT License | 5 votes |
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 #4
Source File: Request.java From play_games with MIT License | 5 votes |
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); } } ); }