blob: 1c3f2031a0116fd85f64cac35e6826c3c5808be9 [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;
alision465ceba2013-07-04 09:24:30 -040042import android.content.ClipData;
43import android.content.ClipData.Item;
alisionb1763882013-06-18 17:30:51 -040044import android.content.Context;
alision465ceba2013-07-04 09:24:30 -040045import android.content.DialogInterface;
alisionb1763882013-06-18 17:30:51 -040046import android.content.Intent;
alision465ceba2013-07-04 09:24:30 -040047import android.graphics.Color;
alisionfde875f2013-05-28 17:01:54 -040048import android.os.Bundle;
49import android.os.RemoteException;
alision465ceba2013-07-04 09:24:30 -040050import android.os.Vibrator;
alisionfde875f2013-05-28 17:01:54 -040051import android.util.Log;
alision465ceba2013-07-04 09:24:30 -040052import android.view.DragEvent;
alisionfde875f2013-05-28 17:01:54 -040053import android.view.LayoutInflater;
54import android.view.View;
alision465ceba2013-07-04 09:24:30 -040055import android.view.View.DragShadowBuilder;
56import android.view.View.OnDragListener;
alisionfde875f2013-05-28 17:01:54 -040057import android.view.ViewGroup;
alision465ceba2013-07-04 09:24:30 -040058import android.widget.AdapterView;
59import android.widget.AdapterView.OnItemClickListener;
60import android.widget.AdapterView.OnItemLongClickListener;
61import android.widget.ArrayAdapter;
62import android.widget.BaseAdapter;
63import android.widget.ListAdapter;
64import android.widget.ListView;
alisionb1763882013-06-18 17:30:51 -040065import android.widget.TextView;
alision1005ba12013-06-19 13:52:44 -040066import android.widget.Toast;
alisionfde875f2013-05-28 17:01:54 -040067
68import com.savoirfairelinux.sflphone.R;
alision806e18e2013-06-21 15:30:17 -040069import com.savoirfairelinux.sflphone.model.Conference;
alisionfde875f2013-05-28 17:01:54 -040070import com.savoirfairelinux.sflphone.model.SipCall;
71import com.savoirfairelinux.sflphone.service.ISipService;
alision465ceba2013-07-04 09:24:30 -040072import com.savoirfairelinux.sflphone.views.SwipeListViewTouchListener;
alisionfde875f2013-05-28 17:01:54 -040073
74public class CallListFragment extends Fragment {
alision806e18e2013-06-21 15:30:17 -040075 static final String TAG = CallListFragment.class.getSimpleName();
alisionfde875f2013-05-28 17:01:54 -040076
77 private Callbacks mCallbacks = sDummyCallbacks;
78
79 CallListAdapter mAdapter;
80
alision1005ba12013-06-19 13:52:44 -040081 public static final int REQUEST_TRANSFER = 10;
82 public static final int REQUEST_CONF = 20;
83
alisionfde875f2013-05-28 17:01:54 -040084 @Override
85 public void onCreate(Bundle savedBundle) {
86 super.onCreate(savedBundle);
87
alisionb1763882013-06-18 17:30:51 -040088 mAdapter = new CallListAdapter(getActivity());
alisionfde875f2013-05-28 17:01:54 -040089
90 }
91
92 /**
93 * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity.
94 */
95 private static Callbacks sDummyCallbacks = new Callbacks() {
96
97 @Override
98 public ISipService getService() {
alisionfde875f2013-05-28 17:01:54 -040099 return null;
100 }
alision85992112013-05-29 12:18:08 -0400101
102 @Override
alisiondf1dac92013-06-27 17:35:53 -0400103 public void onCallSelected(Conference conf) {
alision806e18e2013-06-21 15:30:17 -0400104 }
105
106 @Override
107 public void onCallsTerminated() {
alision85992112013-05-29 12:18:08 -0400108 }
alisionfde875f2013-05-28 17:01:54 -0400109 };
110
111 /**
112 * The Activity calling this fragment has to implement this interface
113 *
114 */
115 public interface Callbacks {
116 public ISipService getService();
alisionb1763882013-06-18 17:30:51 -0400117
alisiondf1dac92013-06-27 17:35:53 -0400118 public void onCallSelected(Conference conf);
alision806e18e2013-06-21 15:30:17 -0400119
120 public void onCallsTerminated();
alisionfde875f2013-05-28 17:01:54 -0400121
122 }
123
124 @Override
125 public void onAttach(Activity activity) {
126 super.onAttach(activity);
127
128 if (!(activity instanceof Callbacks)) {
129 throw new IllegalStateException("Activity must implement fragment's callbacks.");
130 }
131
132 mCallbacks = (Callbacks) activity;
133 }
134
135 @Override
136 public void onDetach() {
137 super.onDetach();
138 mCallbacks = sDummyCallbacks;
139 }
140
alision465ceba2013-07-04 09:24:30 -0400141 ListView list;
alisionb1763882013-06-18 17:30:51 -0400142
alisionfde875f2013-05-28 17:01:54 -0400143 @Override
144 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
145 ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.frag_call_list, container, false);
146
alision465ceba2013-07-04 09:24:30 -0400147 list = (ListView) rootView.findViewById(R.id.call_list);
alisionb1763882013-06-18 17:30:51 -0400148
alision465ceba2013-07-04 09:24:30 -0400149 list.setDivider(getResources().getDrawable(android.R.drawable.divider_horizontal_dark));
150 list.setDividerHeight(10);
151 list.setAdapter(mAdapter);
152 list.setOnItemClickListener(mItemClickListener);
153 list.setOnTouchListener(new SwipeListViewTouchListener(list, new SwipeListViewTouchListener.OnSwipeCallback() {
154 @Override
155 public void onSwipeLeft(ListView listView, int[] reverseSortedPositions) {
156 // Log.i(this.getClass().getName(), "swipe left : pos="+reverseSortedPositions[0]);
157 // TODO : YOUR CODE HERE FOR LEFT ACTION
alisionf2ae4362013-07-05 16:16:12 -0400158 Conference tmp = mAdapter.getItem(reverseSortedPositions[0]);
159 try {
160 if (tmp.hasMultipleParticipants()) {
161 mCallbacks.getService().hangUpConference(tmp.getId());
162 } else {
163 mCallbacks.getService().hangUp(tmp.getParticipants().get(0).getCallId());
164 }
165 } catch (RemoteException e) {
166 // TODO Auto-generated catch block
167 e.printStackTrace();
168 }
169
alision465ceba2013-07-04 09:24:30 -0400170 }
171
172 @Override
173 public void onSwipeRight(ListView listView, int[] reverseSortedPositions) {
174 // Log.i(ProfileMenuActivity.class.getClass().getName(), "swipe right : pos="+reverseSortedPositions[0]);
175 // TODO : YOUR CODE HERE FOR RIGHT ACTION
alisionf2ae4362013-07-05 16:16:12 -0400176
177 Conference tmp = mAdapter.getItem(reverseSortedPositions[0]);
178 try {
179 if (tmp.hasMultipleParticipants()) {
180 if (tmp.isOnHold()) {
181 mCallbacks.getService().unholdConference(tmp.getId());
182 } else {
183 mCallbacks.getService().holdConference(tmp.getId());
184 }
185 } else {
186 if (tmp.isOnHold()) {
187 Toast.makeText(getActivity(), "call is on hold, unholding", Toast.LENGTH_SHORT).show();
188 mCallbacks.getService().unhold(tmp.getParticipants().get(0).getCallId());
189 } else {
190 Toast.makeText(getActivity(), "call is current, holding", Toast.LENGTH_SHORT).show();
191 mCallbacks.getService().hold(tmp.getParticipants().get(0).getCallId());
192 }
193 }
194 } catch (RemoteException e) {
195 // TODO Auto-generated catch block
196 e.printStackTrace();
197 }
alision465ceba2013-07-04 09:24:30 -0400198 }
199 }, true, // example : left action = dismiss
200 false)); // example : right action without dismiss animation);
201 list.setOnItemLongClickListener(mItemLongClickListener);
202
alisionfde875f2013-05-28 17:01:54 -0400203 return rootView;
204 }
205
alision465ceba2013-07-04 09:24:30 -0400206 OnDragListener dragListener = new OnDragListener() {
207
Alexandre Lision6e8931e2013-09-19 16:49:34 -0400208 @SuppressWarnings("deprecation") // deprecated in API 16....
alision465ceba2013-07-04 09:24:30 -0400209 @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
Alexandre Lision6e8931e2013-09-19 16:49:34 -0400295 @SuppressWarnings("unchecked") // No proper solution with HashMap runtime cast
alisionfde875f2013-05-28 17:01:54 -0400296 public void update() {
297 try {
298 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) {
alision806e18e2013-06-21 15:30:17 -0400307 Conference confOne = new Conference("-1");
308 confOne.getParticipants().add(call);
309 conferences.add(confOne);
310 }
alisiondf1dac92013-06-27 17:35:53 -0400311
312 if (conferences.isEmpty()) {
alision806e18e2013-06-21 15:30:17 -0400313 mCallbacks.onCallsTerminated();
314 }
315
316 mAdapter.update(conferences);
alisionfde875f2013-05-28 17:01:54 -0400317 } catch (RemoteException e) {
318 Log.e(TAG, e.toString());
319 }
320
321 }
alisionb1763882013-06-18 17:30:51 -0400322
Alexandre Lision80a99162013-09-13 14:19:23 -0400323 // private void makeTransferDialog(int groupPosition) {
324 // FragmentManager fm = getFragmentManager();
325 // TransferDFragment editNameDialog = new TransferDFragment();
326 //
327 // if (!mAdapter.getItem(groupPosition).hasMultipleParticipants()) {
328 // Bundle b = new Bundle();
329 // b.putParcelableArrayList("calls", mAdapter.getConcurrentCalls(groupPosition));
330 // b.putParcelable("call_selected", mAdapter.getItem(groupPosition));
331 // editNameDialog.setArguments(b);
332 // editNameDialog.setTargetFragment(this, REQUEST_TRANSFER);
333 // editNameDialog.show(fm, "dialog");
334 // } else {
335 // Toast.makeText(getActivity(), "Transfer a Conference ?", Toast.LENGTH_SHORT).show();
336 // }
337 //
338 // }
339 //
340 // private void makeConferenceDialog(int groupPosition) {
341 // FragmentManager fm = getFragmentManager();
342 // ConferenceDFragment confDialog = ConferenceDFragment.newInstance();
343 //
344 // Bundle b = new Bundle();
345 // b.putParcelableArrayList("calls", mAdapter.getConcurrentCalls(groupPosition));
346 // b.putParcelable("call_selected", mAdapter.getItem(groupPosition));
347 // confDialog.setArguments(b);
348 // confDialog.setTargetFragment(this, REQUEST_CONF);
349 // confDialog.show(fm, "dialog");
350 //
351 // }
alision1005ba12013-06-19 13:52:44 -0400352
alisionb1763882013-06-18 17:30:51 -0400353 @Override
354 public void onActivityResult(int requestCode, int resultCode, Intent data) {
355 super.onActivityResult(requestCode, resultCode, data);
alisiondf1dac92013-06-27 17:35:53 -0400356 Conference transfer = null;
alision1005ba12013-06-19 13:52:44 -0400357 if (requestCode == REQUEST_TRANSFER) {
358 switch (resultCode) {
359 case 0:
alisiondf1dac92013-06-27 17:35:53 -0400360 Conference c = data.getParcelableExtra("target");
alision1005ba12013-06-19 13:52:44 -0400361 transfer = data.getParcelableExtra("transfer");
362 try {
alisionb1763882013-06-18 17:30:51 -0400363
alisiondf1dac92013-06-27 17:35:53 -0400364 mCallbacks.getService().attendedTransfer(transfer.getParticipants().get(0).getCallId(), c.getParticipants().get(0).getCallId());
alision1005ba12013-06-19 13:52:44 -0400365 mAdapter.remove(transfer);
alision465ceba2013-07-04 09:24:30 -0400366 mAdapter.remove(c);
alision1005ba12013-06-19 13:52:44 -0400367 mAdapter.notifyDataSetChanged();
368 } catch (RemoteException e) {
369 // TODO Auto-generated catch block
370 e.printStackTrace();
371 }
372 Toast.makeText(getActivity(), "Transfer complete", Toast.LENGTH_LONG).show();
373 break;
374
375 case 1:
376 String to = data.getStringExtra("to_number");
377 transfer = data.getParcelableExtra("transfer");
378 try {
alisiondf1dac92013-06-27 17:35:53 -0400379 Toast.makeText(getActivity(), "Transferring " + transfer.getParticipants().get(0).getContact().getmDisplayName() + " to " + to,
380 Toast.LENGTH_SHORT).show();
381 mCallbacks.getService().transfer(transfer.getParticipants().get(0).getCallId(), to);
382 mCallbacks.getService().hangUp(transfer.getParticipants().get(0).getCallId());
alision1005ba12013-06-19 13:52:44 -0400383 } catch (RemoteException e) {
384 // TODO Auto-generated catch block
385 e.printStackTrace();
386 }
387 break;
388
389 default:
390 break;
alisionb1763882013-06-18 17:30:51 -0400391 }
alision907bde72013-06-20 14:40:37 -0400392 } else if (requestCode == REQUEST_CONF) {
alision1005ba12013-06-19 13:52:44 -0400393 switch (resultCode) {
394 case 0:
alision465ceba2013-07-04 09:24:30 -0400395 Conference call_to_add = data.getParcelableExtra("transfer");
396 Conference call_target = data.getParcelableExtra("target");
alision1005ba12013-06-19 13:52:44 -0400397
alision465ceba2013-07-04 09:24:30 -0400398 bindCalls(call_to_add, call_target);
alision1005ba12013-06-19 13:52:44 -0400399 break;
400
401 default:
402 break;
403 }
alisionb1763882013-06-18 17:30:51 -0400404 }
405 }
406
alision465ceba2013-07-04 09:24:30 -0400407 private void bindCalls(Conference call_to_add, Conference call_target) {
408 try {
409
410 if (call_target.hasMultipleParticipants() && !call_to_add.hasMultipleParticipants()) {
411
412 mCallbacks.getService().addParticipant(call_to_add.getParticipants().get(0), call_target.getId());
413
414 } else if (call_target.hasMultipleParticipants() && call_to_add.hasMultipleParticipants()) {
415
416 // We join two conferences
417 mCallbacks.getService().joinConference(call_to_add.getId(), call_target.getId());
418
419 } else if (!call_target.hasMultipleParticipants() && call_to_add.hasMultipleParticipants()) {
420
421 mCallbacks.getService().addParticipant(call_target.getParticipants().get(0), call_to_add.getId());
422
423 } else {
424 // We join two single calls to create a conf
425 mCallbacks.getService().joinParticipant(call_to_add.getParticipants().get(0).getCallId(),
426 call_target.getParticipants().get(0).getCallId());
427 }
428
429 } catch (RemoteException e) {
430 // TODO Auto-generated catch block
431 e.printStackTrace();
432 }
433 }
434
435 public class CallListAdapter extends BaseAdapter {
alision806e18e2013-06-21 15:30:17 -0400436
437 private ArrayList<Conference> calls;
alisionb1763882013-06-18 17:30:51 -0400438
439 private Context mContext;
alisionb1763882013-06-18 17:30:51 -0400440
alision465ceba2013-07-04 09:24:30 -0400441 public CallListAdapter(Context act) {
442 super();
443 mContext = act;
alision806e18e2013-06-21 15:30:17 -0400444 calls = new ArrayList<Conference>();
alision1005ba12013-06-19 13:52:44 -0400445
446 }
447
alision806e18e2013-06-21 15:30:17 -0400448 public ArrayList<Conference> getConcurrentCalls(int position) {
449 ArrayList<Conference> toReturn = new ArrayList<Conference>();
alisionb1763882013-06-18 17:30:51 -0400450 for (int i = 0; i < calls.size(); ++i) {
alision1005ba12013-06-19 13:52:44 -0400451 if (position != i)
alisionb1763882013-06-18 17:30:51 -0400452 toReturn.add(calls.get(i));
453 }
454 return toReturn;
455 }
456
alision465ceba2013-07-04 09:24:30 -0400457 public void remove(Conference transfer) {
Alexandre Lision6d75d062013-09-13 14:18:34 -0400458 calls.remove(transfer);
alisionb1763882013-06-18 17:30:51 -0400459 }
460
alision806e18e2013-06-21 15:30:17 -0400461 public void update(ArrayList<Conference> list) {
alisionb1763882013-06-18 17:30:51 -0400462 calls.clear();
alision806e18e2013-06-21 15:30:17 -0400463 calls.addAll(list);
alisionb1763882013-06-18 17:30:51 -0400464 notifyDataSetChanged();
alisionb1763882013-06-18 17:30:51 -0400465 }
466
alision465ceba2013-07-04 09:24:30 -0400467 @Override
468 public int getCount() {
469 return calls.size();
470 }
471
472 @Override
473 public Conference getItem(int position) {
474 return calls.get(position);
475 }
476
477 @Override
478 public long getItemId(int position) {
479 return 0;
480 }
481
482 @Override
483 public View getView(int position, View convertView, ViewGroup parent) {
484 if (convertView == null)
485 convertView = LayoutInflater.from(mContext).inflate(R.layout.item_calllist, null);
486
487 Conference call = calls.get(position);
488 if (call.getParticipants().size() == 1) {
489 ((TextView) convertView.findViewById(R.id.call_title)).setText(call.getParticipants().get(0).getContact().getmDisplayName());
Alexandre Lision0c384512013-09-17 17:15:57 -0400490
491 long duration = System.currentTimeMillis() / 1000 - (call.getParticipants().get(0).getTimestamp_start());
492
493 ((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 -0400494 } else {
Alexandre Lision2b237922013-09-09 16:23:02 -0400495 String tmp = "Conference with " + call.getParticipants().size() + " participants";
Alexandre Lision0c384512013-09-17 17:15:57 -0400496
alision465ceba2013-07-04 09:24:30 -0400497 ((TextView) convertView.findViewById(R.id.call_title)).setText(tmp);
498 }
Alexandre Lision0c384512013-09-17 17:15:57 -0400499
alision465ceba2013-07-04 09:24:30 -0400500 ((TextView) convertView.findViewById(R.id.call_status)).setText(call.getState());
501 convertView.setOnDragListener(dragListener);
502
503 convertView.setTag(call);
504 return convertView;
505 }
506
507 }
508
509 public static class DropActionsChoice extends DialogFragment {
510
511 ListAdapter mAdapter;
512 private Bundle args;
513
514 /**
515 * Create a new instance of CallActionsDFragment
516 */
517 public static DropActionsChoice newInstance() {
518 DropActionsChoice f = new DropActionsChoice();
519 return f;
520 }
521
522 @Override
523 public void onCreate(Bundle savedInstanceState) {
524 super.onCreate(savedInstanceState);
525
526 // Pick a style based on the num.
527 int style = DialogFragment.STYLE_NORMAL, theme = 0;
528 setStyle(style, theme);
529 }
530
531 @Override
532 public Dialog onCreateDialog(Bundle savedInstanceState) {
533 ListView rootView = new ListView(getActivity());
534
535 args = getArguments();
536 mAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, getResources().getStringArray(
537 R.array.drop_actions));
538
539 // ListView list = (ListView) rootView.findViewById(R.id.concurrent_calls);
540 rootView.setAdapter(mAdapter);
541 rootView.setOnItemClickListener(new OnItemClickListener() {
542
543 @Override
544 public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
545 Intent in = new Intent();
546
547 in.putExtra("transfer", args.getParcelable("call_initial"));
548 in.putExtra("target", args.getParcelable("call_targeted"));
549
550 switch (pos) {
551 case 0: // Transfer
552 getTargetFragment().onActivityResult(REQUEST_TRANSFER, 0, in);
553 break;
554 case 1: // Conference
555 getTargetFragment().onActivityResult(REQUEST_CONF, 0, in);
556 break;
557 }
558 dismiss();
559
560 }
561 });
562
563 final AlertDialog a = new AlertDialog.Builder(getActivity()).setView(rootView).setTitle("Choose Action")
564 .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
565 public void onClick(DialogInterface dialog, int whichButton) {
566 dismiss();
567 }
568 }).create();
569
570 return a;
571 }
alisionb1763882013-06-18 17:30:51 -0400572 }
alisionfde875f2013-05-28 17:01:54 -0400573
574}