本文整理汇总了Java中com.google.android.gms.games.leaderboard.LeaderboardVariant类的典型用法代码示例。如果您正苦于以下问题:Java LeaderboardVariant类的具体用法?Java LeaderboardVariant怎么用?Java LeaderboardVariant使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LeaderboardVariant类属于com.google.android.gms.games.leaderboard包,在下文中一共展示了LeaderboardVariant类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: googleShowLeaderboard
import com.google.android.gms.games.leaderboard.LeaderboardVariant; //导入依赖的package包/类
@Override
public void googleShowLeaderboard(final String leaderboardID)
{
googleRunLoggingIn(new Runnable()
{
@Override
public void run()
{
Intent leaderboardIntent = Games.Leaderboards.getLeaderboardIntent(
AndroidServices.this.gameHelper.getApiClient(),
leaderboardID,
LeaderboardVariant.TIME_SPAN_ALL_TIME,
LeaderboardVariant.COLLECTION_PUBLIC);
AndroidServices.this.activity.startActivityForResult(
leaderboardIntent,
AndroidServices.this.activityRequestCode);
}
});
}
示例2: incrementScore
import com.google.android.gms.games.leaderboard.LeaderboardVariant; //导入依赖的package包/类
@Override public IFuture<Boolean> incrementScore(final String leaderboardId, final int by) {
final Future<Boolean> future = Future.make();
activity.getMainHandler().post(new Runnable() {
@Override public void run() {
Games.Leaderboards
.loadCurrentPlayerLeaderboardScore(
helper.getApiClient(),
leaderboardId,
LeaderboardVariant.TIME_SPAN_WEEKLY,
LeaderboardVariant.COLLECTION_PUBLIC
)
.setResultCallback(new ResultCallback<LoadPlayerScoreResult>() {
@Override public void onResult(LoadPlayerScoreResult result) {
processLoadScoreResult(result, leaderboardId, by, future);
}
});
}
});
return future;
}
示例3: submitScore
import com.google.android.gms.games.leaderboard.LeaderboardVariant; //导入依赖的package包/类
@Override
public void submitScore(String leaderboardId, long value, final GameServicesCallbacks.SuccessWithScoreListener submitScoreListener) {
if (enableGameServices) {
Games.Leaderboards.submitScoreImmediate(googleApiClient, leaderboardId, value).setResultCallback(new ResultCallback<Leaderboards.SubmitScoreResult>() {
@Override
public void onResult(Leaderboards.SubmitScoreResult submitScoreResult) {
if (submitScoreResult.getStatus().isSuccess()) {
submitScoreListener.success(
new Score(
new Leaderboard(submitScoreResult.getScoreData().getLeaderboardId(), getProvider(), "", ""), // here is no iconURL and title at this moment
0, // rank is undefined here
SoomlaProfile.getInstance().getStoredUserProfile(getProvider()),
submitScoreResult.getScoreData().getScoreResult(LeaderboardVariant.TIME_SPAN_ALL_TIME).rawScore
)
);
} else {
submitScoreListener.fail(submitScoreResult.getStatus().getStatusMessage());
}
}
});
} else {
submitScoreListener.fail("To use GPGS features, please set `enableGameServices = true` in Google provider initialization parameters.");
}
}
示例4: loadScoreOfLeaderBoardIfLarger
import com.google.android.gms.games.leaderboard.LeaderboardVariant; //导入依赖的package包/类
private void loadScoreOfLeaderBoardIfLarger(final String leaderboardId, final int currentScore, final String gameDifficulty) {
Games.Leaderboards.loadCurrentPlayerLeaderboardScore(mGoogleApiClient, leaderboardId, LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC).setResultCallback(new ResultCallback<Leaderboards.LoadPlayerScoreResult>() {
@Override
public void onResult(final Leaderboards.LoadPlayerScoreResult scoreResult) {
if (isScoreResultValid(scoreResult)) {
// here you can get the score like this
int score = (int) scoreResult.getScore().getRawScore();
if (score > currentScore) {
SharedPreferences.Editor editor = getSharedPreferences(ResultsActivity.PREF_NAME, MODE_PRIVATE).edit();
editor.putInt(ResultsActivity.SCORE_PREFIX + gameDifficulty, score);
editor.apply();
}
}
}
});
}
示例5: showLeaderList
import com.google.android.gms.games.leaderboard.LeaderboardVariant; //导入依赖的package包/类
public void showLeaderList(final String id) {
if (googleApiClient == null || !googleApiClient.isConnected()) return;
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (googleApiClient != null && googleApiClient.isConnected()) {
activity.startActivityForResult(Games.Leaderboards.getLeaderboardIntent(googleApiClient, id, LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC), REQUEST_LEADERBOARD);
Log.d(TAG, "GPGS: showLeaderList.");
}
}
});
}
示例6: getLeaderboardValue
import com.google.android.gms.games.leaderboard.LeaderboardVariant; //导入依赖的package包/类
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 + "'.");
}
});
}
示例7: showLeaderboard
import com.google.android.gms.games.leaderboard.LeaderboardVariant; //导入依赖的package包/类
@Override public void showLeaderboard(final String leaderboardId) {
activity.getMainHandler().post(new Runnable() {
@Override public void run() {
Intent intent = Games.Leaderboards.getLeaderboardIntent(
helper.getApiClient(),
leaderboardId,
LeaderboardVariant.TIME_SPAN_WEEKLY
);
activity.startActivityForResult(intent, LEADERBOARD_REQUEST_CODE);
}
});
}
示例8: getPlayerRecord
import com.google.android.gms.games.leaderboard.LeaderboardVariant; //导入依赖的package包/类
@Override
public int getPlayerRecord() {
final AtomicBoolean found = new AtomicBoolean();
Games.Leaderboards.loadPlayerCenteredScores(aHelper.getApiClient(), Leaderboard.MOST_POINTS, 1,
1,
25).setResultCallback(new ResultCallback<Leaderboards.LoadScoresResult>() {
@Override
public void onResult(Leaderboards.LoadScoresResult arg0) {
found.set(true);
}
});
while (!found.get()) {
}
found.set(false);
final AtomicLong score = new AtomicLong(0);
Games.Leaderboards.loadCurrentPlayerLeaderboardScore(aHelper.getApiClient(), Leaderboard.MOST_POINTS, LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC).setResultCallback(new ResultCallback<Leaderboards.LoadPlayerScoreResult>() {
@Override
public void onResult(Leaderboards.LoadPlayerScoreResult result) {
if (result != null && result.getScore() != null) {
LeaderboardScore lbScore = result.getScore();
score.set(lbScore.getRawScore());
}
found.set(true);
}
});
while (!found.get()) {
}
return Math.round(score.get());
}
示例9: refreshNumber
import com.google.android.gms.games.leaderboard.LeaderboardVariant; //导入依赖的package包/类
public void refreshNumber() {
if (!isChallenge) {
int maxDigits = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(this).getString("digits", "3")) - 1;
goal = (int) (rand.nextDouble() * 0.9 * Math.pow(10, maxDigits) + Math.pow(10, maxDigits - 1));
} else {
goal = LeaderboardManager.getInstance(this).getRandomGoalNumber(PreferenceManager.getDefaultSharedPreferences(this).getInt("rounds_finished", 0));
}
gameFrag.setGoal(goal);
recordTime = 0;
Runnable r = new Runnable() {
@Override
public void run() {
String id = LeaderboardManager.getInstance(GameActivity.this).getIdForGoal(goal);
PendingResult<LoadScoresResult> result = Games.Leaderboards.loadTopScores(helper.getApiClient(), id, LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC, 1);
result.setResultCallback(new ResultCallback<Leaderboards.LoadScoresResult>() {
@Override
public void onResult(LoadScoresResult arg0) {
if (arg0.getScores().getCount() > 0) {
recordTime = arg0.getScores().get(0).getRawScore() / 1000.0;
} else {
recordTime = -10;
}
}
});
}
};
if (isChallenge && PreferenceManager.getDefaultSharedPreferences(this).getBoolean("sign_in", true)) {
if (helper != null && helper.isSignedIn()) {
r.run();
} else if (helper != null) {
onSignIn.add(r);
}
}
gameFrag.setIsChallenge(isChallenge);
}
示例10: getLeaderboard
import com.google.android.gms.games.leaderboard.LeaderboardVariant; //导入依赖的package包/类
public void getLeaderboard( String leaderboardId ) {
Games.Leaderboards.loadTopScores(
getApiClient(),
leaderboardId,
LeaderboardVariant.TIME_SPAN_ALL_TIME,
LeaderboardVariant.COLLECTION_SOCIAL,
25,
true
).setResultCallback(new ScoresLoadedListener());
}
示例11: issueLeaderboardRefresh
import com.google.android.gms.games.leaderboard.LeaderboardVariant; //导入依赖的package包/类
public void issueLeaderboardRefresh() {
if (isSignedIn() && mGamesClient != null) {
if (mGLView != null && mGLView.mRenderer != null) {
mGamesClient.submitScore(LEADERBOARD_ID, mGLView.mRenderer.mCaughtCounter);
}
mGamesClient.loadPlayerCenteredScores(this, LEADERBOARD_ID, 2, LeaderboardVariant.COLLECTION_PUBLIC, 10, true);
}
}
开发者ID:d3alek,项目名称:TheHunt---Interactive-graphical-platform-for-AI-Experiments,代码行数:9,代码来源:TheHunt.java
示例12: incrementScore
import com.google.android.gms.games.leaderboard.LeaderboardVariant; //导入依赖的package包/类
/**
* Increments current score to leaderboard
* @param pLeaderboard
* @param pScore
*/
public void incrementScore(final String pLeaderboard, final long pScore){
if(isSignedIn() == false)
return;
final String playerId = getGamesClient().getCurrentPlayer().getPlayerId();
//Toast.makeText(this, "increment " + playerId, Toast.LENGTH_LONG).show();
getGamesClient().loadPlayerCenteredScores(new OnLeaderboardScoresLoadedListener() {
@Override
public void onLeaderboardScoresLoaded(int arg0, LeaderboardBuffer arg1, LeaderboardScoreBuffer arg2) {
Iterator <LeaderboardScore> it =arg2.iterator();
//Toast.makeText(ActivityBaseGameLeaderboard.this, "on score loaded", Toast.LENGTH_LONG).show();
if(it.hasNext() == false){
//Toast.makeText(ActivityBaseGameLeaderboard.this, "first submit", Toast.LENGTH_LONG).show();
submitScore(pLeaderboard, pScore);
return;
}
while(it.hasNext()){
LeaderboardScore lbScore = it.next();
long score = lbScore.getRawScore();
//Toast.makeText(ActivityBaseGameLeaderboard.this, score + " " + lbScore.getScoreHolder().getPlayerId(), Toast.LENGTH_LONG).show();
if(lbScore.getScoreHolder().getPlayerId().equals(playerId)){
submitScore(pLeaderboard, pScore + score);
}
}
}
}, pLeaderboard, LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC, 1);
}
示例13: fetchLeaderboardEntriesSync
import com.google.android.gms.games.leaderboard.LeaderboardVariant; //导入依赖的package包/类
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.loadTopScores(mGoogleApiClient, leaderBoardId,
LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC,
MathUtils.clamp(limit, 1, 25), forceRefresh).await()
:
Games.Leaderboards.loadPlayerCenteredScores(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;
}
示例14: onLeaderboardMetadataLoaded
import com.google.android.gms.games.leaderboard.LeaderboardVariant; //导入依赖的package包/类
@Override
public void onLeaderboardMetadataLoaded (int statusCode, LeaderboardBuffer leaderboard){
JSONObject json = new JSONObject();
try{
json.put("type", GAME_LEADERBOARD_METADATA_LOADED);
json.put("statusCode", statusCode);
switch (statusCode) {
case GamesClient.STATUS_OK:
// if data was successfully loaded and is up-to-date.
JSONArray list = new JSONArray();
JSONObject obj;
JSONArray vList;
JSONObject v;
Leaderboard lb;
ArrayList<LeaderboardVariant> variants;
LeaderboardVariant variant;
int i, l, j, k;
for(i=0,l=leaderboard.getCount();i<l;i++){
obj = new JSONObject();
lb = leaderboard.get(i);
obj.put("displayName", lb.getDisplayName());
Uri uri = lb.getIconImageUri();
if (null != uri)
obj.put("iconImageUri", uri.getScheme() + ':' + uri.getSchemeSpecificPart());
obj.put("leaderboardId", lb.getLeaderboardId());
obj.put("scoreOrder", lb.getScoreOrder());
variants = lb.getVariants();
vList = new JSONArray();
for(j=0,k=variants.size();j<k;j++){
v = new JSONObject();
variant = variants.get(i);
v.put("collection", variant.getCollection());
v.put("numScores", variant.getNumScores());
v.put("timeSpan", variant.getTimeSpan());
v.put("hasPlayerInfo", variant.hasPlayerInfo());
if(variant.hasPlayerInfo()){
v.put("displayPlayerRank", variant.getDisplayPlayerRank());
v.put("displayPlayerScore", variant.getDisplayPlayerScore());
v.put("playerRank", variant.getPlayerRank());
v.put("rawPlayerScore", variant.getRawPlayerScore());
}
vList.put(v);
obj.put("variants", vList);
}
list.put(obj);
}
json.put("leaderboard", list);
break;
case GamesClient.STATUS_INTERNAL_ERROR:
// if an unexpected error occurred in the service
break;
case GamesClient.STATUS_NETWORK_ERROR_STALE_DATA:
// if the device was unable to communicate with the network. in this case, the operation is not retried automatically.
break;
case GamesClient.STATUS_CLIENT_RECONNECT_REQUIRED:
// need to reconnect GamesClient
mHelper.reconnectClients(clientTypes);
break;
case GamesClient.STATUS_LICENSE_CHECK_FAILED:
// the game is not licensed to the user. further calls will return the same code.
break;
default:
// error
break;
}
}catch(JSONException ex){
Log.e(TAG, "game_leaderboard_scores_loaded ["+statusCode+"] exception: "+ex.getMessage());
return;
}
leaderboard.close();
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, json);
pluginResult.setKeepCallback(true);
connectionCB.sendPluginResult(pluginResult);
}
示例15: onScoreSubmitted
import com.google.android.gms.games.leaderboard.LeaderboardVariant; //导入依赖的package包/类
@Override
public void onScoreSubmitted (int statusCode, SubmitScoreResult result){
JSONObject json = new JSONObject();
try{
json.put("type", GAME_SCORES_SUBMITTED);
json.put("statusCode", statusCode);
switch (statusCode) {
case GamesClient.STATUS_OK:
// if data was successfully loaded and is up-to-date.
json.put("leaderboardId", result.getLeaderboardId());
json.put("playerId", result.getPlayerId());
json.put("resultStatusCode", result.getStatusCode());
SubmitScoreResult.Result timeResult = result.getScoreResult(LeaderboardVariant.TIME_SPAN_ALL_TIME);
JSONObject r = new JSONObject();
r.put("formattedScore", timeResult.formattedScore);
r.put("newBest", timeResult.newBest);
r.put("rawScore", timeResult.rawScore);
json.put("timeResult", r);
timeResult = result.getScoreResult(LeaderboardVariant.TIME_SPAN_WEEKLY);
r = new JSONObject();
r.put("formattedScore", timeResult.formattedScore);
r.put("newBest", timeResult.newBest);
r.put("rawScore", timeResult.rawScore);
json.put("weekly", r);
timeResult = result.getScoreResult(LeaderboardVariant.TIME_SPAN_DAILY);
r = new JSONObject();
r.put("formattedScore", timeResult.formattedScore);
r.put("newBest", timeResult.newBest);
r.put("rawScore", timeResult.rawScore);
json.put("daily", r);
break;
case GamesClient.STATUS_INTERNAL_ERROR:
// if an unexpected error occurred in the service
break;
case GamesClient.STATUS_NETWORK_ERROR_OPERATION_DEFERRED:
// if the device is offline or was otherwise unable to post the score to the server. The score was stored locally and will be posted to the server the next time the device is online and is able to perform a sync (no further action is required from the client).
break;
case GamesClient.STATUS_CLIENT_RECONNECT_REQUIRED:
// need to reconnect GamesClient
mHelper.reconnectClients(clientTypes);
break;
case GamesClient.STATUS_LICENSE_CHECK_FAILED:
// The game is not licensed to the user. Further calls will return the same code.
break;
default:
// error
break;
}
}catch(JSONException ex){
Log.e(TAG, "GAME_SCORES_SUBMITTED ["+statusCode+"] exception: "+ex.getMessage());
return;
}
PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, json);
pluginResult.setKeepCallback(true);
connectionCB.sendPluginResult(pluginResult);
}