project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/PlayerListAdapter.java
author Medo <smaxein@googlemail.com>
Mon, 16 Jul 2012 20:16:03 +0200
changeset 7330 867e4fda496e
child 7332 3f2e130f9715
permissions -rw-r--r--
Hedgeroid: Layout experiments for the lobby page
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7330
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
     1
package org.hedgewars.hedgeroid.netplay;
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
     2
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
     3
import java.util.ArrayList;
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
     4
import java.util.Collection;
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
     5
import java.util.Collections;
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
     6
import java.util.List;
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
     7
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
     8
import org.hedgewars.hedgeroid.R;
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
     9
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    10
import android.content.Context;
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    11
import android.view.LayoutInflater;
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    12
import android.view.View;
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    13
import android.view.ViewGroup;
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    14
import android.widget.BaseAdapter;
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    15
import android.widget.TextView;
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    16
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    17
public class PlayerListAdapter extends BaseAdapter {
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    18
	private List<Player> players = new ArrayList<Player>();
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    19
	private Context context;
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    20
	
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    21
	public PlayerListAdapter(Context context) {
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    22
		this.context = context;
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    23
	}
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    24
	
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    25
	public int getCount() {
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    26
		return players.size();
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    27
	}
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    28
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    29
	public Object getItem(int position) {
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    30
		return players.get(position);
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    31
	}
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    32
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    33
	public long getItemId(int position) {
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    34
		return players.get(position).playerId;
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    35
	}
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    36
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    37
	public boolean hasStableIds() {
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    38
		return true;
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    39
	}
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    40
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    41
	public void setPlayerList(Collection<Player> players) {
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    42
		this.players = new ArrayList<Player>(players);
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    43
		Collections.sort(this.players, Player.nameComparator);
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    44
		notifyDataSetChanged();
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    45
	}
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    46
	
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    47
	public View getView(int position, View convertView, ViewGroup parent) {
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    48
		View v = convertView;
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    49
		if (v == null) {
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    50
			LayoutInflater vi = LayoutInflater.from(context);
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    51
			v = vi.inflate(android.R.layout.simple_list_item_1, null);
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    52
			TextView tv = (TextView)v.findViewById(android.R.id.text1);
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    53
			tv.setCompoundDrawablePadding(5);
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    54
			tv.setCompoundDrawablesWithIntrinsicBounds(R.drawable.human, 0, 0, 0);
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    55
		}
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    56
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    57
		String player = players.get(position).name;
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    58
		TextView username = (TextView) v.findViewById(android.R.id.text1);
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    59
		username.setText(player);
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    60
		return v;
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    61
	}
867e4fda496e Hedgeroid: Layout experiments for the lobby page
Medo <smaxein@googlemail.com>
parents:
diff changeset
    62
}