Java Code Examples for com.google.android.gms.games.GamesStatusCodes#STATUS_OK

The following examples show how to use com.google.android.gms.games.GamesStatusCodes#STATUS_OK . 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: GpgsClient.java    From gdx-gamesvcs with Apache License 2.0 5 votes vote down vote up
/**
 * 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 2
Source File: RealTimeMultiplayer.java    From godot-gpgs with MIT License 5 votes vote down vote up
@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 3
Source File: RealTimeMultiplayer.java    From godot-gpgs with MIT License 5 votes vote down vote up
@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 4
Source File: RealTimeMultiplayer.java    From godot-gpgs with MIT License 5 votes vote down vote up
@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 5
Source File: RoomController.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@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 6
Source File: RoomController.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@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 7
Source File: RoomController.java    From dice-heroes with GNU General Public License v3.0 5 votes vote down vote up
@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 8
Source File: DrawingActivity.java    From 8bitartist with Apache License 2.0 5 votes vote down vote up
@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 9
Source File: DrawingActivity.java    From 8bitartist with Apache License 2.0 5 votes vote down vote up
@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 10
Source File: BaseGooglePlayServicesActivity.java    From Onesearch with MIT License 4 votes vote down vote up
private boolean isScoreResultValid(final Leaderboards.LoadPlayerScoreResult scoreResult) {
    return scoreResult != null && GamesStatusCodes.STATUS_OK == scoreResult.getStatus().getStatusCode() && scoreResult.getScore() != null;
}