author | Medo <smaxein@googlemail.com> |
Sat, 18 Aug 2012 00:47:51 +0200 | |
changeset 7508 | 763d3961400b |
parent 7491 | project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/RoomlistAdapter.java@d954c1a36e51 |
child 7584 | 7831c84cc644 |
permissions | -rw-r--r-- |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7491
diff
changeset
|
1 |
package org.hedgewars.hedgeroid; |
7342
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
2 |
|
7358
57a508884052
Hedgeroid: Major overhaul of the network connection code. Now it is threaded and
Medo <smaxein@googlemail.com>
parents:
7352
diff
changeset
|
3 |
import java.util.Comparator; |
7342
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
4 |
|
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
5 |
import org.hedgewars.hedgeroid.R; |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7491
diff
changeset
|
6 |
import org.hedgewars.hedgeroid.Datastructures.Room; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7491
diff
changeset
|
7 |
import org.hedgewars.hedgeroid.Datastructures.RoomWithId; |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7491
diff
changeset
|
8 |
import org.hedgewars.hedgeroid.util.ObservableTreeMapAdapter; |
7342
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
9 |
|
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
10 |
import android.content.Context; |
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
11 |
import android.content.res.Resources; |
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
12 |
import android.view.LayoutInflater; |
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
13 |
import android.view.View; |
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
14 |
import android.view.ViewGroup; |
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
15 |
import android.widget.TextView; |
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
16 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7491
diff
changeset
|
17 |
public class RoomlistAdapter extends ObservableTreeMapAdapter<String, RoomWithId> { |
7342
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
18 |
private Context context; |
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
19 |
|
7461
38acbfdb484f
Hedgeroid: Started to implement RoomActivity
Medo <smaxein@googlemail.com>
parents:
7358
diff
changeset
|
20 |
public RoomlistAdapter(Context context) { |
7342
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
21 |
this.context = context; |
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
22 |
} |
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
23 |
|
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
24 |
@Override |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7491
diff
changeset
|
25 |
protected Comparator<RoomWithId> getEntryOrder() { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7491
diff
changeset
|
26 |
return RoomWithId.NEWEST_FIRST_ORDER; |
7342
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
27 |
} |
7476
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
7461
diff
changeset
|
28 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7491
diff
changeset
|
29 |
@Override |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7491
diff
changeset
|
30 |
public long getItemId(int position) { |
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7491
diff
changeset
|
31 |
return getItem(position).id; |
7342
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
32 |
} |
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7491
diff
changeset
|
33 |
|
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7491
diff
changeset
|
34 |
@Override |
7342
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
35 |
public boolean hasStableIds() { |
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
36 |
return true; |
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
37 |
} |
7352
641f11cdd319
Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents:
7349
diff
changeset
|
38 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7491
diff
changeset
|
39 |
private static CharSequence formatExtra(Resources res, Room room) { |
7342
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
40 |
String ownermsg = res.getString(R.string.roomlist_owner, room.owner); |
7485 | 41 |
String mapmsg = res.getString(R.string.roomlist_map, room.formatMapName(res)); |
7349
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
42 |
String scheme = room.scheme.equals(room.weapons) ? room.scheme : room.scheme + " / " + room.weapons; |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
43 |
String schememsg = res.getString(R.string.roomlist_scheme, scheme); |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
44 |
return ownermsg + ". " + mapmsg + ", " + schememsg; |
7342
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
45 |
} |
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
46 |
|
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
47 |
public View getView(int position, View convertView, ViewGroup parent) { |
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
48 |
View v = convertView; |
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
49 |
if (v == null) { |
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
50 |
LayoutInflater vi = LayoutInflater.from(context); |
7349
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
51 |
v = vi.inflate(R.layout.listview_room, null); |
7342
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
52 |
} |
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
53 |
|
7508
763d3961400b
Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
7491
diff
changeset
|
54 |
Room room = getItem(position).room; |
7342
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
55 |
int iconRes = room.inProgress ? R.drawable.roomlist_ingame : R.drawable.roomlist_preparing; |
7349
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
56 |
|
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
57 |
if(v.findViewById(android.R.id.text1) == null) { |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
58 |
// Tabular room list |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
59 |
TextView roomnameView = (TextView)v.findViewById(R.id.roomname); |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
60 |
TextView playerCountView = (TextView)v.findViewById(R.id.playercount); |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
61 |
TextView teamCountView = (TextView)v.findViewById(R.id.teamcount); |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
62 |
TextView ownerView = (TextView)v.findViewById(R.id.owner); |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
63 |
TextView mapView = (TextView)v.findViewById(R.id.map); |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
64 |
TextView schemeView = (TextView)v.findViewById(R.id.scheme); |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
65 |
TextView weaponView = (TextView)v.findViewById(R.id.weapons); |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
66 |
|
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
67 |
roomnameView.setCompoundDrawablesWithIntrinsicBounds(iconRes, 0, 0, 0); |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
68 |
roomnameView.setText(room.name); |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
69 |
if(playerCountView != null) { |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
70 |
playerCountView.setText(String.valueOf(room.playerCount)); |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
71 |
} |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
72 |
if(teamCountView != null) { |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
73 |
teamCountView.setText(String.valueOf(room.teamCount)); |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
74 |
} |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
75 |
ownerView.setText(room.owner); |
7485 | 76 |
mapView.setText(room.formatMapName(context.getResources())); |
7349
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
77 |
schemeView.setText(room.scheme); |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
78 |
weaponView.setText(room.weapons); |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
79 |
} else { |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
80 |
// Small room list |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
81 |
TextView v1 = (TextView)v.findViewById(android.R.id.text1); |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
82 |
TextView v2 = (TextView)v.findViewById(android.R.id.text2); |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
83 |
|
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
84 |
v1.setCompoundDrawablesWithIntrinsicBounds(iconRes, 0, 0, 0); |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
85 |
v1.setText(room.name); |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
86 |
v2.setText(formatExtra(context.getResources(), room)); |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
87 |
} |
12fdfd2038d4
Hedgeroid: More work on the lobby activity
Medo <smaxein@googlemail.com>
parents:
7342
diff
changeset
|
88 |
|
7342
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
89 |
return v; |
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
90 |
} |
0e29eec2df5c
Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
91 |
} |