Java Code Examples for com.google.android.gms.games.multiplayer.realtime.RoomConfig#Builder

The following examples show how to use com.google.android.gms.games.multiplayer.realtime.RoomConfig#Builder . 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: RealTimeMultiplayer.java    From godot-gpgs with MIT License 5 votes vote down vote up
private void acceptInviteToRoom(String invId) {
    // accept the invitation
    Log.d(TAG, "GPGS: Accepting invitation: " + invId);
    RoomConfig.Builder roomConfigBuilder = RoomConfig.builder(this);
    roomConfigBuilder.setInvitationIdToAccept(invId)
            .setMessageReceivedListener(this)
            .setRoomStatusUpdateListener(this);
    GodotLib.calldeferred(instanceId, "_on_gpgs_rtm_invitation_accepted", new Object[] { });
    activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    Games.RealTimeMultiplayer.join(googleApiClient, roomConfigBuilder.build());
}
 
Example 2
Source File: DrawingActivity.java    From 8bitartist with Apache License 2.0 5 votes vote down vote up
/**
 * Accept an invitation to join an RTMP game
 */
private void acceptInvitation(Invitation invitation) {
    Log.d(TAG, "Got invitation: " + invitation);
    RoomConfig.Builder roomConfigBuilder = RoomConfig.builder(this)
            .setMessageReceivedListener(this)
            .setRoomStatusUpdateListener(this)
            .setInvitationIdToAccept(invitation.getInvitationId());

    Games.RealTimeMultiplayer.join(mGoogleApiClient, roomConfigBuilder.build());
}
 
Example 3
Source File: RealTimeMultiplayer.java    From godot-gpgs with MIT License 4 votes vote down vote up
/**
 * Intent Activity result parser
 * @param request The request of the Intent
 * @param response The response of the Intent
 * @param intent The Intent
 */
public void onActivityResult(int request, int response, Intent intent) {
    switch(request) {
        case RealTimeMultiplayer.RC_SELECT_PLAYERS:
            // Return if the user cancel
            if (response != Activity.RESULT_OK) return;

            // get the invitee list
            Bundle extras = intent.getExtras();
            final ArrayList<String> invitees = intent.getStringArrayListExtra(Games.EXTRA_PLAYER_IDS);

            // Get auto-match criteria
            Bundle autoMatchCriteria = null;
            int minAutoMatchPlayers = intent.getIntExtra(Multiplayer.EXTRA_MIN_AUTOMATCH_PLAYERS, 0);
            int maxAutoMatchPlayers = intent.getIntExtra(Multiplayer.EXTRA_MAX_AUTOMATCH_PLAYERS, 0);

            if (minAutoMatchPlayers > 0) autoMatchCriteria = RoomConfig.createAutoMatchCriteria(minAutoMatchPlayers, maxAutoMatchPlayers, 0);
            else autoMatchCriteria = null;

            // Create the room and specify a variant if appropriate
            RoomConfig.Builder roomConfigBuilder = makeBasicRoomConfigBuilder();
            roomConfigBuilder.addPlayersToInvite(invitees);
            if (autoMatchCriteria != null) roomConfigBuilder.setAutoMatchCriteria(autoMatchCriteria);
            RoomConfig roomConfig = roomConfigBuilder.build();
            Games.RealTimeMultiplayer.create(googleApiClient, roomConfig);

            // Prevent screen from sleeping during handshake
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
            break;

        case RealTimeMultiplayer.RC_WAITING_ROOM:
            // we got the result from the "waiting room" UI.
            if (response == Activity.RESULT_OK) {
                // ready to start playing
                Log.d(TAG, "GPGS: Starting game (waiting room returned OK).");
                GodotLib.calldeferred(instanceId, "_on_gpgs_rtm_start_game", new Object[] { });
            } else if (response == GamesActivityResultCodes.RESULT_LEFT_ROOM) {
                // player indicated that they want to leave the room
                leaveRoom();
            } else if (response == Activity.RESULT_CANCELED) {
                // Dialog was cancelled (user pressed back key, for instance). In our game,
                // this means leaving the room too. In more elaborate games, this could mean
                // something else (like minimizing the waiting room UI).
                leaveRoom();
            }
            break;

        case RealTimeMultiplayer.RC_INVITATION_INBOX:
            // we got the result from the "select invitation" UI (invitation inbox). We're
            // ready to accept the selected invitation:
            handleInvitationInboxResult(response, intent);
            break;
    }
}
 
Example 4
Source File: RealTimeMultiplayer.java    From godot-gpgs with MIT License 4 votes vote down vote up
private RoomConfig.Builder makeBasicRoomConfigBuilder() {
    return RoomConfig.builder(this)
    .setMessageReceivedListener(this)
    .setRoomStatusUpdateListener(this);
}
 
Example 5
Source File: DrawingActivity.java    From 8bitartist with Apache License 2.0 4 votes vote down vote up
@Override
public void onActivityResult(int request, int response, Intent data) {
    super.onActivityResult(request, response, data);
    Log.i(TAG, "onActivityResult: code = " + request + ", response = " + response);

    // Coming back from resolving a sign-in request
    if (request == RC_SIGN_IN) {
        mSignInClicked = false;
        mResolvingConnectionFailure = false;
        if (response == RESULT_OK) {
            mGoogleApiClient.connect();
        } else {
            BaseGameUtils.showActivityResultError(this, request, response,
                    R.string.sign_in_failed);
        }
    }

    // Coming back from a RealTime Multiplayer waiting room
    if (request == RC_WAITING_ROOM) {
        dismissSpinner();

        Room room = data.getParcelableExtra(Multiplayer.EXTRA_ROOM);
        if (response == RESULT_OK) {
            Log.d(TAG, "Waiting Room: Success");
            mRoom = room;
            startMatch();
        } else if (response == RESULT_CANCELED) {
            Log.d(TAG, "Waiting Room: Canceled");
            leaveRoom();
        } else if (response == GamesActivityResultCodes.RESULT_LEFT_ROOM) {
            Log.d(TAG, "Waiting Room: Left Room");
            leaveRoom();
        } else if (response == GamesActivityResultCodes.RESULT_INVALID_ROOM) {
            Log.d(TAG, "Waiting Room: Invalid Room");
            leaveRoom();
        }
    }

    // We are coming back from the player selection UI, in preparation to start a match.
    if (request == RC_SELECT_PLAYERS) {
        if (response != Activity.RESULT_OK) {
            // user canceled
            Log.d(TAG, "onActivityResult: user canceled player selection.");
            return;
        }

        // Create a basic room configuration
        RoomConfig.Builder roomConfigBuilder = RoomConfig.builder(this)
                .setMessageReceivedListener(this)
                .setRoomStatusUpdateListener(this);

        // Set the auto match criteria
        int minAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MIN_AUTOMATCH_PLAYERS, 0);
        int maxAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MAX_AUTOMATCH_PLAYERS, 0);
        if (minAutoMatchPlayers > 0 || maxAutoMatchPlayers > 0) {
            Bundle autoMatchCriteria = RoomConfig.createAutoMatchCriteria(
                    minAutoMatchPlayers, maxAutoMatchPlayers, 0);
            roomConfigBuilder.setAutoMatchCriteria(autoMatchCriteria);
        }

        // Set the invitees
        final ArrayList<String> invitees = data.getStringArrayListExtra(Games.EXTRA_PLAYER_IDS);
        if (invitees != null && invitees.size() > 0) {
            roomConfigBuilder.addPlayersToInvite(invitees);
        }

        // Build the room and start the match
        showSpinner();
        Games.RealTimeMultiplayer.create(mGoogleApiClient, roomConfigBuilder.build());
    }
}