project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/RoomPlayerlistAdapter.java
author Medo <smaxein@googlemail.com>
Mon, 06 Aug 2012 22:39:36 +0200
changeset 7476 2fb781bbdd51
permissions -rw-r--r--
Hedgeroid: Start using the frontlib for more operations
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7476
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
     1
package org.hedgewars.hedgeroid.netplay;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
     2
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
     3
import java.util.Comparator;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
     4
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
     5
import org.hedgewars.hedgeroid.R;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
     6
import org.hedgewars.hedgeroid.netplay.RoomPlayerlist.PlayerInRoom;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
     7
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
     8
import android.content.Context;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
     9
import android.view.LayoutInflater;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    10
import android.view.View;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    11
import android.view.ViewGroup;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    12
import android.widget.TextView;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    13
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    14
public class RoomPlayerlistAdapter extends ObservableTreeMapAdapter<String, PlayerInRoom> {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    15
	private Context context;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    16
	
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    17
	public RoomPlayerlistAdapter(Context context) {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    18
		this.context = context;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    19
	}
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    20
	
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    21
	@Override
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    22
	protected Comparator<PlayerInRoom> getEntryOrder() {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    23
		return AlphabeticalOrderComparator.INSTANCE;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    24
	}
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    25
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    26
	public PlayerInRoom getItem(int position) {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    27
		return getEntries().get(position);
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    28
	}
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    29
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    30
	public long getItemId(int position) {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    31
		return getEntries().get(position).id;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    32
	}
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    33
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    34
	public boolean hasStableIds() {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    35
		return true;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    36
	}
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    37
	
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    38
	public View getView(int position, View convertView, ViewGroup parent) {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    39
		View v = convertView;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    40
		if (v == null) {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    41
			LayoutInflater vi = LayoutInflater.from(context);
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    42
			v = vi.inflate(R.layout.listview_player, null);
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    43
		}
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    44
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    45
		PlayerInRoom player = getItem(position);
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    46
		TextView username = (TextView) v.findViewById(android.R.id.text1);
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    47
		username.setText(player.player.name);
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    48
		int readyDrawable = player.ready ? R.drawable.lightbulb_on : R.drawable.lightbulb_off;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    49
		username.setCompoundDrawablesWithIntrinsicBounds(readyDrawable, 0, 0, 0);
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    50
		return v;
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    51
	}
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    52
	
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    53
	private static final class AlphabeticalOrderComparator implements Comparator<PlayerInRoom> {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    54
		public static final AlphabeticalOrderComparator INSTANCE = new AlphabeticalOrderComparator();
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    55
		public int compare(PlayerInRoom lhs, PlayerInRoom rhs) {
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    56
			return lhs.player.name.compareToIgnoreCase(rhs.player.name);
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    57
		};
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    58
	}
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff changeset
    59
}