Esempio n. 1
0
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstance) {
    if (view != null) return view;
    view = inflater.inflate(R.layout.fragment_main, container, false);
    playersView = (SortableListView) view.findViewById(R.id.playerList);
    playersView.setAdapter(playersAdapter);
    registerForContextMenu(playersView);
    timerButton = (Button) view.findViewById(R.id.timerButton);
    passButton = (Button) view.findViewById(R.id.passButton);
    pauseButton = (ImageButton) view.findViewById(R.id.pauseButton);
    roundView = (TextView) view.findViewById(R.id.roundView);
    pauseOverlay = (LinearLayout) view.findViewById(R.id.pauseOverlay);

    // set listeners for buttons
    timerButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            if (!game.hasPlayers()) return;
            if (game.isOnBreak()) startRound();
            Game.turns.next();
            showPlayer(Game.turns.getActivePlayer());
          }
        });
    passButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View arg0) {
            if (!game.hasPlayers()) return;
            Game.turns.pass();
            showPlayer(Game.turns.getActivePlayer());
            if (game.isOnBreak()) endRound();
          }
        });
    pauseButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            if (!game.isOnBreak() && !game.isPaused()) {
              game.pause();
              pauseOverlay.setVisibility(View.VISIBLE);
            }
          }
        });
    pauseOverlay.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            pauseOverlay.setVisibility(View.INVISIBLE);
            if (!game.isOnBreak()) game.resume();
          }
        });
    return view;
  }
Esempio n. 2
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();
 }
Esempio n. 3
0
 public void addPlayer(String name) {
   game.addPlayer(name);
   playersView.setPlayerList(game.getPlayers());
   playersAdapter.notifyDataSetChanged();
 }
Esempio n. 4
0
 /** Scrolls the list to the position of the player */
 public void showPlayer(Player player) {
   playersView.smoothScrollToPosition(playersAdapter.getPosition(player));
 }