blob: f26d9e7ea35b134a90cd3a73028439f8f797e3c8 [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
Alexandre Lision064e1e02013-10-01 16:18:42 -040032package org.sflphone.fragments;
alisionfde875f2013-05-28 17:01:54 -040033
34import java.util.ArrayList;
35import java.util.HashMap;
36
Alexandre Lision064e1e02013-10-01 16:18:42 -040037import org.sflphone.R;
38import org.sflphone.model.Conference;
39import org.sflphone.model.SipCall;
40import org.sflphone.service.ISipService;
Alexandre Lision064e1e02013-10-01 16:18:42 -040041
alisionfde875f2013-05-28 17:01:54 -040042import android.app.Activity;
alision465ceba2013-07-04 09:24:30 -040043import android.app.AlertDialog;
44import android.app.Dialog;
45import android.app.DialogFragment;
alisionfde875f2013-05-28 17:01:54 -040046import android.app.Fragment;
alision465ceba2013-07-04 09:24:30 -040047import android.content.ClipData;
48import android.content.ClipData.Item;
alisionb1763882013-06-18 17:30:51 -040049import android.content.Context;
alision465ceba2013-07-04 09:24:30 -040050import android.content.DialogInterface;
alisionb1763882013-06-18 17:30:51 -040051import android.content.Intent;
alision465ceba2013-07-04 09:24:30 -040052import android.graphics.Color;
alisionfde875f2013-05-28 17:01:54 -040053import android.os.Bundle;
54import android.os.RemoteException;
alision465ceba2013-07-04 09:24:30 -040055import android.os.Vibrator;
alisionfde875f2013-05-28 17:01:54 -040056import android.util.Log;
alision465ceba2013-07-04 09:24:30 -040057import android.view.DragEvent;
alisionfde875f2013-05-28 17:01:54 -040058import android.view.LayoutInflater;
59import android.view.View;
alision465ceba2013-07-04 09:24:30 -040060import android.view.View.DragShadowBuilder;
61import android.view.View.OnDragListener;
alisionfde875f2013-05-28 17:01:54 -040062import android.view.ViewGroup;
alision465ceba2013-07-04 09:24:30 -040063import android.widget.AdapterView;
64import android.widget.AdapterView.OnItemClickListener;
65import android.widget.AdapterView.OnItemLongClickListener;
66import android.widget.ArrayAdapter;
67import android.widget.BaseAdapter;
68import android.widget.ListAdapter;
69import android.widget.ListView;
alisionb1763882013-06-18 17:30:51 -040070import android.widget.TextView;
alision1005ba12013-06-19 13:52:44 -040071import android.widget.Toast;
alisionfde875f2013-05-28 17:01:54 -040072
alisionfde875f2013-05-28 17:01:54 -040073public class CallListFragment extends Fragment {
alision806e18e2013-06-21 15:30:17 -040074 static final String TAG = CallListFragment.class.getSimpleName();
alisionfde875f2013-05-28 17:01:54 -040075
76 private Callbacks mCallbacks = sDummyCallbacks;
77
78 CallListAdapter mAdapter;
79
alision1005ba12013-06-19 13:52:44 -040080 public static final int REQUEST_TRANSFER = 10;
81 public static final int REQUEST_CONF = 20;
82
alisionfde875f2013-05-28 17:01:54 -040083 @Override
84 public void onCreate(Bundle savedBundle) {
85 super.onCreate(savedBundle);
86
alisionb1763882013-06-18 17:30:51 -040087 mAdapter = new CallListAdapter(getActivity());
alisionfde875f2013-05-28 17:01:54 -040088
89 }
90
91 /**
92 * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity.
93 */
94 private static Callbacks sDummyCallbacks = new Callbacks() {
95
96 @Override
97 public ISipService getService() {
alisionfde875f2013-05-28 17:01:54 -040098 return null;
99 }
alision85992112013-05-29 12:18:08 -0400100
101 @Override
alisiondf1dac92013-06-27 17:35:53 -0400102 public void onCallSelected(Conference conf) {
alision806e18e2013-06-21 15:30:17 -0400103 }
104
105 @Override
106 public void onCallsTerminated() {
alision85992112013-05-29 12:18:08 -0400107 }
alisionfde875f2013-05-28 17:01:54 -0400108 };
109
110 /**
111 * The Activity calling this fragment has to implement this interface
112 *
113 */
114 public interface Callbacks {
115 public ISipService getService();
alisionb1763882013-06-18 17:30:51 -0400116
alisiondf1dac92013-06-27 17:35:53 -0400117 public void onCallSelected(Conference conf);
alision806e18e2013-06-21 15:30:17 -0400118
119 public void onCallsTerminated();
alisionfde875f2013-05-28 17:01:54 -0400120
121 }
122
123 @Override
124 public void onAttach(Activity activity) {
125 super.onAttach(activity);
126
127 if (!(activity instanceof Callbacks)) {
128 throw new IllegalStateException("Activity must implement fragment's callbacks.");
129 }
130
131 mCallbacks = (Callbacks) activity;
132 }
133
134 @Override
135 public void onDetach() {
136 super.onDetach();
137 mCallbacks = sDummyCallbacks;
138 }
139
alision465ceba2013-07-04 09:24:30 -0400140 ListView list;
alisionb1763882013-06-18 17:30:51 -0400141
alisionfde875f2013-05-28 17:01:54 -0400142 @Override
143 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
144 ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.frag_call_list, container, false);
145
alision465ceba2013-07-04 09:24:30 -0400146 list = (ListView) rootView.findViewById(R.id.call_list);
alisionb1763882013-06-18 17:30:51 -0400147
alision465ceba2013-07-04 09:24:30 -0400148 list.setDivider(getResources().getDrawable(android.R.drawable.divider_horizontal_dark));
149 list.setDividerHeight(10);
150 list.setAdapter(mAdapter);
151 list.setOnItemClickListener(mItemClickListener);
Alexandre Lisione168d4a2013-10-24 12:32:59 -0400152// list.setOnTouchListener(new SwipeListViewTouchListener(list, new SwipeListViewTouchListener.OnSwipeCallback() {
153// @Override
154// public void onSwipeLeft(ListView listView, int[] reverseSortedPositions) {
155// // Log.i(this.getClass().getName(), "swipe left : pos="+reverseSortedPositions[0]);
156// // TODO : YOUR CODE HERE FOR LEFT ACTION
157// Conference tmp = mAdapter.getItem(reverseSortedPositions[0]);
158// try {
159// if (tmp.hasMultipleParticipants()) {
160// mCallbacks.getService().hangUpConference(tmp.getId());
161// } else {
162// mCallbacks.getService().hangUp(tmp.getParticipants().get(0).getCallId());
163// }
164// } catch (RemoteException e) {
165// // TODO Auto-generated catch block
166// e.printStackTrace();
167// }
168//
169// }
170//
171// @Override
172// public void onSwipeRight(ListView listView, int[] reverseSortedPositions) {
173// // Log.i(ProfileMenuActivity.class.getClass().getName(), "swipe right : pos="+reverseSortedPositions[0]);
174// // TODO : YOUR CODE HERE FOR RIGHT ACTION
175//
176// Conference tmp = mAdapter.getItem(reverseSortedPositions[0]);
177// try {
178// if (tmp.hasMultipleParticipants()) {
179// if (tmp.isOnHold()) {
180// mCallbacks.getService().unholdConference(tmp.getId());
181// } else {
182// mCallbacks.getService().holdConference(tmp.getId());
183// }
184// } else {
185// if (tmp.isOnHold()) {
186// Toast.makeText(getActivity(), "call is on hold, unholding", Toast.LENGTH_SHORT).show();
187// mCallbacks.getService().unhold(tmp.getParticipants().get(0).getCallId());
188// } else {
189// Toast.makeText(getActivity(), "call is current, holding", Toast.LENGTH_SHORT).show();
190// mCallbacks.getService().hold(tmp.getParticipants().get(0).getCallId());
191// }
192// }
193// } catch (RemoteException e) {
194// // TODO Auto-generated catch block
195// e.printStackTrace();
196// }
197// }
198// }, true, // example : left action = dismiss
199// false)); // example : right action without dismiss animation);
alision465ceba2013-07-04 09:24:30 -0400200 list.setOnItemLongClickListener(mItemLongClickListener);
201
alisionfde875f2013-05-28 17:01:54 -0400202 return rootView;
203 }
204
alision465ceba2013-07-04 09:24:30 -0400205 OnDragListener dragListener = new OnDragListener() {
206
Alexandre Lision6e8931e2013-09-19 16:49:34 -0400207 @SuppressWarnings("deprecation") // deprecated in API 16....
alision465ceba2013-07-04 09:24:30 -0400208 @Override
209 public boolean onDrag(View v, DragEvent event) {
210 switch (event.getAction()) {
211 case DragEvent.ACTION_DRAG_STARTED:
212 // Do nothing
213 Log.w(TAG, "ACTION_DRAG_STARTED");
214 break;
215 case DragEvent.ACTION_DRAG_ENTERED:
216 Log.w(TAG, "ACTION_DRAG_ENTERED");
217 v.setBackgroundColor(Color.GREEN);
218 break;
219 case DragEvent.ACTION_DRAG_EXITED:
220 Log.w(TAG, "ACTION_DRAG_EXITED");
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400221 v.setBackgroundDrawable(getResources().getDrawable(R.drawable.item_contact_selector));
alision465ceba2013-07-04 09:24:30 -0400222 break;
223 case DragEvent.ACTION_DROP:
224 Log.w(TAG, "ACTION_DROP");
225 View view = (View) event.getLocalState();
226
227 Item i = event.getClipData().getItemAt(0);
228 Intent intent = i.getIntent();
229 intent.setExtrasClassLoader(Conference.class.getClassLoader());
230
231 Conference initial = (Conference) view.getTag();
232 Conference target = (Conference) v.getTag();
alisionf2ae4362013-07-05 16:16:12 -0400233
234 if (initial == target) {
alision465ceba2013-07-04 09:24:30 -0400235 return true;
236 }
237
238 DropActionsChoice dialog = DropActionsChoice.newInstance();
239 Bundle b = new Bundle();
240 b.putParcelable("call_initial", initial);
241 b.putParcelable("call_targeted", target);
242 dialog.setArguments(b);
243 dialog.setTargetFragment(CallListFragment.this, 0);
244 dialog.show(getFragmentManager(), "dialog");
245
246 Toast.makeText(
247 getActivity(),
248 "Dropped " + initial.getParticipants().get(0).getContact().getmDisplayName() + " on "
249 + target.getParticipants().get(0).getContact().getmDisplayName(), Toast.LENGTH_SHORT).show();
250 // view.setBackgroundColor(Color.WHITE);
251 // v.setBackgroundColor(Color.BLACK);
252 break;
253 case DragEvent.ACTION_DRAG_ENDED:
254 Log.w(TAG, "ACTION_DRAG_ENDED");
255 View view1 = (View) event.getLocalState();
256 view1.setVisibility(View.VISIBLE);
Alexandre Lision8b9d8e82013-10-04 09:21:27 -0400257 v.setBackgroundDrawable(getResources().getDrawable(R.drawable.item_contact_selector));
alision465ceba2013-07-04 09:24:30 -0400258 default:
259 break;
260 }
261 return true;
262 }
263
264 };
265
266 private OnItemLongClickListener mItemLongClickListener = new OnItemLongClickListener() {
267
268 @Override
269 public boolean onItemLongClick(AdapterView<?> arg0, View view, int pos, long arg3) {
270 final Vibrator vibe = (Vibrator) view.getContext().getSystemService(Context.VIBRATOR_SERVICE);
271 vibe.vibrate(80);
272 Intent i = new Intent();
273 Bundle b = new Bundle();
274 b.putParcelable("conference", mAdapter.getItem(pos));
275 i.putExtra("bconference", b);
alisionf2ae4362013-07-05 16:16:12 -0400276
277 DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
alision465ceba2013-07-04 09:24:30 -0400278 ClipData data = ClipData.newIntent("conference", i);
279 view.startDrag(data, shadowBuilder, view, 0);
280 return false;
281 }
282
283 };
284
285 private OnItemClickListener mItemClickListener = new OnItemClickListener() {
286
287 @Override
288 public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
289 mCallbacks.onCallSelected(mAdapter.getItem(pos));
290
291 }
292 };
293
Alexandre Lision6e8931e2013-09-19 16:49:34 -0400294 @SuppressWarnings("unchecked") // No proper solution with HashMap runtime cast
alisionfde875f2013-05-28 17:01:54 -0400295 public void update() {
296 try {
297 HashMap<String, SipCall> list = (HashMap<String, SipCall>) mCallbacks.getService().getCallList();
alision806e18e2013-06-21 15:30:17 -0400298
alisiondf1dac92013-06-27 17:35:53 -0400299 // Toast.makeText(getActivity(), "Calls: " + list.size(), Toast.LENGTH_SHORT).show();
alision806e18e2013-06-21 15:30:17 -0400300 ArrayList<Conference> conferences = new ArrayList<Conference>();
alisiondf1dac92013-06-27 17:35:53 -0400301 HashMap<String, Conference> tmp = (HashMap<String, Conference>) mCallbacks.getService().getConferenceList();
302 conferences.addAll(tmp.values());
alision806e18e2013-06-21 15:30:17 -0400303
304 ArrayList<SipCall> simple_calls = new ArrayList<SipCall>(list.values());
305 for (SipCall call : simple_calls) {
alision806e18e2013-06-21 15:30:17 -0400306 Conference confOne = new Conference("-1");
307 confOne.getParticipants().add(call);
308 conferences.add(confOne);
309 }
alisiondf1dac92013-06-27 17:35:53 -0400310
311 if (conferences.isEmpty()) {
alision806e18e2013-06-21 15:30:17 -0400312 mCallbacks.onCallsTerminated();
313 }
314
315 mAdapter.update(conferences);
alisionfde875f2013-05-28 17:01:54 -0400316 } catch (RemoteException e) {
317 Log.e(TAG, e.toString());
318 }
319
320 }
alisionb1763882013-06-18 17:30:51 -0400321
Alexandre Lision80a99162013-09-13 14:19:23 -0400322 // private void makeTransferDialog(int groupPosition) {
323 // FragmentManager fm = getFragmentManager();
324 // TransferDFragment editNameDialog = new TransferDFragment();
325 //
326 // if (!mAdapter.getItem(groupPosition).hasMultipleParticipants()) {
327 // Bundle b = new Bundle();
328 // b.putParcelableArrayList("calls", mAdapter.getConcurrentCalls(groupPosition));
329 // b.putParcelable("call_selected", mAdapter.getItem(groupPosition));
330 // editNameDialog.setArguments(b);
331 // editNameDialog.setTargetFragment(this, REQUEST_TRANSFER);
332 // editNameDialog.show(fm, "dialog");
333 // } else {
334 // Toast.makeText(getActivity(), "Transfer a Conference ?", Toast.LENGTH_SHORT).show();
335 // }
336 //
337 // }
338 //
339 // private void makeConferenceDialog(int groupPosition) {
340 // FragmentManager fm = getFragmentManager();
341 // ConferenceDFragment confDialog = ConferenceDFragment.newInstance();
342 //
343 // Bundle b = new Bundle();
344 // b.putParcelableArrayList("calls", mAdapter.getConcurrentCalls(groupPosition));
345 // b.putParcelable("call_selected", mAdapter.getItem(groupPosition));
346 // confDialog.setArguments(b);
347 // confDialog.setTargetFragment(this, REQUEST_CONF);
348 // confDialog.show(fm, "dialog");
349 //
350 // }
alision1005ba12013-06-19 13:52:44 -0400351
alisionb1763882013-06-18 17:30:51 -0400352 @Override
353 public void onActivityResult(int requestCode, int resultCode, Intent data) {
354 super.onActivityResult(requestCode, resultCode, data);
alisiondf1dac92013-06-27 17:35:53 -0400355 Conference transfer = null;
alision1005ba12013-06-19 13:52:44 -0400356 if (requestCode == REQUEST_TRANSFER) {
357 switch (resultCode) {
358 case 0:
alisiondf1dac92013-06-27 17:35:53 -0400359 Conference c = data.getParcelableExtra("target");
alision1005ba12013-06-19 13:52:44 -0400360 transfer = data.getParcelableExtra("transfer");
361 try {
alisionb1763882013-06-18 17:30:51 -0400362
alisiondf1dac92013-06-27 17:35:53 -0400363 mCallbacks.getService().attendedTransfer(transfer.getParticipants().get(0).getCallId(), c.getParticipants().get(0).getCallId());
alision1005ba12013-06-19 13:52:44 -0400364 mAdapter.remove(transfer);
alision465ceba2013-07-04 09:24:30 -0400365 mAdapter.remove(c);
alision1005ba12013-06-19 13:52:44 -0400366 mAdapter.notifyDataSetChanged();
367 } catch (RemoteException e) {
368 // TODO Auto-generated catch block
369 e.printStackTrace();
370 }
371 Toast.makeText(getActivity(), "Transfer complete", Toast.LENGTH_LONG).show();
372 break;
373
374 case 1:
375 String to = data.getStringExtra("to_number");
376 transfer = data.getParcelableExtra("transfer");
377 try {
alisiondf1dac92013-06-27 17:35:53 -0400378 Toast.makeText(getActivity(), "Transferring " + transfer.getParticipants().get(0).getContact().getmDisplayName() + " to " + to,
379 Toast.LENGTH_SHORT).show();
380 mCallbacks.getService().transfer(transfer.getParticipants().get(0).getCallId(), to);
381 mCallbacks.getService().hangUp(transfer.getParticipants().get(0).getCallId());
alision1005ba12013-06-19 13:52:44 -0400382 } catch (RemoteException e) {
383 // TODO Auto-generated catch block
384 e.printStackTrace();
385 }
386 break;
387
388 default:
389 break;
alisionb1763882013-06-18 17:30:51 -0400390 }
alision907bde72013-06-20 14:40:37 -0400391 } else if (requestCode == REQUEST_CONF) {
alision1005ba12013-06-19 13:52:44 -0400392 switch (resultCode) {
393 case 0:
alision465ceba2013-07-04 09:24:30 -0400394 Conference call_to_add = data.getParcelableExtra("transfer");
395 Conference call_target = data.getParcelableExtra("target");
alision1005ba12013-06-19 13:52:44 -0400396
alision465ceba2013-07-04 09:24:30 -0400397 bindCalls(call_to_add, call_target);
alision1005ba12013-06-19 13:52:44 -0400398 break;
399
400 default:
401 break;
402 }
alisionb1763882013-06-18 17:30:51 -0400403 }
404 }
405
alision465ceba2013-07-04 09:24:30 -0400406 private void bindCalls(Conference call_to_add, Conference call_target) {
407 try {
408
409 if (call_target.hasMultipleParticipants() && !call_to_add.hasMultipleParticipants()) {
410
411 mCallbacks.getService().addParticipant(call_to_add.getParticipants().get(0), call_target.getId());
412
413 } else if (call_target.hasMultipleParticipants() && call_to_add.hasMultipleParticipants()) {
414
415 // We join two conferences
416 mCallbacks.getService().joinConference(call_to_add.getId(), call_target.getId());
417
418 } else if (!call_target.hasMultipleParticipants() && call_to_add.hasMultipleParticipants()) {
419
420 mCallbacks.getService().addParticipant(call_target.getParticipants().get(0), call_to_add.getId());
421
422 } else {
423 // We join two single calls to create a conf
424 mCallbacks.getService().joinParticipant(call_to_add.getParticipants().get(0).getCallId(),
425 call_target.getParticipants().get(0).getCallId());
426 }
427
428 } catch (RemoteException e) {
429 // TODO Auto-generated catch block
430 e.printStackTrace();
431 }
432 }
433
434 public class CallListAdapter extends BaseAdapter {
alision806e18e2013-06-21 15:30:17 -0400435
436 private ArrayList<Conference> calls;
alisionb1763882013-06-18 17:30:51 -0400437
438 private Context mContext;
alisionb1763882013-06-18 17:30:51 -0400439
alision465ceba2013-07-04 09:24:30 -0400440 public CallListAdapter(Context act) {
441 super();
442 mContext = act;
alision806e18e2013-06-21 15:30:17 -0400443 calls = new ArrayList<Conference>();
alision1005ba12013-06-19 13:52:44 -0400444
445 }
446
alision806e18e2013-06-21 15:30:17 -0400447 public ArrayList<Conference> getConcurrentCalls(int position) {
448 ArrayList<Conference> toReturn = new ArrayList<Conference>();
alisionb1763882013-06-18 17:30:51 -0400449 for (int i = 0; i < calls.size(); ++i) {
alision1005ba12013-06-19 13:52:44 -0400450 if (position != i)
alisionb1763882013-06-18 17:30:51 -0400451 toReturn.add(calls.get(i));
452 }
453 return toReturn;
454 }
455
alision465ceba2013-07-04 09:24:30 -0400456 public void remove(Conference transfer) {
Alexandre Lision6d75d062013-09-13 14:18:34 -0400457 calls.remove(transfer);
alisionb1763882013-06-18 17:30:51 -0400458 }
459
alision806e18e2013-06-21 15:30:17 -0400460 public void update(ArrayList<Conference> list) {
alisionb1763882013-06-18 17:30:51 -0400461 calls.clear();
alision806e18e2013-06-21 15:30:17 -0400462 calls.addAll(list);
alisionb1763882013-06-18 17:30:51 -0400463 notifyDataSetChanged();
alisionb1763882013-06-18 17:30:51 -0400464 }
465
alision465ceba2013-07-04 09:24:30 -0400466 @Override
467 public int getCount() {
468 return calls.size();
469 }
470
471 @Override
472 public Conference getItem(int position) {
473 return calls.get(position);
474 }
475
476 @Override
477 public long getItemId(int position) {
478 return 0;
479 }
480
481 @Override
482 public View getView(int position, View convertView, ViewGroup parent) {
483 if (convertView == null)
484 convertView = LayoutInflater.from(mContext).inflate(R.layout.item_calllist, null);
485
486 Conference call = calls.get(position);
487 if (call.getParticipants().size() == 1) {
488 ((TextView) convertView.findViewById(R.id.call_title)).setText(call.getParticipants().get(0).getContact().getmDisplayName());
Alexandre Lision0c384512013-09-17 17:15:57 -0400489
490 long duration = System.currentTimeMillis() / 1000 - (call.getParticipants().get(0).getTimestamp_start());
491
492 ((TextView) convertView.findViewById(R.id.call_time)).setText(String.format("%d:%02d:%02d", duration/3600, (duration%3600)/60, (duration%60)));
alision465ceba2013-07-04 09:24:30 -0400493 } else {
Alexandre Lision2b237922013-09-09 16:23:02 -0400494 String tmp = "Conference with " + call.getParticipants().size() + " participants";
Alexandre Lision0c384512013-09-17 17:15:57 -0400495
alision465ceba2013-07-04 09:24:30 -0400496 ((TextView) convertView.findViewById(R.id.call_title)).setText(tmp);
497 }
Alexandre Lision0c384512013-09-17 17:15:57 -0400498
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}