Back to project page SeeKampf.
The source code is released under:
GNU General Public License
If you think the Android project SeeKampf listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package net.avedo.seekampf.fragments; /*www . j a va2s. co m*/ import android.content.Context; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import net.avedo.seekampf.R; import net.avedo.seekampf.models.Island; import net.avedo.seekampf.utils.Constants; public class HomeDetailsFragment extends RestDetailsFragment<Island> { public static final String TAG = "HomeDetails"; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_home_details, container, false); } @Override protected String fetchServiceUrl() { return Constants.API_URL + "?server=" + settings.getString(res.getString(R.string.prefs_server_key), "1") + "&typ=inseln&me=true&id=" + this.serviceObjectId; } @Override protected String fetchServiceTag() { return HomeDetailsFragment.TAG; } @Override protected void createView() { // Fetch the main layout ... View mainView = this.getView(); // ... and fetch the linear layout. LinearLayout mainLayout = (LinearLayout) mainView.findViewById(R.id.mainLayout); // Fetch the layout inflater ... LayoutInflater li = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); // ... and the application resources. Resources res = getActivity().getResources(); // Fetch the island name field ... TextView islandName = (TextView) mainView.findViewById(R.id.islandName); // ... and initialize it. islandName.setText(this.serviceObject.getInselname() + " (" + this.serviceObject.getKoordinaten() + ")"); // Fetch the island gold view ... TextView islandGold = (TextView) mainView.findViewById(R.id.islandGold); // ... and assign the received value. islandGold.setText("" + this.serviceObject.getGold()); // Fetch the island hourly gold view ... TextView islandHourlyGold = (TextView) mainView.findViewById(R.id.islandHourlyGold); // ... and assign the received value. islandHourlyGold.setText("" + this.serviceObject.getGoldstd()); // Fetch the island stone view ... TextView islandStone = (TextView) mainView.findViewById(R.id.islandStone); // ... and assign the received value. islandStone.setText("" + this.serviceObject.getStein()); // Fetch the island hourly stone view ... TextView islandHourlyStone = (TextView) mainView.findViewById(R.id.islandHourlyStone); // ... and assign the received value. islandHourlyStone.setText("" + this.serviceObject.getSteinstd()); // Fetch the island wood view ... TextView islandWood = (TextView) mainView.findViewById(R.id.islandWood); // ... and assign the received value. islandWood.setText("" + this.serviceObject.getHolz()); // Fetch the island hourly wood view ... TextView islandHourlyWood = (TextView) mainView.findViewById(R.id.islandHourlyWood); // ... and assign the received value. islandHourlyWood.setText("" + this.serviceObject.getHolzstd()); // Fetch the island stone throwers view ... TextView islandStoneThrower = (TextView) mainView.findViewById(R.id.islandStoneThrower); // ... and assign the received value. islandStoneThrower.setText("" + this.serviceObject.getSteinewerfer()); // Fetch the island speermen view ... TextView islandSpeermen = (TextView) mainView.findViewById(R.id.islandSpeermen); // ... and assign the received value. islandSpeermen.setText("" + this.serviceObject.getSpeertraeger()); // Fetch the island archers view ... TextView islandArchers = (TextView) mainView.findViewById(R.id.islandArchers); // ... and assign the received value. islandArchers.setText("" + this.serviceObject.getBogenschuetzen()); // Fetch the update building state ... ImageView islandUpdateBuilding = (ImageView) mainView.findViewById(R.id.islandUpdateBuilding); // ... and change the alpha value, if necessary. if (!this.serviceObject.isGebaeudewirdgebaut()) { // Make the icons transparent. Drawable icon = this.res.getDrawable(R.drawable.building); icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight()); icon.mutate().setAlpha(40); islandUpdateBuilding.setImageDrawable(icon); } // Fetch the training units state ... ImageView islandBuildingUnits = (ImageView) mainView.findViewById(R.id.islandBuildingUnits); // ... and change the alpha value, if necessary. if (!this.serviceObject.isEinheitenwerdengebaut()) { // Make the icons transparent. Drawable icon = this.res.getDrawable(R.drawable.soldier); icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight()); icon.mutate().setAlpha(40); islandBuildingUnits.setImageDrawable(icon); } // Fetch the building ships state ... ImageView islandBuildingShips = (ImageView) mainView.findViewById(R.id.islandBuildingShips); // ... and change the alpha value, if necessary. if (!this.serviceObject.isSchiffewerdengebaut()) { // Make the icons transparent. Drawable icon = this.res.getDrawable(R.drawable.ship); icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight()); icon.mutate().setAlpha(40); islandBuildingShips.setImageDrawable(icon); } // Fetch the building units state ... ImageView islandInConflict = (ImageView) mainView.findViewById(R.id.islandInConflict); // ... and change the alpha value, if necessary. if (!this.serviceObject.isAngriff()) { // Make the icons transparent. Drawable icon = this.res.getDrawable(R.drawable.conflict); icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight()); icon.mutate().setAlpha(40); islandInConflict.setImageDrawable(icon); } // Finally append all buildings. createBuildingRow(mainLayout, R.string.mainBuilding, this.serviceObject.getHaupthauslvl(), true, res, li); createBuildingRow(mainLayout, R.string.goldmine, this.serviceObject.getGoldminelvl(), true, res, li); createBuildingRow(mainLayout, R.string.quarry, this.serviceObject.getSteinbruchlvl(), true, res, li); createBuildingRow(mainLayout, R.string.sawmill, this.serviceObject.getSaegewerklvl(), true, res, li); createBuildingRow(mainLayout, R.string.baracks, this.serviceObject.getKasernelvl(), this.serviceObject.getHaupthauslvl() >= 5, res, li); createBuildingRow(mainLayout, R.string.port, this.serviceObject.getHafenlvl(), this.serviceObject.getHaupthauslvl() >= 10, res, li); createBuildingRow(mainLayout, R.string.warehouse, this.serviceObject.getSpeicherlvl(), true, res, li); createBuildingRow(mainLayout, R.string.workshop, this.serviceObject.getWerkstattlvl(), this.serviceObject.getHaupthauslvl() >= 15, res, li); createBuildingRow(mainLayout, R.string.wall, this.serviceObject.getSteinmauerlvl(), true, res, li); createBuildingRow(mainLayout, R.string.watchtower, this.serviceObject.getWachturmlvl(), true, res, li); createBuildingRow(mainLayout, R.string.wonder, this.serviceObject.getWahrzeichenlvl(), this.serviceObject.getHaupthauslvl() >= 20, res, li); } protected void createBuildingRow(LinearLayout parent, int nameRes, int level, boolean visible, Resources res, LayoutInflater li) { if(visible) { // Load the building row layout, ... View buildingView = li.inflate(R.layout.building_row, null); // ... fetch the building name view ... TextView buildingName = (TextView) buildingView.findViewById(R.id.buildingName); // ... and assign the received value. buildingName.setText(res.getString(nameRes) + " (" + res.getString(R.string.level) + " " + level + ")"); // Finally add the layout to its parent. parent.addView(buildingView); } } }