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; /*from w w w.j a v a 2 s . com*/ import net.avedo.seekampf.R; import net.avedo.seekampf.R.drawable; import net.avedo.seekampf.R.id; import net.avedo.seekampf.R.layout; import net.avedo.seekampf.R.string; import net.avedo.seekampf.core.CustomAdapter; import net.avedo.seekampf.core.RestDetailsActivity; import net.avedo.seekampf.models.Island; import net.avedo.seekampf.utils.Constants; import android.content.Context; import android.content.Intent; import android.graphics.drawable.Drawable; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; public class HomeFragment extends RestListFragment<Island> { public static final String TAG = "HomeFragment"; @Override protected String fetchServiceTag() { return TAG; } @Override protected void fetchServiceAdapter(Island[] islands) { adapter = new IslandAdapter(getActivity(), R.layout.home_row, islands); } @Override protected Class<Island[]> fetchServiceObjClass() { return Island[].class; } protected String fetchServiceUrl() { return "https://www.seekampf.de/api/api2.php?server=" + settings.getString(res.getString(R.string.prefs_server_key), "1") + "&typ=inseln&me=true"; } @Override public void onListItemClick(ListView list, View view, int position, long id) { Intent intent = new Intent(getActivity(), RestDetailsActivity.class); intent.putExtra(Constants.INTENT_EXTRA_ID, id); intent.putExtra(Constants.INTENT_EXTRA_FRAGMENT, Constants.FRAGMENT_HOME_DETAILS); getActivity().startActivity(intent); } private class IslandAdapter extends CustomAdapter<Island> { public IslandAdapter(Context context, int resId, Island[] islands) { super(context, resId, islands); } @Override public View getView(int position, View convertView, ViewGroup parent) { super.getView(position, convertView, parent); if (convertView == null) { // Fetch the layout inflater ... LayoutInflater vi = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); // ... and load the island row layout. convertView = vi.inflate(R.layout.home_row, null); } // Fetch the current island. Island island = getItem(position); // Fetch the island name field ... TextView islandName = (TextView) convertView.findViewById(R.id.islandName); // ... and initialize it. islandName.setText(island.getInselname() + " (" + island.getKoordinaten() + ")"); // Fetch the island gold view ... TextView islandGold = (TextView) convertView.findViewById(R.id.islandGold); // ... and assign the received value. islandGold.setText("" + island.getGold()); // Fetch the island hourly gold view ... TextView islandHourlyGold = (TextView) convertView.findViewById(R.id.islandHourlyGold); // ... and assign the received value. islandHourlyGold.setText("" + island.getGoldstd()); // Fetch the island stone view ... TextView islandStone = (TextView) convertView.findViewById(R.id.islandStone); // ... and assign the received value. islandStone.setText("" + island.getStein()); // Fetch the island hourly stone view ... TextView islandHourlyStone = (TextView) convertView.findViewById(R.id.islandHourlyStone); // ... and assign the received value. islandHourlyStone.setText("" + island.getSteinstd()); // Fetch the island wood view ... TextView islandWood = (TextView) convertView.findViewById(R.id.islandWood); // ... and assign the received value. islandWood.setText("" + island.getHolz()); // Fetch the island hourly wood view ... TextView islandHourlyWood = (TextView) convertView.findViewById(R.id.islandHourlyWood); // ... and assign the received value. islandHourlyWood.setText("" + island.getHolzstd()); // Fetch the island stone throwers view ... TextView islandStoneThrower = (TextView) convertView.findViewById(R.id.islandStoneThrower); // ... and assign the received value. islandStoneThrower.setText("" + island.getSteinewerfer()); // Fetch the island speermen view ... TextView islandSpeermen = (TextView) convertView.findViewById(R.id.islandSpeermen); // ... and assign the received value. islandSpeermen.setText("" + island.getSpeertraeger()); // Fetch the island archers view ... TextView islandArchers = (TextView) convertView.findViewById(R.id.islandArchers); // ... and assign the received value. islandArchers.setText("" + island.getBogenschuetzen()); // Fetch the update building state ... ImageView islandUpdateBuilding = (ImageView) convertView.findViewById(R.id.islandUpdateBuilding); // ... and change the alpha value, if necessary. if(!island.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) convertView.findViewById(R.id.islandBuildingUnits); // ... and change the alpha value, if necessary. if(!island.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) convertView.findViewById(R.id.islandBuildingShips); // ... and change the alpha value, if necessary. if(!island.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) convertView.findViewById(R.id.islandInConflict); // ... and change the alpha value, if necessary. if(!island.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); } return convertView; } } }