If you think the Android project GhostStories listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package games.ghoststories.fragments;
/*www.java2s.com*/import games.ghoststories.R;
import games.ghoststories.controllers.GhostDeckController;
import games.ghoststories.data.GhostDeckData;
import games.ghoststories.data.GhostStoriesGameManager;
import games.ghoststories.data.PlayerData;
import games.ghoststories.data.TokenSupplyData;
import games.ghoststories.enums.EColor;
import games.ghoststories.views.aux_area.GhostDeckView;
import games.ghoststories.views.aux_area.PlayerInfoView;
import games.ghoststories.views.common.QiTokenView;
import games.ghoststories.views.common.TaoTokenView;
import java.util.List;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
/**
* Fragment representing the aux area. The aux area contains the game
* instructions, player info areas, ghost deck, ghost graveyard and token
* supply.
*/publicclass AuxAreaFragment extends Fragment {
/*
* (non-Javadoc)
* @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
*/
@Override
public View onCreateView(LayoutInflater pInflater, ViewGroup pContainer,
Bundle pSavedInstanceState) {
View auxAreaView = pInflater.inflate(R.layout.aux_area, pContainer, false);
GhostStoriesGameManager gm = GhostStoriesGameManager.getInstance();
//Setup the ghost deck
GhostDeckView ghostDeckView =
(GhostDeckView)auxAreaView.findViewById(R.id.ghost_deck);
GhostDeckData ghostDeckData = gm.getGhostDeckData();
ghostDeckView.setGhostDeckData(ghostDeckData);
new GhostDeckController(ghostDeckData, ghostDeckView);
//Setup the player info area
View playerInfoArea = auxAreaView.findViewById(R.id.player_info_area);
List<EColor> playerOrder = gm.getPlayerOrder();
for(int i = 0; i < playerOrder.size(); ++i) {
setupPlayerInfoView(playerInfoArea, getPlayerInfoId(i),
gm.getPlayerData(playerOrder.get(i)));
}
//Setup the token supply
TokenSupplyData supply = gm.getTokenSupply();
for(EColor c : EColor.values()) {
TaoTokenView tokenView =
(TaoTokenView)auxAreaView.findViewById(c.getTokenId());
tokenView.setData(supply);
}
QiTokenView qiView = (QiTokenView)auxAreaView.findViewById(R.id.qi_tokens);
qiView.setData(supply);
return auxAreaView;
}
/**
* @param pPlayer The player index to get the info area for
* @return The player info area for the specified player
*/privateint getPlayerInfoId(int pPlayer) {
int id = R.id.info_area_1;
switch(pPlayer) {
case 0:
id = R.id.info_area_1;
break;
case 1:
id = R.id.info_area_2;
break;
case 2:
id = R.id.info_area_3;
break;
case 3:
id = R.id.info_area_4;
break;
}
return id;
}
/**
* Sets up the {@link PlayerInfoView} using the given id and player data
* @param pParent The parent view
* @param pId The id of the player area
* @param pData The data to use to populate the player area
*/privatevoid setupPlayerInfoView(View pParent, int pId, PlayerData pData) {
PlayerInfoView infoArea =
(PlayerInfoView)pParent.findViewById(pId);
infoArea.setPlayerData(pData);
}
}