com.google.android.gms.games.leaderboard.LeaderboardScoreBuffer Java Examples

The following examples show how to use com.google.android.gms.games.leaderboard.LeaderboardScoreBuffer. 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: 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 #2
Source File: ScoresLoadedListener.java    From ANE-Google-Play-Game-Services with Apache License 2.0 5 votes vote down vote up
public void onResult( Leaderboards.LoadScoresResult scoresResult ) {


        LeaderboardScoreBuffer scores = scoresResult.getScores();

        if( scores.getCount() == currentBufferSize ) {
            Extension.context.onLeaderboardLoaded(scores);
        }
        else {
            currentBufferSize = scores.getCount();
            Games.Leaderboards.loadMoreScores( Extension.context.getApiClient(), scores, 25, PageDirection.NEXT ).setResultCallback( this );
        }

    }
 
Example #3
Source File: GpgsClient.java    From gdx-gamesvcs with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example #4
Source File: ExtensionContext.java    From ANE-Google-Play-Game-Services with Apache License 2.0 4 votes vote down vote up
public void onLeaderboardLoaded( LeaderboardScoreBuffer scores ) {
    dispatchEvent( "ON_LEADERBOARD_LOADED", scoresToJsonString(scores) );
}