com.google.android.gms.games.GamesStatusCodes Java Examples
The following examples show how to use
com.google.android.gms.games.GamesStatusCodes.
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: Leaderboards.java From godot-gpgs with MIT License | 6 votes |
public void leaderSubmit(final String id, final int score) { if (googleApiClient == null || !googleApiClient.isConnected()) return; activity.runOnUiThread(new Runnable() { @Override public void run() { Games.Leaderboards.submitScoreImmediate(googleApiClient, id, score).setResultCallback(new ResultCallback<SubmitScoreResult>() { @Override public void onResult(SubmitScoreResult result) { Status status = result.getStatus(); if (status.getStatusCode() == GamesStatusCodes.STATUS_OK) { Log.d(TAG, "GPGS: leaderSubmit OK"); GodotLib.calldeferred(instance_id, "_on_google_play_game_services_leaderboard_submitted_ok", new Object[] { id }); } else if (status.getStatusCode() == GamesStatusCodes.STATUS_CLIENT_RECONNECT_REQUIRED) { Log.d(TAG, "GPGS: leaderSubmit reconnect required -> reconnecting..."); googleApiClient.reconnect(); } else { Log.d(TAG, "GPGS: leaderSubmit connection error -> " + status.getStatusMessage()); GodotLib.calldeferred(instance_id, "_on_leaderboard_submit_error", new Object[]{ id }); } } }); Log.d(TAG, "GPGS: leaderSubmit '" + id + "' by " + score + "."); } }); }
Example #2
Source File: GoogleCloudSave.java From dice-heroes with GNU General Public License v3.0 | 6 votes |
private void processOpenSnapshotResult(OpenSnapshotResult result, final UserData userData, IConflictResolver resolver) { final Snapshot snapshot = result.getSnapshot(); if (result.getStatus().isSuccess()) { final SnapshotContents contents = snapshot.getSnapshotContents(); final Map server = fromBytes(contents); if (server != null && server.containsKey("uuid") && !server.get("uuid").equals(userData.uuid())) { performUserResolve(server, resolver, new IConflictResolverCallback() { @Override public void onResolved(boolean useLocal) { contents.writeBytes(useLocal ? toBytes(userData) : toBytes(server)); Games.Snapshots.commitAndClose(client, snapshot, EMPTY_CHANGE); } }); } else { contents.writeBytes(toBytes(userData)); Games.Snapshots.commitAndClose(client, snapshot, EMPTY_CHANGE); } } else if (result.getStatus().getStatusCode() == GamesStatusCodes.STATUS_SNAPSHOT_CONFLICT) { Snapshot conflictingSnapshot = result.getConflictingSnapshot(); startResolving(userData, conflictingSnapshot, result.getConflictId(), resolver); } }
Example #3
Source File: GoogleCloudSave.java From dice-heroes with GNU General Public License v3.0 | 6 votes |
private void startResolving(final UserData userData, final Snapshot conflictingSnapshot, final String conflictId, final IConflictResolver resolver) { final SnapshotContents contents = conflictingSnapshot.getSnapshotContents(); final Map server = fromBytes(contents); if (server == null) { contents.writeBytes(toBytes(userData)); Games.Snapshots.resolveConflict(client, conflictId, SNAPSHOT_ID, EMPTY_CHANGE, contents); return; } performUserResolve(server, resolver, new IConflictResolverCallback() { @SuppressWarnings("unchecked") @Override public void onResolved(boolean useLocal) { contents.writeBytes(useLocal ? toBytes(userData) : toBytes(server)); Games.Snapshots .resolveConflict(client, conflictId, SNAPSHOT_ID, EMPTY_CHANGE, contents) .setResultCallback(new ResultCallback<OpenSnapshotResult>() { @Override public void onResult(OpenSnapshotResult result) { if (result.getStatus().getStatusCode() == GamesStatusCodes.STATUS_SNAPSHOT_CONFLICT) { startResolving(userData, result.getConflictingSnapshot(), result.getConflictId(), resolver); } } }); } }); }
Example #4
Source File: GpgsClient.java From gdx-gamesvcs with Apache License 2.0 | 5 votes |
/** * Conflict resolution for when Snapshots are opened. Must be run in an AsyncTask or in a * background thread, */ public Snapshot processSnapshotOpenResult(Snapshots.OpenSnapshotResult result, int retryCount) { Snapshot mResolvedSnapshot = null; retryCount++; int status = result.getStatus().getStatusCode(); Gdx.app.log(GAMESERVICE_ID, "Open Snapshot Result status: " + result.getStatus().getStatusMessage()); if (status == GamesStatusCodes.STATUS_OK) { return result.getSnapshot(); } else if (status == GamesStatusCodes.STATUS_SNAPSHOT_CONFLICT) { Snapshot snapshot = result.getSnapshot(); Snapshot conflictSnapshot = result.getConflictingSnapshot(); // Resolve between conflicts by selecting the highest progress or, if equal, newest of the conflicting // snapshots. mResolvedSnapshot = snapshot; if (snapshot.getMetadata().getProgressValue() < conflictSnapshot.getMetadata().getProgressValue() || snapshot.getMetadata().getProgressValue() == conflictSnapshot.getMetadata().getProgressValue() && snapshot.getMetadata().getLastModifiedTimestamp() < conflictSnapshot.getMetadata().getLastModifiedTimestamp()) { mResolvedSnapshot = conflictSnapshot; } Snapshots.OpenSnapshotResult resolveResult = Games.Snapshots.resolveConflict( mGoogleApiClient, result.getConflictId(), mResolvedSnapshot).await(); if (retryCount < MAX_SNAPSHOT_RESOLVE_RETRIES) { // Recursively attempt again return processSnapshotOpenResult(resolveResult, retryCount); } } // Fail, return null. return null; }
Example #5
Source File: RealTimeMultiplayer.java From godot-gpgs with MIT License | 5 votes |
@Override public void onRoomConnected(int statusCode, Room room) { Log.d(TAG, "onRoomConnected(" + statusCode + ", " + room + ")"); if (statusCode != GamesStatusCodes.STATUS_OK) { Log.e(TAG, "*** Error: onRoomConnected, status " + statusCode); showGameError(); return; } updateRoom(room); }
Example #6
Source File: RealTimeMultiplayer.java From godot-gpgs with MIT License | 5 votes |
@Override public void onRoomCreated(int statusCode, Room room) { Log.d(TAG, "onRoomCreated(" + statusCode + ", " + room + ")"); if (statusCode != GamesStatusCodes.STATUS_OK) { Log.e(TAG, "*** Error: onRoomCreated, status " + statusCode); showGameError(); return; } // save room ID so we can leave cleanly before the game starts. roomId = room.getRoomId(); // show the waiting room UI showWaitingRoom(room); }
Example #7
Source File: RealTimeMultiplayer.java From godot-gpgs with MIT License | 5 votes |
@Override public void onJoinedRoom(int statusCode, Room room) { Log.d(TAG, "onJoinedRoom(" + statusCode + ", " + room + ")"); if (statusCode != GamesStatusCodes.STATUS_OK) { Log.e(TAG, "*** Error: onRoomConnected, status " + statusCode); showGameError(); return; } // show the waiting room UI showWaitingRoom(room); }
Example #8
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 #9
Source File: RoomController.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
@Override public void onRoomCreated(final int statusCode, final Room room) { this.room = room; Logger.log("room created, status ok: " + (statusCode == GamesStatusCodes.STATUS_OK)); if (statusCode != GamesStatusCodes.STATUS_OK) { Gdx.app.postRunnable(new Runnable() { @Override public void run() { die(false, Config.thesaurus.localize("disconnect-game-services-error")); } }); } else { multiplayer.showWaitingRoom(room); } }
Example #10
Source File: RoomController.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
@Override public void onJoinedRoom(final int statusCode, final Room room) { this.room = room; Logger.log("joined room, status ok: " + (statusCode == GamesStatusCodes.STATUS_OK)); if (statusCode != GamesStatusCodes.STATUS_OK) { Gdx.app.postRunnable(new Runnable() { @Override public void run() { die(false, Config.thesaurus.localize("disconnect-game-services-error")); } }); } else { multiplayer.showWaitingRoom(room); } }
Example #11
Source File: RoomController.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
@Override public void onLeftRoom(final int statusCode, final String roomId) { Logger.log("left room, status ok: " + (statusCode == GamesStatusCodes.STATUS_OK)); Gdx.app.postRunnable(new Runnable() { @Override public void run() { if (statusCode != GamesStatusCodes.STATUS_OK) { die(false, Config.thesaurus.localize("disconnect-game-services-error")); } else { session.disconnect(false); } } }); }
Example #12
Source File: RoomController.java From dice-heroes with GNU General Public License v3.0 | 5 votes |
@Override public void onRoomConnected(final int statusCode, final Room room) { Logger.log("room connected, status ok: " + (statusCode == GamesStatusCodes.STATUS_OK)); if (statusCode != GamesStatusCodes.STATUS_OK) { die(false, Config.thesaurus.localize("disconnect-game-services-error")); return; } RoomController.this.room = room; session.setVariant(room.getVariant()); String playerId = room.getParticipantId(Games.Players.getCurrentPlayerId(multiplayer.client)); for (Participant participant : room.getParticipants()) { if (participant.getStatus() != Participant.STATUS_JOINED) continue; if (participant.getParticipantId().equals(playerId)) { me = new MultiplayerParticipant(participant); } else { others.add(new MultiplayerParticipant(participant)); } } all.put(me.getId(), me); for (MultiplayerParticipant p : others) { all.put(p.getId(), p); } publicOthers = new ObjectSet<IParticipant>(others); publicAll = new ObjectMap<String, IParticipant>(all); multiplayer.updateInvites(); Logger.log(" - room: " + RoomController.this.toString(room)); }
Example #13
Source File: DrawingActivity.java From 8bitartist with Apache License 2.0 | 5 votes |
@Override public void onRoomCreated(int statusCode, Room room) { Log.d(TAG, "onRoomCreated: " + statusCode + ":" + room); if (statusCode != GamesStatusCodes.STATUS_OK) { Log.w(TAG, "Error in onRoomCreated: " + statusCode); Toast.makeText(this, "Error creating room.", Toast.LENGTH_SHORT).show(); dismissSpinner(); return; } showWaitingRoom(room); }
Example #14
Source File: DrawingActivity.java From 8bitartist with Apache License 2.0 | 5 votes |
@Override public void onRoomConnected(int statusCode, Room room) { Log.d(TAG, "onRoomConnected: " + statusCode + ":" + room); if (statusCode != GamesStatusCodes.STATUS_OK) { Log.w(TAG, "Error in onRoomConnected: " + statusCode); return; } mRoom = room; updateViewVisibility(); }
Example #15
Source File: Main.java From chess with Apache License 2.0 | 4 votes |
@Override public void onActivityResult(int request, int response, final Intent data) { super.onActivityResult(request, response, data); if (BuildConfig.DEBUG) Logger.log("Main onActivityResult"); if (response == GamesActivityResultCodes.RESULT_RECONNECT_REQUIRED && !mGoogleApiClient.isConnected() && !mGoogleApiClient.isConnecting()) { mGoogleApiClient.connect(); } else if (response == Activity.RESULT_CANCELED) { // User cancelled. mGoogleApiClient.disconnect(); } else if (response == Activity.RESULT_OK) { if (request == RC_SELECT_PLAYERS) { // get the invitee list final ArrayList<String> invitees = data.getStringArrayListExtra(Games.EXTRA_PLAYER_IDS); // get auto-match criteria Bundle autoMatchCriteria; int minAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MIN_AUTOMATCH_PLAYERS, 0); int maxAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MAX_AUTOMATCH_PLAYERS, 0); if (minAutoMatchPlayers > 0) { autoMatchCriteria = RoomConfig .createAutoMatchCriteria(minAutoMatchPlayers, maxAutoMatchPlayers, 0); } else { autoMatchCriteria = null; } TurnBasedMatchConfig tbmc = TurnBasedMatchConfig.builder().addInvitedPlayers(invitees) .setAutoMatchCriteria(autoMatchCriteria) .setVariant(StartFragment.LAST_SELECTED_MATCH_MODE).build(); // kick the match off Games.TurnBasedMultiplayer.createMatch(mGoogleApiClient, tbmc).setResultCallback( new ResultCallback<TurnBasedMultiplayer.InitiateMatchResult>() { @Override public void onResult(final TurnBasedMultiplayer.InitiateMatchResult result) { if (BuildConfig.DEBUG) Logger.log( "InitiateMatchResult onResult " + result.getStatus()); // Check if the status code is not success; if (result.getStatus().getStatusCode() != GamesStatusCodes.STATUS_OK) { return; } TurnBasedMatch match = result.getMatch(); if (match.getData() == null) { Game.newGame(new Match(match), mGoogleApiClient); } else { if (!Game.load(match.getData(), new Match(match), mGoogleApiClient)) { updateApp(); return; } } startGame(match.getMatchId()); } }); } else if (request == RC_RESOLVE) { // We're coming back from an activity that was launched to resolve a // connection problem. For example, the sign-in UI. if (!mGoogleApiClient.isConnected() && !mGoogleApiClient.isConnecting()) { // Ready to try to connect again. mGoogleApiClient.connect(); } } } }
Example #16
Source File: BaseGooglePlayServicesActivity.java From Onesearch with MIT License | 4 votes |
private boolean isScoreResultValid(final Leaderboards.LoadPlayerScoreResult scoreResult) { return scoreResult != null && GamesStatusCodes.STATUS_OK == scoreResult.getStatus().getStatusCode() && scoreResult.getScore() != null; }