com.google.android.gms.games.multiplayer.realtime.Room Java Examples

The following examples show how to use com.google.android.gms.games.multiplayer.realtime.Room. 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 6 votes vote down vote up
@Override
public void onConnectedToRoom(Room room) {
    Log.d(TAG, "onConnectedToRoom.");

    //get participants and my ID:
    participants = room.getParticipants();
    myId = room.getParticipantId(Games.Players.getCurrentPlayerId(googleApiClient));

     // save room ID if its not initialized in onRoomCreated() so we can leave cleanly before the game starts.
     if (roomId == null) roomId = room.getRoomId();

    // print out the list of participants (for debug purposes)
    Log.d(TAG, "Room ID: " + roomId);
    Log.d(TAG, "My ID " + myId);
    Log.d(TAG, "<< CONNECTED TO ROOM>>");
}
 
Example #2
Source File: MainActivity.java    From android-basic-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void onConnectedToRoom(Room room) {
  Log.d(TAG, "onConnectedToRoom.");

  //get participants and my ID:
  mParticipants = room.getParticipants();
  mMyId = room.getParticipantId(mPlayerId);

  // save room ID if its not initialized in onRoomCreated() so we can leave cleanly before the game starts.
  if (mRoomId == null) {
    mRoomId = room.getRoomId();
  }

  // print out the list of participants (for debug purposes)
  Log.d(TAG, "Room ID: " + mRoomId);
  Log.d(TAG, "My ID " + mMyId);
  Log.d(TAG, "<< CONNECTED TO 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: MainActivity.java    From android-basic-samples with Apache License 2.0 5 votes vote down vote up
void updateRoom(Room room) {
  if (room != null) {
    mParticipants = room.getParticipants();
  }
  if (mParticipants != null) {
    updatePeerScoresDisplay();
  }
}
 
Example #5
Source File: MainActivity.java    From android-basic-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onJoinedRoom(int statusCode, Room room) {
  Log.d(TAG, "onJoinedRoom(" + statusCode + ", " + room + ")");
  if (statusCode != GamesCallbackStatusCodes.OK) {
    Log.e(TAG, "*** Error: onRoomConnected, status " + statusCode);
    showGameError();
    return;
  }

  // show the waiting room UI
  showWaitingRoom(room);
}
 
Example #6
Source File: MainActivity.java    From android-basic-samples 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 != GamesCallbackStatusCodes.OK) {
    Log.e(TAG, "*** Error: onRoomConnected, status " + statusCode);
    showGameError();
    return;
  }
  updateRoom(room);
}
 
Example #7
Source File: MainActivity.java    From android-basic-samples 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 != GamesCallbackStatusCodes.OK) {
    Log.e(TAG, "*** Error: onRoomCreated, status " + statusCode);
    showGameError();
    return;
  }

  // save room ID so we can leave cleanly before the game starts.
  mRoomId = room.getRoomId();

  // show the waiting room UI
  showWaitingRoom(room);
}
 
Example #8
Source File: MainActivity.java    From android-basic-samples with Apache License 2.0 5 votes vote down vote up
void showWaitingRoom(Room room) {
  // minimum number of players required for our game
  // For simplicity, we require everyone to join the game before we start it
  // (this is signaled by Integer.MAX_VALUE).
  final int MIN_PLAYERS = Integer.MAX_VALUE;
  mRealTimeMultiplayerClient.getWaitingRoomIntent(room, MIN_PLAYERS)
      .addOnSuccessListener(new OnSuccessListener<Intent>() {
        @Override
        public void onSuccess(Intent intent) {
          // show waiting room UI
          startActivityForResult(intent, RC_WAITING_ROOM);
        }
      })
      .addOnFailureListener(createFailureListener("There was a problem getting the waiting room!"));
}
 
Example #9
Source File: DrawingActivity.java    From 8bitartist with Apache License 2.0 5 votes vote down vote up
@Override
public void onPeersDisconnected(Room room, List<String> strings) {
    Log.d(TAG, "onPeersDisconnected: " + room + ":" + strings);
    for (String pId : strings) {
        onParticipantDisconnected(pId, pId);
    }
}
 
Example #10
Source File: DrawingActivity.java    From 8bitartist with Apache License 2.0 5 votes vote down vote up
@Override
public void onPeersConnected(Room room, List<String> strings) {
    Log.d(TAG, "onPeersConnected:" + room + ":" + strings);
    mRoom = room;
    for (String pId : strings) {
        onParticipantConnected(mRoom.getParticipant(pId));
    }
}
 
Example #11
Source File: DrawingActivity.java    From 8bitartist with Apache License 2.0 5 votes vote down vote up
@Override
public void onConnectedToRoom(Room room) {
    Log.d(TAG, "onConnectedRoRoom: " + room);
    mRoom = room;

    // Add self to participants
    mMyPersistentId = mRoom.getParticipantId(
            Games.Players.getCurrentPlayerId(mGoogleApiClient));
    Participant me = mRoom.getParticipant(mMyPersistentId);
    onParticipantConnected(me);

    updateTurnIndices();
    updateViewVisibility();
}
 
Example #12
Source File: DrawingActivity.java    From 8bitartist with Apache License 2.0 5 votes vote down vote up
@Override
public void onPeerJoined(Room room, List<String> strings) {
    Log.d(TAG, "onPeerJoined: " + room + ":" + strings);
    mRoom = room;
    for (String pId : strings) {
        onParticipantConnected(mRoom.getParticipant(pId));
    }
}
 
Example #13
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 #14
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 #15
Source File: DrawingActivity.java    From 8bitartist with Apache License 2.0 5 votes vote down vote up
/**
 * Show the UI for an RTMP waiting room.
 */
private void showWaitingRoom(Room room) {
    // Require all players to join before starting
    final int MIN_PLAYERS = Integer.MAX_VALUE;

    Intent i = Games.RealTimeMultiplayer.getWaitingRoomIntent(mGoogleApiClient, room, MIN_PLAYERS);
    startActivityForResult(i, RC_WAITING_ROOM);
}
 
Example #16
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 #17
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 #18
Source File: RealTimeMultiplayer.java    From godot-gpgs with MIT License 5 votes vote down vote up
void showWaitingRoom(Room room) {
    // minimum number of players required for our game
    // For simplicity, we require everyone to join the game before we start it
    // (this is signaled by Integer.MAX_VALUE).
    final int MIN_PLAYERS = Integer.MAX_VALUE;
    Intent i = Games.RealTimeMultiplayer.getWaitingRoomIntent(googleApiClient, room, MIN_PLAYERS);

    // show waiting room UI
    activity.startActivityForResult(i, RC_WAITING_ROOM);
}
 
Example #19
Source File: RealTimeMultiplayer.java    From godot-gpgs with MIT License 4 votes vote down vote up
@Override
public void onPeerInvitedToRoom(Room room, List<String> arg1) {
    updateRoom(room);
}
 
Example #20
Source File: RealTimeMultiplayer.java    From godot-gpgs with MIT License 4 votes vote down vote up
@Override
public void onDisconnectedFromRoom(Room room) {
    roomId = null;
    GodotLib.calldeferred(instanceId, "_on_gpgs_rtm_disconnected_from_room", new Object[] { });
}
 
Example #21
Source File: RealTimeMultiplayer.java    From godot-gpgs with MIT License 4 votes vote down vote up
void updateRoom(Room room) {
    if (room != null) participants = room.getParticipants();
    if (participants != null) {
        // Nothing
    }
}
 
Example #22
Source File: MainActivity.java    From android-basic-samples with Apache License 2.0 4 votes vote down vote up
@Override
public void onPeersDisconnected(Room room, @NonNull List<String> peers) {
  updateRoom(room);
}
 
Example #23
Source File: MainActivity.java    From android-basic-samples with Apache License 2.0 4 votes vote down vote up
@Override
public void onPeersConnected(Room room, @NonNull List<String> peers) {
  updateRoom(room);
}
 
Example #24
Source File: MainActivity.java    From android-basic-samples with Apache License 2.0 4 votes vote down vote up
@Override
public void onRoomConnecting(Room room) {
  updateRoom(room);
}
 
Example #25
Source File: MainActivity.java    From android-basic-samples with Apache License 2.0 4 votes vote down vote up
@Override
public void onRoomAutoMatching(Room room) {
  updateRoom(room);
}
 
Example #26
Source File: MainActivity.java    From android-basic-samples with Apache License 2.0 4 votes vote down vote up
@Override
public void onPeerLeft(Room room, @NonNull List<String> peersWhoLeft) {
  updateRoom(room);
}
 
Example #27
Source File: MainActivity.java    From android-basic-samples with Apache License 2.0 4 votes vote down vote up
@Override
public void onPeerJoined(Room room, @NonNull List<String> arg1) {
  updateRoom(room);
}
 
Example #28
Source File: MainActivity.java    From android-basic-samples with Apache License 2.0 4 votes vote down vote up
@Override
public void onPeerInvitedToRoom(Room room, @NonNull List<String> arg1) {
  updateRoom(room);
}
 
Example #29
Source File: MainActivity.java    From android-basic-samples with Apache License 2.0 4 votes vote down vote up
@Override
public void onPeerDeclined(Room room, @NonNull List<String> arg1) {
  updateRoom(room);
}
 
Example #30
Source File: MainActivity.java    From android-basic-samples with Apache License 2.0 4 votes vote down vote up
@Override
public void onDisconnectedFromRoom(Room room) {
  mRoomId = null;
  mRoomConfig = null;
  showGameError();
}