本文整理汇总了Java中com.google.android.gms.games.multiplayer.Multiplayer类的典型用法代码示例。如果您正苦于以下问题:Java Multiplayer类的具体用法?Java Multiplayer怎么用?Java Multiplayer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Multiplayer类属于com.google.android.gms.games.multiplayer包,在下文中一共展示了Multiplayer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onConnected
import com.google.android.gms.games.multiplayer.Multiplayer; //导入依赖的package包/类
@Override
public void onConnected(Bundle connectionHint) {
Log.d(TAG, "onConnected() called. Sign in successful!");
Log.d(TAG, "Sign-in succeeded.");
// register listener so we are notified if we receive an invitation to play
// while we are in the game
Games.Invitations.registerInvitationListener(mGoogleApiClient, this);
if (connectionHint != null) {
Log.d(TAG, "onConnected: connection hint provided. Checking for invite.");
Invitation inv = connectionHint
.getParcelable(Multiplayer.EXTRA_INVITATION);
if (inv != null && inv.getInvitationId() != null) {
// retrieve and cache the invitation ID
Log.d(TAG,"onConnected: connection hint has a room invite!");
acceptInviteToRoom(inv.getInvitationId());
return;
}
}
switchToMainScreen();
}
示例2: onActivityResult
import com.google.android.gms.games.multiplayer.Multiplayer; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
gameHelper.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_LOOK_AT_MATCHES) {
// Returning from the 'Select Match' dialog
if (resultCode != Activity.RESULT_OK) {
// user canceled
return;
}
TurnBasedMatch match = data.getParcelableExtra(Multiplayer.EXTRA_TURN_BASED_MATCH);
if (match.getData() == null)
startMatch(match);
else
updateMatch(match);
Log.d(TAG, "Match = " + match);
}
}
示例3: onConnected
import com.google.android.gms.games.multiplayer.Multiplayer; //导入依赖的package包/类
@Override
public void onConnected(Bundle connectionHint) {
Timber.d("Google login successful");
// check if pending invitation
Invitation invitation = null;
if (connectionHint != null) {
invitation = connectionHint.getParcelable(Multiplayer.EXTRA_INVITATION);
}
spinnerUtils.hideSpinner();
// check for tutorial
MenuFragment fragment = MenuFragment.createInstance(invitation);
if (tutorialUtils.shouldShowTutorial()) {
tutorialUtils.onShowTutorial();
onTutorialStart();
this.menuFragment = fragment;
} else {
showFragment(fragment, true);
}
}
示例4: onConnected
import com.google.android.gms.games.multiplayer.Multiplayer; //导入依赖的package包/类
@Override
public void onConnected(Bundle bundle) {
Log.i(TAG, "onConnected: sign-in successful.");
// This is *NOT* required; if you do not register a handler for
// invitation events, you will get standard notifications instead.
// Standard notifications may be preferable behavior in many cases.
Games.Invitations.registerInvitationListener(mGoogleApiClient, this);
// Get invitation from Bundle
if (bundle != null) {
Invitation invitation = bundle.getParcelable(Multiplayer.EXTRA_INVITATION);
if (invitation != null) {
onInvitationReceived(invitation);
}
}
updateViewVisibility();
}
示例5: onConnected
import com.google.android.gms.games.multiplayer.Multiplayer; //导入依赖的package包/类
/** Called when we successfully obtain a connection to a client. */
@Override
public void onConnected(Bundle connectionHint) {
debugLog("onConnected: connected!");
if (connectionHint != null) {
debugLog("onConnected: connection hint provided. Checking for invite.");
Invitation inv = connectionHint
.getParcelable(Multiplayer.EXTRA_INVITATION);
if (inv != null && inv.getInvitationId() != null) {
// retrieve and cache the invitation ID
debugLog("onConnected: connection hint has a room invite!");
mInvitation = inv;
debugLog("Invitation ID: " + mInvitation.getInvitationId());
}
debugLog("onConnected: connection hint provided. Checking for TBMP game.");
mTurnBasedMatch = connectionHint.getParcelable(Multiplayer.EXTRA_TURN_BASED_MATCH);
}
// we're good to go
succeedSignIn();
}
示例6: onConnected
import com.google.android.gms.games.multiplayer.Multiplayer; //导入依赖的package包/类
@Override
public void onConnected(Bundle connectionHint) {
Log.d(LOG_TAG, "onConnected() called. Sign in successful!");
Log.d(LOG_TAG, "Sign-in succeeded.");
// register listener so we are notified if we receive an invitation to play
// while we are in the game
Games.Invitations.registerInvitationListener(mGoogleApiClient, this);
if (connectionHint != null) {
Log.d(LOG_TAG, "onConnected: connection hint provided. Checking for invite.");
Invitation inv = connectionHint
.getParcelable(Multiplayer.EXTRA_INVITATION);
if (inv != null && inv.getInvitationId() != null) {
// retrieve and cache the invitation ID
Log.d(LOG_TAG,"onConnected: connection hint has a room invite!");
acceptInviteToRoom(inv.getInvitationId());
}
}
}
示例7: onConnected
import com.google.android.gms.games.multiplayer.Multiplayer; //导入依赖的package包/类
/** Called when we successfully obtain a connection to a client. */
@Override
public void onConnected(Bundle connectionHint) {
debugLog("onConnected: connected!");
if (connectionHint != null) {
debugLog("onConnected: connection hint provided. Checking for invite.");
Invitation inv = connectionHint
.getParcelable(Multiplayer.EXTRA_INVITATION);
if (inv != null && inv.getInvitationId() != null) {
// retrieve and cache the invitation ID
debugLog("onConnected: connection hint has a room invite!");
mInvitation = inv;
debugLog("Invitation ID: " + mInvitation.getInvitationId());
}
debugLog("onConnected: connection hint provided. Checking for TBMP game.");
mTurnBasedMatch = connectionHint
.getParcelable(Multiplayer.EXTRA_TURN_BASED_MATCH);
}
// we're good to go
succeedSignIn();
}
示例8: onConnected
import com.google.android.gms.games.multiplayer.Multiplayer; //导入依赖的package包/类
/** Called when we successfully obtain a connection to a client. */
@Override
public void onConnected(Bundle connectionHint) {
debugLog("onConnected: connected!");
if (connectionHint != null) {
debugLog("onConnected: connection hint provided. Checking for invite.");
Invitation inv = connectionHint
.getParcelable(Multiplayer.EXTRA_INVITATION);
if (inv != null && inv.getInvitationId() != null) {
// retrieve and cache the invitation ID
debugLog("onConnected: connection hint has a room invite!");
mInvitation = inv;
debugLog("Invitation ID: " + mInvitation.getInvitationId());
}
// Do we have any requests pending?
mRequests = Games.Requests
.getGameRequestsFromBundle(connectionHint);
if (!mRequests.isEmpty()) {
// We have requests in onConnected's connectionHint.
debugLog("onConnected: connection hint has " + mRequests.size()
+ " request(s)");
}
debugLog("onConnected: connection hint provided. Checking for TBMP game.");
mTurnBasedMatch = connectionHint
.getParcelable(Multiplayer.EXTRA_TURN_BASED_MATCH);
}
// we're good to go
succeedSignIn();
}
示例9: onConnected
import com.google.android.gms.games.multiplayer.Multiplayer; //导入依赖的package包/类
/**
* Called when we successfully obtain a connection to a client.
*/
@Override
public void onConnected(Bundle connectionHint) {
debugLog("onConnected: connected!");
if (connectionHint != null) {
debugLog("onConnected: connection hint provided. Checking for invite.");
Invitation inv = connectionHint
.getParcelable(Multiplayer.EXTRA_INVITATION);
if (inv != null && inv.getInvitationId() != null) {
// retrieve and cache the invitation ID
debugLog("onConnected: connection hint has a room invite!");
mInvitation = inv;
debugLog("Invitation ID: " + mInvitation.getInvitationId());
}
// Do we have any requests pending?
mRequests = Games.Requests
.getGameRequestsFromBundle(connectionHint);
if (!mRequests.isEmpty()) {
// We have requests in onConnected's connectionHint.
debugLog("onConnected: connection hint has " + mRequests.size()
+ " request(s)");
}
debugLog("onConnected: connection hint provided. Checking for TBMP game.");
mTurnBasedMatch = connectionHint
.getParcelable(Multiplayer.EXTRA_TURN_BASED_MATCH);
}
// we're good to go
succeedSignIn();
}
示例10: handleSelectPlayersResult
import com.google.android.gms.games.multiplayer.Multiplayer; //导入依赖的package包/类
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...");
RoomConfig.Builder rtmConfigBuilder = RoomConfig.builder(this);
rtmConfigBuilder.addPlayersToInvite(invitees);
rtmConfigBuilder.setMessageReceivedListener(this);
rtmConfigBuilder.setRoomStatusUpdateListener(this);
if (autoMatchCriteria != null) {
rtmConfigBuilder.setAutoMatchCriteria(autoMatchCriteria);
}
switchToScreen(R.id.screen_wait);
keepScreenOn();
resetGameVars();
Games.RealTimeMultiplayer.create(mGoogleApiClient, rtmConfigBuilder.build());
Log.d(TAG, "Room created, waiting for it to be ready...");
}
示例11: handleInvitationInboxResult
import com.google.android.gms.games.multiplayer.Multiplayer; //导入依赖的package包/类
private void handleInvitationInboxResult(int response, Intent data) {
if (response != Activity.RESULT_OK) {
Log.w(TAG, "*** invitation inbox UI cancelled, " + response);
switchToMainScreen();
return;
}
Log.d(TAG, "Invitation inbox UI succeeded.");
Invitation inv = data.getExtras().getParcelable(Multiplayer.EXTRA_INVITATION);
// accept invitation
acceptInviteToRoom(inv.getInvitationId());
}
示例12: handleWaitingRoomResult
import com.google.android.gms.games.multiplayer.Multiplayer; //导入依赖的package包/类
private void handleWaitingRoomResult(int resultCode, Intent intent) {
Room room = intent.getParcelableExtra(Multiplayer.EXTRA_ROOM);
Log.d(TAG, "handleWaitingRoomResult: ");
switch (resultCode) {
case Activity.RESULT_OK:
Log.d(TAG, "handleWaitingRoomResult: OK");
gameListener.onMultiplayerGameStarting();
List<PlayerData> playerList = new ArrayList<>();
String currentPlayerId = Games.Players.getCurrentPlayerId(gameHelper.getApiClient());
for (Participant participant : room.getParticipants()) {
String playerId = participant.getPlayer().getPlayerId();
PlayerData playerData = new PlayerData(playerId, participant.getParticipantId(), participant.getDisplayName());
if (Objects.equals(currentPlayerId, playerId)) {
playerData.isSelf = true;
}
playerList.add(playerData);
}
networkListener.onRoomReady(playerList);
break;
case Activity.RESULT_CANCELED:
Log.d(TAG, "handleWaitingRoomResult: CANCEL");
// TODO: 02-Apr-17 leave room
break;
case RESULT_LEFT_ROOM:
Log.d(TAG, "handleWaitingRoomResult: RESULT_LEFT_ROOM");
Games.RealTimeMultiplayer.leave(getGameHelper().getApiClient(), this, room.getRoomId());
break;
case RESULT_INVALID_ROOM:
// TODO: 02-Apr-17 handle invalid room
Log.d(TAG, "handleWaitingRoomResult: INVALID");
break;
}
}
示例13: handleSelectPlayersResult
import com.google.android.gms.games.multiplayer.Multiplayer; //导入依赖的package包/类
private void handleSelectPlayersResult(int response, Intent data) {
Log.d(TAG, "handleSelectPlayersResult: ");
if (response != Activity.RESULT_OK) {
Log.w(TAG, "*** select players UI cancelled, " + response);
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...");
RoomConfig.Builder rtmConfigBuilder = RoomConfig.builder(this);
rtmConfigBuilder.addPlayersToInvite(invitees);
rtmConfigBuilder.setMessageReceivedListener(this);
rtmConfigBuilder.setRoomStatusUpdateListener(this);
if (autoMatchCriteria != null) {
rtmConfigBuilder.setAutoMatchCriteria(autoMatchCriteria);
}
keepScreenOn();
Games.RealTimeMultiplayer.create(getGameHelper().getApiClient(), rtmConfigBuilder.build());
Log.d(TAG, "Room created, waiting for it to be ready...");
}
示例14: handleSelectPlayersResult
import com.google.android.gms.games.multiplayer.Multiplayer; //导入依赖的package包/类
protected void handleSelectPlayersResult(int response, Intent data) {
if (response != Activity.RESULT_OK) {
Log.w("SELECT_PLAYERS_RESULT", "*** select players UI cancelled, " + response);
return;
}
Log.d("SELECT_PLAYERS_RESULT", "Select players UI succeeded.");
// get the invitee list
final ArrayList<String> invitees = data.getStringArrayListExtra(Games.EXTRA_PLAYER_IDS);
Log.d("SELECT_PLAYERS_RESULT", "Invitee count: " + invitees.size());
// get the automatch criteria
Bundle autoMatchCriteria = null;
int minAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MIN_AUTOMATCH_PLAYERS, MIN_NUMBER_OF_PLAYERS);
int maxAutoMatchPlayers = data.getIntExtra(Multiplayer.EXTRA_MAX_AUTOMATCH_PLAYERS, MAX_NUMBER_OF_PLAYERS);
if (minAutoMatchPlayers > 0 || maxAutoMatchPlayers > 0) {
autoMatchCriteria = RoomConfig.createAutoMatchCriteria(
minAutoMatchPlayers, maxAutoMatchPlayers, 0);
Log.d("SELECT_PLAYERS_RESULT", "Automatch criteria: " + autoMatchCriteria);
}
// create the room
Log.d("SELECT_PLAYERS_RESULT", "Creating room...");
mRoomConfig = RoomConfig.builder(mRoomUpdateCallbackImpl)
.addPlayersToInvite(invitees)
.setOnMessageReceivedListener(SpaceRace.messageManager)
.setRoomStatusUpdateCallback(mRoomStatusUpdateCallback)
.setAutoMatchCriteria(autoMatchCriteria)
.build();
mRealTimeMultiplayerClient.create(mRoomConfig);
Log.d("SELECT_PLAYERS_RESULT", "Room created, waiting for it to be ready...");
}
示例15: handleInvitationInboxResult
import com.google.android.gms.games.multiplayer.Multiplayer; //导入依赖的package包/类
protected void handleInvitationInboxResult(int response, Intent data) {
if (response != Activity.RESULT_OK) {
Log.w("INVITATION INBOX", "*** invitation inbox UI cancelled, " + response);
return;
}
Log.d("INVITATION INBOX", "Invitation inbox UI succeeded.");
Invitation invitation = data.getExtras().getParcelable(Multiplayer.EXTRA_INVITATION);
// accept invitation
if (invitation != null) {
acceptInviteToRoom(invitation.getInvitationId());
}
}