com.google.android.gms.games.leaderboard.LeaderboardScore Java Examples
The following examples show how to use
com.google.android.gms.games.leaderboard.LeaderboardScore.
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 |
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 #2
Source File: ExtensionContext.java From ANE-Google-Play-Game-Services with Apache License 2.0 | 6 votes |
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: Request.java From play_games with MIT License | 5 votes |
private Map<String, Object> scoreToMap(LeaderboardScore score) { Map<String, Object> data = new HashMap<>(); data.put("displayRank", score.getDisplayRank()); data.put("displayScore", score.getDisplayScore()); data.put("rank", score.getRank()); data.put("rawScore", score.getRawScore()); data.put("scoreTag", score.getScoreTag()); data.put("timestampMillis", score.getTimestampMillis()); data.put("scoreHolderDisplayName", score.getScoreHolderDisplayName()); return data; }
Example #4
Source File: Leaderboards.java From godot-gpgs with MIT License | 5 votes |
public void getLeaderboardValue(final String id) { if (googleApiClient == null || !googleApiClient.isConnected()) return; activity.runOnUiThread(new Runnable() { @Override public void run() { Games.Leaderboards.loadCurrentPlayerLeaderboardScore(googleApiClient, id, LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC).setResultCallback(new ResultCallback<LoadPlayerScoreResult>() { @Override public void onResult(LoadPlayerScoreResult result) { Status status = result.getStatus(); if (status.getStatusCode() == GamesStatusCodes.STATUS_OK) { LeaderboardScore score = result.getScore(); if (score != null) { int scoreValue = (int) score.getRawScore(); Log.d(TAG, "GPGS: Leaderboard values is " + score.getDisplayScore()); GodotLib.calldeferred(instance_id, "_on_leaderboard_get_value", new Object[]{ scoreValue, id }); } else { Log.d(TAG, "GPGS: getLeaderboardValue STATUS_OK but is NULL -> Request again..."); getLeaderboardValue(id); } } else if (status.getStatusCode() == GamesStatusCodes.STATUS_CLIENT_RECONNECT_REQUIRED) { Log.d(TAG, "GPGS: getLeaderboardValue reconnect required -> reconnecting..."); googleApiClient.reconnect(); } else { Log.d(TAG, "GPGS: getLeaderboardValue connection error -> " + status.getStatusMessage()); GodotLib.calldeferred(instance_id, "_on_leaderboard_get_value_error", new Object[]{ id }); } } }); Log.d(TAG, "GPGS: getLeaderboardValue '" + id + "'."); } }); }
Example #5
Source File: GameServicesHelper.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
private void processLoadScoreResult(LoadPlayerScoreResult result, String leaderboardId, int by, final Future<Boolean> future) { if (result.getStatus().isSuccess()) { LeaderboardScore score = result.getScore(); long current = score == null ? 0 : score.getRawScore(); Games.Leaderboards .submitScoreImmediate( helper.getApiClient(), leaderboardId, current + by ) .setResultCallback(new ResultCallback<Leaderboards.SubmitScoreResult>() { @Override public void onResult(Leaderboards.SubmitScoreResult submitResult) { final boolean success = submitResult.getStatus().isSuccess(); Gdx.app.postRunnable(new Runnable() { @Override public void run() { future.happen(success); } }); } }); } else { Gdx.app.postRunnable(new Runnable() { @Override public void run() { future.happen(false); } }); } }
Example #6
Source File: GpgsClient.java From gdx-gamesvcs with Apache License 2.0 | 4 votes |
private boolean fetchLeaderboardEntriesSync(String leaderBoardId, int limit, boolean relatedToPlayer, IFetchLeaderBoardEntriesResponseListener callback) { if (!isSessionActive()) return false; if (gpgsLeaderboardIdMapper != null) leaderBoardId = gpgsLeaderboardIdMapper.mapToGsId(leaderBoardId); Leaderboards.LoadScoresResult scoresResult = (relatedToPlayer ? Games.Leaderboards.loadPlayerCenteredScores(mGoogleApiClient, leaderBoardId, LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC, MathUtils.clamp(limit, 1, 25), forceRefresh).await() : Games.Leaderboards.loadTopScores(mGoogleApiClient, leaderBoardId, LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC, MathUtils.clamp(limit, 1, 25), forceRefresh).await()); if (!scoresResult.getStatus().isSuccess()) { Gdx.app.log(GAMESERVICE_ID, "Failed to fetch leaderboard entries:" + scoresResult.getStatus().getStatusMessage()); callback.onLeaderBoardResponse(null); return false; } LeaderboardScoreBuffer scores = scoresResult.getScores(); Array<ILeaderBoardEntry> gpgsLbEs = new Array<ILeaderBoardEntry>(scores.getCount()); String playerDisplayName = getPlayerDisplayName(); for (LeaderboardScore score : scores) { GpgsLeaderBoardEntry gpgsLbE = new GpgsLeaderBoardEntry(); gpgsLbE.userDisplayName = score.getScoreHolderDisplayName(); gpgsLbE.currentPlayer = gpgsLbE.userDisplayName.equalsIgnoreCase(playerDisplayName); gpgsLbE.formattedValue = score.getDisplayScore(); gpgsLbE.scoreRank = score.getDisplayRank(); gpgsLbE.userId = score.getScoreHolder().getPlayerId(); gpgsLbE.sortValue = score.getRawScore(); gpgsLbE.scoreTag = score.getScoreTag(); gpgsLbEs.add(gpgsLbE); } scores.release(); callback.onLeaderBoardResponse(gpgsLbEs); return true; }