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 ww w. java2 s . c o 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.Player; 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 PlayerListFragment extends RestListFragment<Player> { public static final String TAG = "PlayerList"; @Override protected String fetchServiceTag() { return TAG; } @Override protected void fetchServiceAdapter(Player[] players) { adapter = new PlayerAdapter(getActivity(), R.layout.player_row, players); } @Override protected Class<Player[]> fetchServiceObjClass() { return Player[].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=spieler&orderby=platzierung&dir=asc"; } private class PlayerAdapter extends CustomAdapter<Player> { public PlayerAdapter(Context context, int resId, Player[] players) { super(context, resId, players); } @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 player row layout. convertView = li.inflate(R.layout.player_row, null); } // Fetch the current player. Player player = getItem(position); // Fetch the player rank field ... TextView playerRank = (TextView) convertView.findViewById(R.id.playerRank); // ... and initialize it. playerRank.setText("#" + player.getPlatzierung()); // Fetch the player rank change field ... TextView playerRankChange = (TextView) convertView.findViewById(R.id.playerRankChange); // ... calculate the change in the ranking, ... int rankChange = player.getPlatzierung() - player.getPlatzierung_vortag(); // ... update the text color and initialize it. if(rankChange < 0) { playerRankChange.setTextColor(getResources().getColor(R.color.green)); playerRankChange.setText(Html.fromHtml("↑")); } else if(rankChange > 0) { playerRankChange.setTextColor(getResources().getColor(R.color.red)); playerRankChange.setText(Html.fromHtml("↓")); } else { playerRankChange.setTextColor(getResources().getColor(R.color.blue)); playerRankChange.setText(Html.fromHtml("·")); } // Fetch the player name field ... TextView playerName = (TextView) convertView.findViewById(R.id.playerName); // ... and initialize it. playerName.setText(player.getSpielername()); // Fetch the player points field ... TextView playerPoints = (TextView) convertView.findViewById(R.id.playerPoints); // ... and initialize it. playerPoints.setText("" + player.getPunkte()); // Fetch the player points change field, ... TextView playerPointsChange = (TextView) convertView.findViewById(R.id.playerPointsChange); // ... calculate the change, ... int change = player.getPunkte() - player.getPunkte_vortag(); // ... update the text color and initialize it. if(change > 0) { playerPointsChange.setTextColor(getResources().getColor(R.color.green)); playerPointsChange.setText("+" + change); } else if(change < 0) { playerPointsChange.setTextColor(getResources().getColor(R.color.red)); playerPointsChange.setText("" + change); } else { playerPointsChange.setTextColor(getResources().getColor(R.color.blue)); playerPointsChange.setText("+0"); } return convertView; } } }