blob: 4b3f516cf54ed07f828eb747c617274589dba2cd [file] [log] [blame]
alisionfde875f2013-05-28 17:01:54 -04001/*
alision2ec64f92013-06-17 17:28:58 -04002 * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
alisionfde875f2013-05-28 17:01:54 -04003 *
4 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * Additional permission under GNU GPL version 3 section 7:
21 *
22 * If you modify this program, or any covered work, by linking or
23 * combining it with the OpenSSL project's OpenSSL library (or a
24 * modified version of that library), containing parts covered by the
25 * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
26 * grants you additional permission to convey the resulting work.
27 * Corresponding Source for a non-source form of such a combination
28 * shall include the source code for the parts of OpenSSL used as well
29 * as that of the covered work.
30 */
31
32package com.savoirfairelinux.sflphone.fragments;
33
34import java.util.ArrayList;
35import java.util.HashMap;
36
37import android.app.Activity;
alision465ceba2013-07-04 09:24:30 -040038import android.app.AlertDialog;
39import android.app.Dialog;
40import android.app.DialogFragment;
alisionfde875f2013-05-28 17:01:54 -040041import android.app.Fragment;
alisionb1763882013-06-18 17:30:51 -040042import android.app.FragmentManager;
alision465ceba2013-07-04 09:24:30 -040043import android.content.ClipData;
44import android.content.ClipData.Item;
alisionb1763882013-06-18 17:30:51 -040045import android.content.Context;
alision465ceba2013-07-04 09:24:30 -040046import android.content.DialogInterface;
alisionb1763882013-06-18 17:30:51 -040047import android.content.Intent;
alision465ceba2013-07-04 09:24:30 -040048import android.graphics.Color;
alisionfde875f2013-05-28 17:01:54 -040049import android.os.Bundle;
50import android.os.RemoteException;
alision465ceba2013-07-04 09:24:30 -040051import android.os.Vibrator;
alisionfde875f2013-05-28 17:01:54 -040052import android.util.Log;
alision465ceba2013-07-04 09:24:30 -040053import android.view.DragEvent;
alisionfde875f2013-05-28 17:01:54 -040054import android.view.LayoutInflater;
55import android.view.View;
alision465ceba2013-07-04 09:24:30 -040056import android.view.View.DragShadowBuilder;
57import android.view.View.OnDragListener;
alisionfde875f2013-05-28 17:01:54 -040058import android.view.ViewGroup;
alision465ceba2013-07-04 09:24:30 -040059import android.widget.AdapterView;
60import android.widget.AdapterView.OnItemClickListener;
61import android.widget.AdapterView.OnItemLongClickListener;
62import android.widget.ArrayAdapter;
63import android.widget.BaseAdapter;
64import android.widget.ListAdapter;
65import android.widget.ListView;
alisionb1763882013-06-18 17:30:51 -040066import android.widget.TextView;
alision1005ba12013-06-19 13:52:44 -040067import android.widget.Toast;
alisionfde875f2013-05-28 17:01:54 -040068
69import com.savoirfairelinux.sflphone.R;
alision806e18e2013-06-21 15:30:17 -040070import com.savoirfairelinux.sflphone.model.Conference;
alisionfde875f2013-05-28 17:01:54 -040071import com.savoirfairelinux.sflphone.model.SipCall;
72import com.savoirfairelinux.sflphone.service.ISipService;
alision465ceba2013-07-04 09:24:30 -040073import com.savoirfairelinux.sflphone.views.SwipeListViewTouchListener;
alisionfde875f2013-05-28 17:01:54 -040074
75public class CallListFragment extends Fragment {
alision806e18e2013-06-21 15:30:17 -040076 static final String TAG = CallListFragment.class.getSimpleName();
alisionfde875f2013-05-28 17:01:54 -040077
78 private Callbacks mCallbacks = sDummyCallbacks;
79
80 CallListAdapter mAdapter;
81
alision1005ba12013-06-19 13:52:44 -040082 public static final int REQUEST_TRANSFER = 10;
83 public static final int REQUEST_CONF = 20;
84
alisionfde875f2013-05-28 17:01:54 -040085 @Override
86 public void onCreate(Bundle savedBundle) {
87 super.onCreate(savedBundle);
88
alisionb1763882013-06-18 17:30:51 -040089 mAdapter = new CallListAdapter(getActivity());
alisionfde875f2013-05-28 17:01:54 -040090
91 }
92
93 /**
94 * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity.
95 */
96 private static Callbacks sDummyCallbacks = new Callbacks() {
97
98 @Override
99 public ISipService getService() {
alisionfde875f2013-05-28 17:01:54 -0400100 return null;
101 }
alision85992112013-05-29 12:18:08 -0400102
103 @Override
alisiondf1dac92013-06-27 17:35:53 -0400104 public void onCallSelected(Conference conf) {
alision806e18e2013-06-21 15:30:17 -0400105 }
106
107 @Override
108 public void onCallsTerminated() {
alision85992112013-05-29 12:18:08 -0400109 }
alisionfde875f2013-05-28 17:01:54 -0400110 };
111
112 /**
113 * The Activity calling this fragment has to implement this interface
114 *
115 */
116 public interface Callbacks {
117 public ISipService getService();
alisionb1763882013-06-18 17:30:51 -0400118
alisiondf1dac92013-06-27 17:35:53 -0400119 public void onCallSelected(Conference conf);
alision806e18e2013-06-21 15:30:17 -0400120
121 public void onCallsTerminated();
alisionfde875f2013-05-28 17:01:54 -0400122
123 }
124
125 @Override
126 public void onAttach(Activity activity) {
127 super.onAttach(activity);
128
129 if (!(activity instanceof Callbacks)) {
130 throw new IllegalStateException("Activity must implement fragment's callbacks.");
131 }
132
133 mCallbacks = (Callbacks) activity;
134 }
135
136 @Override
137 public void onDetach() {
138 super.onDetach();
139 mCallbacks = sDummyCallbacks;
140 }
141
alision465ceba2013-07-04 09:24:30 -0400142 ListView list;
alisionb1763882013-06-18 17:30:51 -0400143
alisionfde875f2013-05-28 17:01:54 -0400144 @Override
145 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
146 ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.frag_call_list, container, false);
147
alision465ceba2013-07-04 09:24:30 -0400148 list = (ListView) rootView.findViewById(R.id.call_list);
alisionb1763882013-06-18 17:30:51 -0400149
alision465ceba2013-07-04 09:24:30 -0400150 list.setDivider(getResources().getDrawable(android.R.drawable.divider_horizontal_dark));
151 list.setDividerHeight(10);
152 list.setAdapter(mAdapter);
153 list.setOnItemClickListener(mItemClickListener);
154 list.setOnTouchListener(new SwipeListViewTouchListener(list, new SwipeListViewTouchListener.OnSwipeCallback() {
155 @Override
156 public void onSwipeLeft(ListView listView, int[] reverseSortedPositions) {
157 // Log.i(this.getClass().getName(), "swipe left : pos="+reverseSortedPositions[0]);
158 // TODO : YOUR CODE HERE FOR LEFT ACTION
alisionf2ae4362013-07-05 16:16:12 -0400159 Conference tmp = mAdapter.getItem(reverseSortedPositions[0]);
160 try {
161 if (tmp.hasMultipleParticipants()) {
162 mCallbacks.getService().hangUpConference(tmp.getId());
163 } else {
164 mCallbacks.getService().hangUp(tmp.getParticipants().get(0).getCallId());
165 }
166 } catch (RemoteException e) {
167 // TODO Auto-generated catch block
168 e.printStackTrace();
169 }
170
alision465ceba2013-07-04 09:24:30 -0400171 }
172
173 @Override
174 public void onSwipeRight(ListView listView, int[] reverseSortedPositions) {
175 // Log.i(ProfileMenuActivity.class.getClass().getName(), "swipe right : pos="+reverseSortedPositions[0]);
176 // TODO : YOUR CODE HERE FOR RIGHT ACTION
alisionf2ae4362013-07-05 16:16:12 -0400177
178 Conference tmp = mAdapter.getItem(reverseSortedPositions[0]);
179 try {
180 if (tmp.hasMultipleParticipants()) {
181 if (tmp.isOnHold()) {
182 mCallbacks.getService().unholdConference(tmp.getId());
183 } else {
184 mCallbacks.getService().holdConference(tmp.getId());
185 }
186 } else {
187 if (tmp.isOnHold()) {
188 Toast.makeText(getActivity(), "call is on hold, unholding", Toast.LENGTH_SHORT).show();
189 mCallbacks.getService().unhold(tmp.getParticipants().get(0).getCallId());
190 } else {
191 Toast.makeText(getActivity(), "call is current, holding", Toast.LENGTH_SHORT).show();
192 mCallbacks.getService().hold(tmp.getParticipants().get(0).getCallId());
193 }
194 }
195 } catch (RemoteException e) {
196 // TODO Auto-generated catch block
197 e.printStackTrace();
198 }
alision465ceba2013-07-04 09:24:30 -0400199 }
200 }, true, // example : left action = dismiss
201 false)); // example : right action without dismiss animation);
202 list.setOnItemLongClickListener(mItemLongClickListener);
203
alisionfde875f2013-05-28 17:01:54 -0400204 return rootView;
205 }
206
alision465ceba2013-07-04 09:24:30 -0400207 OnDragListener dragListener = new OnDragListener() {
208
209 @Override
210 public boolean onDrag(View v, DragEvent event) {
211 switch (event.getAction()) {
212 case DragEvent.ACTION_DRAG_STARTED:
213 // Do nothing
214 Log.w(TAG, "ACTION_DRAG_STARTED");
215 break;
216 case DragEvent.ACTION_DRAG_ENTERED:
217 Log.w(TAG, "ACTION_DRAG_ENTERED");
218 v.setBackgroundColor(Color.GREEN);
219 break;
220 case DragEvent.ACTION_DRAG_EXITED:
221 Log.w(TAG, "ACTION_DRAG_EXITED");
222 v.setBackgroundDrawable(getResources().getDrawable(R.drawable.item_call_selector));
223 break;
224 case DragEvent.ACTION_DROP:
225 Log.w(TAG, "ACTION_DROP");
226 View view = (View) event.getLocalState();
227
228 Item i = event.getClipData().getItemAt(0);
229 Intent intent = i.getIntent();
230 intent.setExtrasClassLoader(Conference.class.getClassLoader());
231
232 Conference initial = (Conference) view.getTag();
233 Conference target = (Conference) v.getTag();
alisionf2ae4362013-07-05 16:16:12 -0400234
235 if (initial == target) {
alision465ceba2013-07-04 09:24:30 -0400236 return true;
237 }
238
239 DropActionsChoice dialog = DropActionsChoice.newInstance();
240 Bundle b = new Bundle();
241 b.putParcelable("call_initial", initial);
242 b.putParcelable("call_targeted", target);
243 dialog.setArguments(b);
244 dialog.setTargetFragment(CallListFragment.this, 0);
245 dialog.show(getFragmentManager(), "dialog");
246
247 Toast.makeText(
248 getActivity(),
249 "Dropped " + initial.getParticipants().get(0).getContact().getmDisplayName() + " on "
250 + target.getParticipants().get(0).getContact().getmDisplayName(), Toast.LENGTH_SHORT).show();
251 // view.setBackgroundColor(Color.WHITE);
252 // v.setBackgroundColor(Color.BLACK);
253 break;
254 case DragEvent.ACTION_DRAG_ENDED:
255 Log.w(TAG, "ACTION_DRAG_ENDED");
256 View view1 = (View) event.getLocalState();
257 view1.setVisibility(View.VISIBLE);
258 v.setBackgroundDrawable(getResources().getDrawable(R.drawable.item_call_selector));
259 default:
260 break;
261 }
262 return true;
263 }
264
265 };
266
267 private OnItemLongClickListener mItemLongClickListener = new OnItemLongClickListener() {
268
269 @Override
270 public boolean onItemLongClick(AdapterView<?> arg0, View view, int pos, long arg3) {
271 final Vibrator vibe = (Vibrator) view.getContext().getSystemService(Context.VIBRATOR_SERVICE);
272 vibe.vibrate(80);
273 Intent i = new Intent();
274 Bundle b = new Bundle();
275 b.putParcelable("conference", mAdapter.getItem(pos));
276 i.putExtra("bconference", b);
alisionf2ae4362013-07-05 16:16:12 -0400277
278 DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
alision465ceba2013-07-04 09:24:30 -0400279 ClipData data = ClipData.newIntent("conference", i);
280 view.startDrag(data, shadowBuilder, view, 0);
281 return false;
282 }
283
284 };
285
286 private OnItemClickListener mItemClickListener = new OnItemClickListener() {
287
288 @Override
289 public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
290 mCallbacks.onCallSelected(mAdapter.getItem(pos));
291
292 }
293 };
294
alisionfde875f2013-05-28 17:01:54 -0400295 public void update() {
296 try {
alision806e18e2013-06-21 15:30:17 -0400297 Log.w(TAG, "Updating");
alisionfde875f2013-05-28 17:01:54 -0400298 HashMap<String, SipCall> list = (HashMap<String, SipCall>) mCallbacks.getService().getCallList();
alision806e18e2013-06-21 15:30:17 -0400299
alisiondf1dac92013-06-27 17:35:53 -0400300 // Toast.makeText(getActivity(), "Calls: " + list.size(), Toast.LENGTH_SHORT).show();
alision806e18e2013-06-21 15:30:17 -0400301 ArrayList<Conference> conferences = new ArrayList<Conference>();
alisiondf1dac92013-06-27 17:35:53 -0400302 HashMap<String, Conference> tmp = (HashMap<String, Conference>) mCallbacks.getService().getConferenceList();
303 conferences.addAll(tmp.values());
alision806e18e2013-06-21 15:30:17 -0400304
305 ArrayList<SipCall> simple_calls = new ArrayList<SipCall>(list.values());
306 for (SipCall call : simple_calls) {
alisiondf1dac92013-06-27 17:35:53 -0400307 Log.w(TAG, "SimpleCall:" + call.getCallId());
alision806e18e2013-06-21 15:30:17 -0400308 Conference confOne = new Conference("-1");
309 confOne.getParticipants().add(call);
310 conferences.add(confOne);
311 }
alisiondf1dac92013-06-27 17:35:53 -0400312
313 if (conferences.isEmpty()) {
alision806e18e2013-06-21 15:30:17 -0400314 mCallbacks.onCallsTerminated();
315 }
316
317 mAdapter.update(conferences);
alisionfde875f2013-05-28 17:01:54 -0400318 } catch (RemoteException e) {
319 Log.e(TAG, e.toString());
320 }
321
322 }
alisionb1763882013-06-18 17:30:51 -0400323
alision1005ba12013-06-19 13:52:44 -0400324 private void makeTransferDialog(int groupPosition) {
alisionb1763882013-06-18 17:30:51 -0400325 FragmentManager fm = getFragmentManager();
alision1005ba12013-06-19 13:52:44 -0400326 TransferDFragment editNameDialog = new TransferDFragment();
alisionb1763882013-06-18 17:30:51 -0400327
alision465ceba2013-07-04 09:24:30 -0400328 if (!mAdapter.getItem(groupPosition).hasMultipleParticipants()) {
alision806e18e2013-06-21 15:30:17 -0400329 Bundle b = new Bundle();
330 b.putParcelableArrayList("calls", mAdapter.getConcurrentCalls(groupPosition));
alision465ceba2013-07-04 09:24:30 -0400331 b.putParcelable("call_selected", mAdapter.getItem(groupPosition));
alision806e18e2013-06-21 15:30:17 -0400332 editNameDialog.setArguments(b);
333 editNameDialog.setTargetFragment(this, REQUEST_TRANSFER);
334 editNameDialog.show(fm, "dialog");
335 } else {
336 Toast.makeText(getActivity(), "Transfer a Conference ?", Toast.LENGTH_SHORT).show();
337 }
alisionb1763882013-06-18 17:30:51 -0400338
339 }
340
alision1005ba12013-06-19 13:52:44 -0400341 private void makeConferenceDialog(int groupPosition) {
342 FragmentManager fm = getFragmentManager();
alision806e18e2013-06-21 15:30:17 -0400343 ConferenceDFragment confDialog = ConferenceDFragment.newInstance();
alision1005ba12013-06-19 13:52:44 -0400344
alisiondf1dac92013-06-27 17:35:53 -0400345 Bundle b = new Bundle();
346 b.putParcelableArrayList("calls", mAdapter.getConcurrentCalls(groupPosition));
alision465ceba2013-07-04 09:24:30 -0400347 b.putParcelable("call_selected", mAdapter.getItem(groupPosition));
alisiondf1dac92013-06-27 17:35:53 -0400348 confDialog.setArguments(b);
349 confDialog.setTargetFragment(this, REQUEST_CONF);
350 confDialog.show(fm, "dialog");
alision1005ba12013-06-19 13:52:44 -0400351
352 }
353
alisionb1763882013-06-18 17:30:51 -0400354 @Override
355 public void onActivityResult(int requestCode, int resultCode, Intent data) {
356 super.onActivityResult(requestCode, resultCode, data);
alisiondf1dac92013-06-27 17:35:53 -0400357 Conference transfer = null;
alision1005ba12013-06-19 13:52:44 -0400358 if (requestCode == REQUEST_TRANSFER) {
359 switch (resultCode) {
360 case 0:
alisiondf1dac92013-06-27 17:35:53 -0400361 Conference c = data.getParcelableExtra("target");
alision1005ba12013-06-19 13:52:44 -0400362 transfer = data.getParcelableExtra("transfer");
363 try {
alisionb1763882013-06-18 17:30:51 -0400364
alisiondf1dac92013-06-27 17:35:53 -0400365 mCallbacks.getService().attendedTransfer(transfer.getParticipants().get(0).getCallId(), c.getParticipants().get(0).getCallId());
alision1005ba12013-06-19 13:52:44 -0400366 mAdapter.remove(transfer);
alision465ceba2013-07-04 09:24:30 -0400367 mAdapter.remove(c);
alision1005ba12013-06-19 13:52:44 -0400368 mAdapter.notifyDataSetChanged();
369 } catch (RemoteException e) {
370 // TODO Auto-generated catch block
371 e.printStackTrace();
372 }
373 Toast.makeText(getActivity(), "Transfer complete", Toast.LENGTH_LONG).show();
374 break;
375
376 case 1:
377 String to = data.getStringExtra("to_number");
378 transfer = data.getParcelableExtra("transfer");
379 try {
alisiondf1dac92013-06-27 17:35:53 -0400380 Toast.makeText(getActivity(), "Transferring " + transfer.getParticipants().get(0).getContact().getmDisplayName() + " to " + to,
381 Toast.LENGTH_SHORT).show();
382 mCallbacks.getService().transfer(transfer.getParticipants().get(0).getCallId(), to);
383 mCallbacks.getService().hangUp(transfer.getParticipants().get(0).getCallId());
alision1005ba12013-06-19 13:52:44 -0400384 } catch (RemoteException e) {
385 // TODO Auto-generated catch block
386 e.printStackTrace();
387 }
388 break;
389
390 default:
391 break;
alisionb1763882013-06-18 17:30:51 -0400392 }
alision907bde72013-06-20 14:40:37 -0400393 } else if (requestCode == REQUEST_CONF) {
alision1005ba12013-06-19 13:52:44 -0400394 switch (resultCode) {
395 case 0:
alision465ceba2013-07-04 09:24:30 -0400396 Conference call_to_add = data.getParcelableExtra("transfer");
397 Conference call_target = data.getParcelableExtra("target");
alision1005ba12013-06-19 13:52:44 -0400398
alision465ceba2013-07-04 09:24:30 -0400399 bindCalls(call_to_add, call_target);
alision1005ba12013-06-19 13:52:44 -0400400 break;
401
402 default:
403 break;
404 }
alisionb1763882013-06-18 17:30:51 -0400405 }
406 }
407
alision465ceba2013-07-04 09:24:30 -0400408 private void bindCalls(Conference call_to_add, Conference call_target) {
409 try {
410
411 if (call_target.hasMultipleParticipants() && !call_to_add.hasMultipleParticipants()) {
412
413 mCallbacks.getService().addParticipant(call_to_add.getParticipants().get(0), call_target.getId());
414
415 } else if (call_target.hasMultipleParticipants() && call_to_add.hasMultipleParticipants()) {
416
417 // We join two conferences
418 mCallbacks.getService().joinConference(call_to_add.getId(), call_target.getId());
419
420 } else if (!call_target.hasMultipleParticipants() && call_to_add.hasMultipleParticipants()) {
421
422 mCallbacks.getService().addParticipant(call_target.getParticipants().get(0), call_to_add.getId());
423
424 } else {
425 // We join two single calls to create a conf
426 mCallbacks.getService().joinParticipant(call_to_add.getParticipants().get(0).getCallId(),
427 call_target.getParticipants().get(0).getCallId());
428 }
429
430 } catch (RemoteException e) {
431 // TODO Auto-generated catch block
432 e.printStackTrace();
433 }
434 }
435
436 public class CallListAdapter extends BaseAdapter {
alision806e18e2013-06-21 15:30:17 -0400437
438 private ArrayList<Conference> calls;
alisionb1763882013-06-18 17:30:51 -0400439
440 private Context mContext;
alisionb1763882013-06-18 17:30:51 -0400441
alision465ceba2013-07-04 09:24:30 -0400442 public CallListAdapter(Context act) {
443 super();
444 mContext = act;
alision806e18e2013-06-21 15:30:17 -0400445 calls = new ArrayList<Conference>();
alision1005ba12013-06-19 13:52:44 -0400446
447 }
448
alision806e18e2013-06-21 15:30:17 -0400449 public ArrayList<Conference> getConcurrentCalls(int position) {
450 ArrayList<Conference> toReturn = new ArrayList<Conference>();
alisionb1763882013-06-18 17:30:51 -0400451 for (int i = 0; i < calls.size(); ++i) {
alision1005ba12013-06-19 13:52:44 -0400452 if (position != i)
alisionb1763882013-06-18 17:30:51 -0400453 toReturn.add(calls.get(i));
454 }
455 return toReturn;
456 }
457
alision465ceba2013-07-04 09:24:30 -0400458 public void remove(Conference transfer) {
alision85992112013-05-29 12:18:08 -0400459
alisionb1763882013-06-18 17:30:51 -0400460 }
461
alision806e18e2013-06-21 15:30:17 -0400462 public void update(ArrayList<Conference> list) {
alisionb1763882013-06-18 17:30:51 -0400463 calls.clear();
alision806e18e2013-06-21 15:30:17 -0400464 calls.addAll(list);
alisionb1763882013-06-18 17:30:51 -0400465 notifyDataSetChanged();
alisionb1763882013-06-18 17:30:51 -0400466 }
467
alision465ceba2013-07-04 09:24:30 -0400468 @Override
469 public int getCount() {
470 return calls.size();
471 }
472
473 @Override
474 public Conference getItem(int position) {
475 return calls.get(position);
476 }
477
478 @Override
479 public long getItemId(int position) {
480 return 0;
481 }
482
483 @Override
484 public View getView(int position, View convertView, ViewGroup parent) {
485 if (convertView == null)
486 convertView = LayoutInflater.from(mContext).inflate(R.layout.item_calllist, null);
487
488 Conference call = calls.get(position);
489 if (call.getParticipants().size() == 1) {
490 ((TextView) convertView.findViewById(R.id.call_title)).setText(call.getParticipants().get(0).getContact().getmDisplayName());
491 } else {
alisionf2ae4362013-07-05 16:16:12 -0400492 String tmp = "Conference with "+ call.getParticipants().size()+" participants";
493// for (SipCall c : call.getParticipants()) {
494// tmp += c.getContact().getmDisplayName() + " ";
495// }
alision465ceba2013-07-04 09:24:30 -0400496 ((TextView) convertView.findViewById(R.id.call_title)).setText(tmp);
497 }
alisionf2ae4362013-07-05 16:16:12 -0400498// ((TextView) convertView.findViewById(R.id.num_participants)).setText("" + call.getParticipants().size());
alision465ceba2013-07-04 09:24:30 -0400499 ((TextView) convertView.findViewById(R.id.call_status)).setText(call.getState());
500 convertView.setOnDragListener(dragListener);
501
502 convertView.setTag(call);
503 return convertView;
504 }
505
506 }
507
508 public static class DropActionsChoice extends DialogFragment {
509
510 ListAdapter mAdapter;
511 private Bundle args;
512
513 /**
514 * Create a new instance of CallActionsDFragment
515 */
516 public static DropActionsChoice newInstance() {
517 DropActionsChoice f = new DropActionsChoice();
518 return f;
519 }
520
521 @Override
522 public void onCreate(Bundle savedInstanceState) {
523 super.onCreate(savedInstanceState);
524
525 // Pick a style based on the num.
526 int style = DialogFragment.STYLE_NORMAL, theme = 0;
527 setStyle(style, theme);
528 }
529
530 @Override
531 public Dialog onCreateDialog(Bundle savedInstanceState) {
532 ListView rootView = new ListView(getActivity());
533
534 args = getArguments();
535 mAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, getResources().getStringArray(
536 R.array.drop_actions));
537
538 // ListView list = (ListView) rootView.findViewById(R.id.concurrent_calls);
539 rootView.setAdapter(mAdapter);
540 rootView.setOnItemClickListener(new OnItemClickListener() {
541
542 @Override
543 public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
544 Intent in = new Intent();
545
546 in.putExtra("transfer", args.getParcelable("call_initial"));
547 in.putExtra("target", args.getParcelable("call_targeted"));
548
549 switch (pos) {
550 case 0: // Transfer
551 getTargetFragment().onActivityResult(REQUEST_TRANSFER, 0, in);
552 break;
553 case 1: // Conference
554 getTargetFragment().onActivityResult(REQUEST_CONF, 0, in);
555 break;
556 }
557 dismiss();
558
559 }
560 });
561
562 final AlertDialog a = new AlertDialog.Builder(getActivity()).setView(rootView).setTitle("Choose Action")
563 .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
564 public void onClick(DialogInterface dialog, int whichButton) {
565 dismiss();
566 }
567 }).create();
568
569 return a;
570 }
alisionb1763882013-06-18 17:30:51 -0400571 }
alisionfde875f2013-05-28 17:01:54 -0400572
573}