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 .ja v a2 s . co m import net.avedo.seekampf.R; import net.avedo.seekampf.R.color; 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.models.Alliance; import android.content.Context; import android.text.Html; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class AllianceListFragment extends RestListFragment<Alliance> { public static final String TAG = "AllianceList"; @Override protected String fetchServiceTag() { return TAG; } @Override protected void fetchServiceAdapter(Alliance[] alliances) { adapter = new AllianceAdapter(getActivity(), R.layout.alliance_row, alliances); } @Override protected Class<Alliance[]> fetchServiceObjClass() { return Alliance[].class; } @Override protected String fetchServiceUrl() { return "https://www.seekampf.de/api/api2.php?server=" + settings.getString(res.getString(R.string.prefs_server_key), "1") + "&typ=allianz&orderby=platzierung&dir=asc"; } private class AllianceAdapter extends CustomAdapter<Alliance> { public AllianceAdapter(Context context, int resId, Alliance[] alliances) { super(context, resId, alliances); } @Override public View getView(int position, View convertView, ViewGroup parent) { super.getView(position, convertView, parent); if (convertView == null) { // Fetch the layout inflater ... LayoutInflater li = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); // ... and load the alliance row layout. convertView = li.inflate(R.layout.alliance_row, null); } // Fetch the current alliance. Alliance alliance = getItem(position); // Fetch the alliance rank field ... TextView allianceRank = (TextView) convertView.findViewById(R.id.allianceRank); // ... and initialize it. allianceRank.setText("#" + alliance.getPlatzierung()); // Fetch the alliance rank change field ... TextView allianceRankChange = (TextView) convertView.findViewById(R.id.allianceRankChange); // ... calculate the change in the ranking, ... int rankChange = alliance.getPlatzierung() - alliance.getPlatzierung_vortag(); // ... update the text color and initialize it. if(rankChange < 0) { allianceRankChange.setTextColor(getResources().getColor(R.color.green)); allianceRankChange.setText(Html.fromHtml("↑")); } else if(rankChange > 0) { allianceRankChange.setTextColor(getResources().getColor(R.color.red)); allianceRankChange.setText(Html.fromHtml("↓")); } else { allianceRankChange.setTextColor(getResources().getColor(R.color.blue)); allianceRankChange.setText(Html.fromHtml("·")); } // Fetch the alliance name field ... TextView allianceName = (TextView) convertView.findViewById(R.id.allianceName); // ... and initialize it. allianceName.setText(alliance.getName() + " [" + alliance.getKuerzel() + "]"); // Fetch the alliance points field ... TextView alliancePoints = (TextView) convertView.findViewById(R.id.alliancePoints); // ... and initialize it. alliancePoints.setText("" + alliance.getPunkte()); // Fetch the alliance points change field, ... TextView alliancePointsChange = (TextView) convertView.findViewById(R.id.alliancePointsChange); // ... calculate the change, ... int change = alliance.getPunkte() - alliance.getPunkte_vortag(); // ... update the text color and initialize it. if(change > 0) { alliancePointsChange.setTextColor(getResources().getColor(R.color.green)); alliancePointsChange.setText("+" + change); } else if(change < 0) { alliancePointsChange.setTextColor(getResources().getColor(R.color.red)); alliancePointsChange.setText("" + change); } else { alliancePointsChange.setTextColor(getResources().getColor(R.color.blue)); alliancePointsChange.setText("+0"); } return convertView; } } }