/** 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();
  }
 /**
  * Returns the invitation ID received through an invitation notification. This should be called
  * from your GameHelperListener's
  *
  * @link{GameHelperListener#onSignInSucceeded method, to check if there's an invitation available.
  *     In that case, accept the invitation.
  * @return The id of the invitation, or null if none was received.
  */
 public String getInvitationId() {
   if (!mGoogleApiClient.isConnected()) {
     Log.w(
         TAG,
         "Warning: getInvitationId() should only be called when signed in, "
             + "that is, after getting onSignInSuceeded()");
   }
   return mInvitation == null ? null : mInvitation.getInvitationId();
 }
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_ARMY_CHOOSER) {
      if (resultCode == Activity.RESULT_OK) {
        Bundle extras = data.getExtras();

        mArmyChosen = extras.getInt("army");

        if (roomConfigInvitation != null) {
          // accepted invitation
          ((BaseGameActivity) getActivity()).getGamesClient().joinRoom(roomConfigInvitation);
          return;
        }

        int nbPlayers = extras.getInt("nb_players", -1);
        if (nbPlayers > 0) {
          mNbPlayers = nbPlayers;
          invitePlayersToMyGame();
        } else {
          mNbPlayers = 4;
          startQuickGame();
        }
      }
    } else if (requestCode == RC_INVITATION_INBOX) {
      if (resultCode != Activity.RESULT_OK) {
        // canceled
        return;
      }

      // get the selected invitation
      Bundle extras = data.getExtras();
      Invitation invitation = extras.getParcelable(GamesClient.EXTRA_INVITATION);

      // accept it, show the army chooser
      roomConfigInvitation =
          ((GameActivity) getActivity())
              .makeBasicRoomConfigBuilder()
              .setInvitationIdToAccept(invitation.getInvitationId())
              .build();
      showJoinGameChooser();
    }
  }
示例#4
0
  /** 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();
  }
示例#5
0
  /** Called when we successfully obtain a connection to a client. */
  @Override
  public void onConnected(Bundle connectionHint) {
    debugLog("onConnected: connected! client=" + mClientCurrentlyConnecting);

    // Mark the current client as connected
    mConnectedClients |= mClientCurrentlyConnecting;

    // If this was the games client and it came with an invite, store it for
    // later retrieval.
    if (mClientCurrentlyConnecting == CLIENT_GAMES && connectionHint != null) {
      debugLog("onConnected: connection hint provided. Checking for invite.");
      Invitation inv = connectionHint.getParcelable(GamesClient.EXTRA_INVITATION);
      if (inv != null && inv.getInvitationId() != null) {
        // accept invitation
        debugLog("onConnected: connection hint has a room invite!");
        mInvitationId = inv.getInvitationId();
        debugLog("Invitation ID: " + mInvitationId);
      }
    }

    // connect the next client in line, if any.
    connectNextClient();
  }