|
1 /* |
|
2 BEEM is a videoconference application on the Android Platform. |
|
3 |
|
4 Copyright (C) 2009-2011 by Frederic-Charles Barthelery, |
|
5 Nikita Kozlov, |
|
6 Vincent Veronis. |
|
7 |
|
8 This file is part of BEEM. |
|
9 |
|
10 BEEM is free software: you can redistribute it and/or modify |
|
11 it under the terms of the GNU General Public License as published by |
|
12 the Free Software Foundation, either version 3 of the License, or |
|
13 (at your option) any later version. |
|
14 |
|
15 BEEM is distributed in the hope that it will be useful, |
|
16 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18 GNU General Public License for more details. |
|
19 |
|
20 You should have received a copy of the GNU General Public License |
|
21 along with BEEM. If not, see <http://www.gnu.org/licenses/>. |
|
22 |
|
23 Please send bug reports with examples or suggestions to |
|
24 contact@beem-project.com or http://www.beem-project.com/ |
|
25 |
|
26 */ |
|
27 package com.beem.project.beem.ui; |
|
28 |
|
29 import java.util.List; |
|
30 |
|
31 import android.app.Activity; |
|
32 import android.content.Intent; |
|
33 import android.os.Bundle; |
|
34 import android.support.v4.app.ListFragment; |
|
35 import android.view.ContextMenu; |
|
36 import android.view.MenuInflater; |
|
37 import android.view.MenuItem; |
|
38 import android.view.View; |
|
39 import android.widget.AdapterView; |
|
40 import android.widget.AdapterView.AdapterContextMenuInfo; |
|
41 import android.widget.ListAdapter; |
|
42 import android.widget.ListView; |
|
43 |
|
44 import com.beem.project.beem.R; |
|
45 import com.beem.project.beem.service.Contact; |
|
46 |
|
47 /** |
|
48 * A Fragment which display a list of contacts. |
|
49 */ |
|
50 public class ContactListFragment extends ListFragment { |
|
51 private String group; |
|
52 private ContactList hostActivity; |
|
53 private Contact mSelectedContact; |
|
54 |
|
55 /** |
|
56 * Create a ContactListFragment. |
|
57 * @param group the group name |
|
58 * @return the ContactListFragment |
|
59 */ |
|
60 public static ContactListFragment newInstance(String group) { |
|
61 ContactListFragment f = new ContactListFragment(); |
|
62 Bundle b = new Bundle(); |
|
63 b.putString("group", group); |
|
64 f.setArguments(b); |
|
65 return f; |
|
66 } |
|
67 |
|
68 @Override |
|
69 public void onCreate(Bundle savedInstanceState) { |
|
70 super.onCreate(savedInstanceState); |
|
71 parseArguments(); |
|
72 } |
|
73 |
|
74 @Override |
|
75 public void onAttach(Activity activity) { |
|
76 super.onAttach(activity); |
|
77 hostActivity = (ContactList) activity; |
|
78 } |
|
79 |
|
80 @Override |
|
81 public void onActivityCreated(Bundle savedInstanceState) { |
|
82 super.onActivityCreated(savedInstanceState); |
|
83 ListAdapter adapter = hostActivity.getContactListAdapter(group); |
|
84 setListAdapter(adapter); |
|
85 registerForContextMenu(getListView()); |
|
86 } |
|
87 |
|
88 @Override |
|
89 public void onListItemClick(ListView l, View v, int position, long id) { |
|
90 ContactListAdapter a = (ContactListAdapter) getListAdapter(); |
|
91 Contact c = (Contact) a.getItem(position); |
|
92 Intent i = new Intent(getActivity(), Chat.class); |
|
93 i.setData(c.toUri()); |
|
94 startActivity(i); |
|
95 } |
|
96 |
|
97 @Override |
|
98 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { |
|
99 super.onCreateContextMenu(menu, v, menuInfo); |
|
100 MenuInflater inflater = hostActivity.getMenuInflater(); |
|
101 inflater.inflate(R.menu.contactlist_context, menu); |
|
102 AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; |
|
103 mSelectedContact = (Contact) getListAdapter().getItem(info.position); |
|
104 menu.setHeaderTitle(mSelectedContact.getJID()); |
|
105 } |
|
106 |
|
107 /** |
|
108 * Parse the arguments submit to the Fragment. |
|
109 */ |
|
110 private void parseArguments() { |
|
111 Bundle b = getArguments(); |
|
112 if (b == null) |
|
113 return; |
|
114 group = b.getString("group"); |
|
115 } |
|
116 |
|
117 @Override |
|
118 public boolean onContextItemSelected(MenuItem item) { |
|
119 Intent in; |
|
120 boolean result = false; |
|
121 if (mSelectedContact != null) { |
|
122 switch (item.getItemId()) { |
|
123 case R.id.contact_list_context_menu_chat_item: |
|
124 List<String> res = mSelectedContact.getMRes(); |
|
125 if (res.isEmpty()) { |
|
126 break; |
|
127 } |
|
128 for (String resv : res) { |
|
129 in = new Intent(hostActivity, Chat.class); |
|
130 in.setData(mSelectedContact.toUri(resv)); |
|
131 item.getSubMenu().add(resv).setIntent(in); |
|
132 } |
|
133 result = true; |
|
134 break; |
|
135 case R.id.contact_list_context_menu_call_item: |
|
136 res = mSelectedContact.getMRes(); |
|
137 if (res.isEmpty()) { |
|
138 break; |
|
139 } |
|
140 for (String resv : res) { |
|
141 in = new Intent(hostActivity, Call.class); |
|
142 in.setData(mSelectedContact.toUri(resv)); |
|
143 in.putExtra("isCaller", true); |
|
144 item.getSubMenu().add(resv).setIntent(in); |
|
145 } |
|
146 result = true; |
|
147 break; |
|
148 case R.id.contact_list_context_menu_user_info: |
|
149 item.getSubMenu().setHeaderTitle(mSelectedContact.getJID()); |
|
150 result = true; |
|
151 break; |
|
152 case R.id.contact_list_context_menu_userinfo_alias: |
|
153 hostActivity.doContextMenuAction(item.getItemId(), mSelectedContact); |
|
154 result = true; |
|
155 break; |
|
156 case R.id.contact_list_context_menu_userinfo_group: |
|
157 in = new Intent(hostActivity, GroupList.class); |
|
158 in.putExtra("contact", mSelectedContact); |
|
159 startActivity(in); |
|
160 result = true; |
|
161 break; |
|
162 case R.id.contact_list_context_menu_userinfo_subscription: |
|
163 hostActivity.doContextMenuAction(item.getItemId(), mSelectedContact); |
|
164 result = true; |
|
165 break; |
|
166 case R.id.contact_list_context_menu_userinfo_block: |
|
167 result = true; |
|
168 break; |
|
169 case R.id.contact_list_context_menu_userinfo_delete: |
|
170 hostActivity.doContextMenuAction(item.getItemId(), mSelectedContact); |
|
171 result = true; |
|
172 break; |
|
173 default: |
|
174 result = super.onContextItemSelected(item); |
|
175 break; |
|
176 } |
|
177 return result; |
|
178 } |
|
179 return super.onContextItemSelected(item); |
|
180 } |
|
181 |
|
182 } |