1 package org.hedgewars.hedgeroid.netplay; |
|
2 |
|
3 import org.hedgewars.hedgeroid.R; |
|
4 import org.hedgewars.hedgeroid.Datastructures.Player; |
|
5 |
|
6 import android.os.Bundle; |
|
7 import android.support.v4.app.ListFragment; |
|
8 import android.view.ContextMenu; |
|
9 import android.view.ContextMenu.ContextMenuInfo; |
|
10 import android.view.LayoutInflater; |
|
11 import android.view.MenuInflater; |
|
12 import android.view.MenuItem; |
|
13 import android.view.View; |
|
14 import android.view.ViewGroup; |
|
15 import android.widget.AdapterView.AdapterContextMenuInfo; |
|
16 |
|
17 public class LobbyPlayerlistFragment extends ListFragment { |
|
18 private Netplay netplay; |
|
19 private LobbyPlayerlistAdapter adapter; |
|
20 |
|
21 @Override |
|
22 public void onCreate(Bundle savedInstanceState) { |
|
23 super.onCreate(savedInstanceState); |
|
24 netplay = Netplay.getAppInstance(getActivity().getApplicationContext()); |
|
25 adapter = new LobbyPlayerlistAdapter(getActivity()); |
|
26 adapter.setSource(netplay.lobbyPlayerlist); |
|
27 setListAdapter(adapter); |
|
28 } |
|
29 |
|
30 @Override |
|
31 public void onDestroy() { |
|
32 super.onDestroy(); |
|
33 adapter.invalidate(); |
|
34 } |
|
35 |
|
36 @Override |
|
37 public void onActivityCreated(Bundle savedInstanceState) { |
|
38 super.onActivityCreated(savedInstanceState); |
|
39 registerForContextMenu(getListView()); |
|
40 } |
|
41 |
|
42 @Override |
|
43 public void onCreateContextMenu(ContextMenu menu, View v, |
|
44 ContextMenuInfo menuInfo) { |
|
45 super.onCreateContextMenu(menu, v, menuInfo); |
|
46 AdapterContextMenuInfo info = (AdapterContextMenuInfo)menuInfo; |
|
47 MenuInflater inflater = getActivity().getMenuInflater(); |
|
48 inflater.inflate(R.menu.lobby_playerlist_context, menu); |
|
49 menu.setHeaderIcon(R.drawable.human); |
|
50 menu.setHeaderTitle(adapter.getItem(info.position).name); |
|
51 } |
|
52 |
|
53 @Override |
|
54 public boolean onContextItemSelected(MenuItem item) { |
|
55 AdapterContextMenuInfo info = (AdapterContextMenuInfo)item.getMenuInfo(); |
|
56 Player player = adapter.getItem(info.position); |
|
57 switch(item.getItemId()) { |
|
58 case R.id.player_info: |
|
59 netplay.sendPlayerInfoQuery(player.name); |
|
60 return true; |
|
61 case R.id.player_follow: |
|
62 netplay.sendFollowPlayer(player.name); |
|
63 return true; |
|
64 default: |
|
65 return super.onContextItemSelected(item); |
|
66 } |
|
67 } |
|
68 |
|
69 @Override |
|
70 public View onCreateView(LayoutInflater inflater, ViewGroup container, |
|
71 Bundle savedInstanceState) { |
|
72 return inflater.inflate(R.layout.fragment_playerlist, container, false); |
|
73 } |
|
74 } |
|