Java Code Examples for com.google.android.gms.games.multiplayer.realtime.RoomConfig#createAutoMatchCriteria()
The following examples show how to use
com.google.android.gms.games.multiplayer.realtime.RoomConfig#createAutoMatchCriteria() .
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: SkeletonActivity.java From android-basic-samples with Apache License 2.0 | 7 votes |
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == RC_SIGN_IN) { Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(intent); try { GoogleSignInAccount account = task.getResult(ApiException.class); onConnected(account); } catch (ApiException apiException) { String message = apiException.getMessage(); if (message == null || message.isEmpty()) { message = getString(R.string.signin_other_error); } onDisconnected(); new AlertDialog.Builder(this) .setMessage(message) .setNeutralButton(android.R.string.ok, null) .show(); } } else if (requestCode == RC_LOOK_AT_MATCHES) { // Returning from the 'Select Match' dialog if (resultCode != Activity.RESULT_OK) { logBadActivityResult(requestCode, resultCode, "User cancelled returning from the 'Select Match' dialog."); return; } TurnBasedMatch match = intent .getParcelableExtra(Multiplayer.EXTRA_TURN_BASED_MATCH); if (match != null) { updateMatch(match); } Log.d(TAG, "Match = " + match); } else if (requestCode == RC_SELECT_PLAYERS) { // Returning from 'Select players to Invite' dialog if (resultCode != Activity.RESULT_OK) { // user canceled logBadActivityResult(requestCode, resultCode, "User cancelled returning from 'Select players to Invite' dialog"); return; } // get the invitee list ArrayList<String> invitees = intent .getStringArrayListExtra(Games.EXTRA_PLAYER_IDS); // get automatch criteria Bundle autoMatchCriteria; 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; } TurnBasedMatchConfig tbmc = TurnBasedMatchConfig.builder() .addInvitedPlayers(invitees) .setAutoMatchCriteria(autoMatchCriteria).build(); // Start the match mTurnBasedMultiplayerClient.createMatch(tbmc) .addOnSuccessListener(new OnSuccessListener<TurnBasedMatch>() { @Override public void onSuccess(TurnBasedMatch turnBasedMatch) { onInitiateMatch(turnBasedMatch); } }) .addOnFailureListener(createFailureListener("There was a problem creating a match!")); showSpinner(); } }
Example 2
Source File: MainActivity.java From android-basic-samples with Apache License 2.0 | 6 votes |
void startQuickGame() { // quick-start a game with 1 randomly selected opponent final int MIN_OPPONENTS = 1, MAX_OPPONENTS = 1; Bundle autoMatchCriteria = RoomConfig.createAutoMatchCriteria(MIN_OPPONENTS, MAX_OPPONENTS, 0); switchToScreen(R.id.screen_wait); keepScreenOn(); resetGameVars(); mRoomConfig = RoomConfig.builder(mRoomUpdateCallback) .setOnMessageReceivedListener(mOnRealTimeMessageReceivedListener) .setRoomStatusUpdateCallback(mRoomStatusUpdateCallback) .setAutoMatchCriteria(autoMatchCriteria) .build(); mRealTimeMultiplayerClient.create(mRoomConfig); }
Example 3
Source File: SkeletonActivity.java From android-basic-samples with Apache License 2.0 | 6 votes |
public void onQuickMatchClicked(View view) { Bundle autoMatchCriteria = RoomConfig.createAutoMatchCriteria(1, 1, 0); TurnBasedMatchConfig turnBasedMatchConfig = TurnBasedMatchConfig.builder() .setAutoMatchCriteria(autoMatchCriteria).build(); showSpinner(); // Start the match mTurnBasedMultiplayerClient.createMatch(turnBasedMatchConfig) .addOnSuccessListener(new OnSuccessListener<TurnBasedMatch>() { @Override public void onSuccess(TurnBasedMatch turnBasedMatch) { onInitiateMatch(turnBasedMatch); } }) .addOnFailureListener(createFailureListener("There was a problem creating a match!")); }
Example 4
Source File: MainActivity.java From android-basic-samples with Apache License 2.0 | 5 votes |
private void handleSelectPlayersResult(int response, Intent data) { if (response != Activity.RESULT_OK) { Log.w(TAG, "*** select players UI cancelled, " + response); switchToMainScreen(); return; } Log.d(TAG, "Select players UI succeeded."); // get the invitee list final ArrayList<String> invitees = data.getStringArrayListExtra(Games.EXTRA_PLAYER_IDS); Log.d(TAG, "Invitee count: " + invitees.size()); // get the automatch criteria Bundle autoMatchCriteria = null; 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) { autoMatchCriteria = RoomConfig.createAutoMatchCriteria( minAutoMatchPlayers, maxAutoMatchPlayers, 0); Log.d(TAG, "Automatch criteria: " + autoMatchCriteria); } // create the room Log.d(TAG, "Creating room..."); switchToScreen(R.id.screen_wait); keepScreenOn(); resetGameVars(); mRoomConfig = RoomConfig.builder(mRoomUpdateCallback) .addPlayersToInvite(invitees) .setOnMessageReceivedListener(mOnRealTimeMessageReceivedListener) .setRoomStatusUpdateCallback(mRoomStatusUpdateCallback) .setAutoMatchCriteria(autoMatchCriteria).build(); mRealTimeMultiplayerClient.create(mRoomConfig); Log.d(TAG, "Room created, waiting for it to be ready..."); }
Example 5
Source File: RealTimeMultiplayer.java From godot-gpgs with MIT License | 4 votes |
/** * 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 6
Source File: DrawingActivity.java From 8bitartist with Apache License 2.0 | 4 votes |
@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()); } }
Example 7
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(); } } } }