author | Medo <smaxein@googlemail.com> |
Mon, 06 Aug 2012 22:39:36 +0200 | |
changeset 7476 | 2fb781bbdd51 |
permissions | -rw-r--r-- |
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 org.hedgewars.hedgeroid.R; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
4 |
import org.hedgewars.hedgeroid.netplay.RoomPlayerlist.PlayerInRoom; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
5 |
|
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
6 |
import android.os.Bundle; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
7 |
import android.support.v4.app.ListFragment; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
8 |
import android.view.ContextMenu; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
9 |
import android.view.ContextMenu.ContextMenuInfo; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
10 |
import android.view.LayoutInflater; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
11 |
import android.view.MenuInflater; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
12 |
import android.view.MenuItem; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
13 |
import android.view.View; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
14 |
import android.view.ViewGroup; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
15 |
import android.widget.AdapterView.AdapterContextMenuInfo; |
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 class RoomPlayerlistFragment extends ListFragment { |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
18 |
private Netplay netplay; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
19 |
private RoomPlayerlistAdapter adapter; |
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 |
public void onCreate(Bundle savedInstanceState) { |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
23 |
super.onCreate(savedInstanceState); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
24 |
netplay = Netplay.getAppInstance(getActivity().getApplicationContext()); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
25 |
adapter = new RoomPlayerlistAdapter(getActivity()); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
26 |
adapter.setSource(netplay.roomPlayerlist); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
27 |
setListAdapter(adapter); |
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 |
@Override |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
31 |
public void onDestroy() { |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
32 |
super.onDestroy(); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
33 |
adapter.invalidate(); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
34 |
} |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
35 |
|
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
36 |
@Override |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
37 |
public void onActivityCreated(Bundle savedInstanceState) { |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
38 |
super.onActivityCreated(savedInstanceState); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
39 |
registerForContextMenu(getListView()); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
40 |
} |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
41 |
|
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
42 |
@Override |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
43 |
public void onCreateContextMenu(ContextMenu menu, View v, |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
44 |
ContextMenuInfo menuInfo) { |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
45 |
super.onCreateContextMenu(menu, v, menuInfo); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
46 |
AdapterContextMenuInfo info = (AdapterContextMenuInfo)menuInfo; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
47 |
String playerName = adapter.getItem(info.position).player.name; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
48 |
|
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
49 |
MenuInflater inflater = getActivity().getMenuInflater(); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
50 |
inflater.inflate(R.menu.room_playerlist_context, menu); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
51 |
if(netplay.isChief() && !playerName.equals(netplay.getPlayerName())) { |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
52 |
inflater.inflate(R.menu.room_playerlist_chief_context, menu); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
53 |
} |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
54 |
menu.setHeaderIcon(R.drawable.human); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
55 |
menu.setHeaderTitle(playerName); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
56 |
} |
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 |
@Override |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
59 |
public boolean onContextItemSelected(MenuItem item) { |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
60 |
AdapterContextMenuInfo info = (AdapterContextMenuInfo)item.getMenuInfo(); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
61 |
PlayerInRoom player = adapter.getItem(info.position); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
62 |
switch(item.getItemId()) { |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
63 |
case R.id.player_info: |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
64 |
netplay.sendPlayerInfoQuery(player.player.name); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
65 |
return true; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
66 |
case R.id.player_kick: |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
67 |
netplay.sendKick(player.player.name); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
68 |
return true; |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
69 |
default: |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
70 |
return super.onContextItemSelected(item); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
71 |
} |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
72 |
} |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
73 |
|
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
74 |
@Override |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
75 |
public View onCreateView(LayoutInflater inflater, ViewGroup container, |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
76 |
Bundle savedInstanceState) { |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
77 |
return inflater.inflate(R.layout.fragment_playerlist, container, false); |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
78 |
} |
2fb781bbdd51
Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents:
diff
changeset
|
79 |
} |