Пример #1
0
 /**
  * Removes all traces of the player, so that the object is eligible for garbage collection
  *
  * @param player
  */
 public void removePlayer(Player player) {
   Log.i(TAG, "Removing player: " + player.getName());
   boolean wasOnBreak = game.isOnBreak();
   // Removing player from the game removes it from the adapter too, as they reference the same
   // ArrayList<Player>
   game.removePlayer(player);
   playersView.setPlayerList(game.getPlayers());
   // Notify the adapter to update the view
   playersAdapter.notifyDataSetChanged();
   // Deduce changes to view states from game states
   if (!game.hasPlayers()) resetGame();
   else if (game.isOnBreak() && !wasOnBreak) endRound();
 }
Пример #2
0
 @Override
 public boolean onContextItemSelected(MenuItem item) {
   AdapterView.AdapterContextMenuInfo info =
       (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
   Player selectedPlayer = playersAdapter.getItem(info.position);
   switch (item.getItemId()) {
     case R.id.set_player_active:
       if (!selectedPlayer.isRunning()) Game.turns.jumpTo(selectedPlayer);
       return true;
     case R.id.add_time:
       showDialog(PLAYER_TIME_ADJUST_DIALOG_NAME, selectedPlayer);
       return true;
     case R.id.remove_player:
       showDialog(REMOVE_DIALOG_NAME, selectedPlayer);
       return true;
     case R.id.rename_player:
       showDialog(RENAME_DIALOG_NAME, selectedPlayer);
     default:
       return super.onContextItemSelected(item);
   }
 }
Пример #3
0
 public void addPlayer(String name) {
   game.addPlayer(name);
   playersView.setPlayerList(game.getPlayers());
   playersAdapter.notifyDataSetChanged();
 }
Пример #4
0
 /** Scrolls the list to the position of the player */
 public void showPlayer(Player player) {
   playersView.smoothScrollToPosition(playersAdapter.getPosition(player));
 }