blob: 259f7d104751c645bfb358e8cc9e6fb0cac773ee [file] [log] [blame]
alisionfde875f2013-05-28 17:01:54 -04001/*
Alexandre Lisionc1024c02014-01-06 11:12:53 -05002 * Copyright (C) 2004-2014 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 */
Alexandre Lision064e1e02013-10-01 16:18:42 -040031package org.sflphone.fragments;
alisionfde875f2013-05-28 17:01:54 -040032
33import java.util.ArrayList;
34import java.util.HashMap;
Alexandre Lisionf02190d2013-12-12 17:26:12 -050035import java.util.Observable;
36import java.util.Observer;
alisionfde875f2013-05-28 17:01:54 -040037
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -050038import android.content.IntentFilter;
Alexandre Lision064e1e02013-10-01 16:18:42 -040039import org.sflphone.R;
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -050040import org.sflphone.interfaces.CallInterface;
Alexandre Lisionf02190d2013-12-12 17:26:12 -050041import org.sflphone.model.CallTimer;
Alexandre Lision064e1e02013-10-01 16:18:42 -040042import org.sflphone.model.Conference;
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -050043import org.sflphone.receivers.CallReceiver;
44import org.sflphone.service.CallManagerCallBack;
Alexandre Lision064e1e02013-10-01 16:18:42 -040045import org.sflphone.service.ISipService;
Alexandre Lision064e1e02013-10-01 16:18:42 -040046
alisionfde875f2013-05-28 17:01:54 -040047import android.app.Activity;
alision465ceba2013-07-04 09:24:30 -040048import android.content.ClipData;
49import android.content.ClipData.Item;
alisionb1763882013-06-18 17:30:51 -040050import android.content.Context;
51import android.content.Intent;
alision465ceba2013-07-04 09:24:30 -040052import android.graphics.Color;
alisionfde875f2013-05-28 17:01:54 -040053import android.os.Bundle;
Alexandre Lisionf02190d2013-12-12 17:26:12 -050054import android.os.Handler;
alisionfde875f2013-05-28 17:01:54 -040055import android.os.RemoteException;
Alexandre Lisionf02190d2013-12-12 17:26:12 -050056import android.os.SystemClock;
alision465ceba2013-07-04 09:24:30 -040057import android.os.Vibrator;
Alexandre Lisionb4e60612014-01-14 17:47:23 -050058import android.app.Fragment;
alisionfde875f2013-05-28 17:01:54 -040059import android.util.Log;
alision465ceba2013-07-04 09:24:30 -040060import android.view.DragEvent;
alisionfde875f2013-05-28 17:01:54 -040061import android.view.LayoutInflater;
62import android.view.View;
alision465ceba2013-07-04 09:24:30 -040063import android.view.View.DragShadowBuilder;
64import android.view.View.OnDragListener;
alisionfde875f2013-05-28 17:01:54 -040065import android.view.ViewGroup;
alision465ceba2013-07-04 09:24:30 -040066import android.widget.AdapterView;
67import android.widget.AdapterView.OnItemClickListener;
68import android.widget.AdapterView.OnItemLongClickListener;
alision465ceba2013-07-04 09:24:30 -040069import android.widget.BaseAdapter;
alision465ceba2013-07-04 09:24:30 -040070import android.widget.ListView;
alisionb1763882013-06-18 17:30:51 -040071import android.widget.TextView;
alision1005ba12013-06-19 13:52:44 -040072import android.widget.Toast;
alisionfde875f2013-05-28 17:01:54 -040073
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -050074public class CallListFragment extends Fragment implements CallInterface{
Alexandre Lisionf02190d2013-12-12 17:26:12 -050075 private static final String TAG = CallListFragment.class.getSimpleName();
alisionfde875f2013-05-28 17:01:54 -040076
77 private Callbacks mCallbacks = sDummyCallbacks;
Alexandre Lisionf02190d2013-12-12 17:26:12 -050078 private TextView nb_calls, nb_confs;
79 CallListAdapter confs_adapter, calls_adapter;
80 CallTimer timer;
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -050081 CallReceiver callReceiver;
alisionfde875f2013-05-28 17:01:54 -040082
alision1005ba12013-06-19 13:52:44 -040083 public static final int REQUEST_TRANSFER = 10;
84 public static final int REQUEST_CONF = 20;
85
alisionfde875f2013-05-28 17:01:54 -040086 /**
87 * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity.
88 */
89 private static Callbacks sDummyCallbacks = new Callbacks() {
90
91 @Override
92 public ISipService getService() {
Alexandre Lisionf02190d2013-12-12 17:26:12 -050093 Log.i(TAG, "I'm a dummy");
alisionfde875f2013-05-28 17:01:54 -040094 return null;
95 }
alision85992112013-05-29 12:18:08 -040096
97 @Override
Alexandre Lisionf02190d2013-12-12 17:26:12 -050098 public void selectedCall(Conference c) {
alision85992112013-05-29 12:18:08 -040099 }
alisionfde875f2013-05-28 17:01:54 -0400100 };
101
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500102 @Override
103 public void incomingCall(Intent call) {
104
105 }
106
107 @Override
108 public void callStateChanged(Intent callState) {
109 Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate");
110 String cID = b.getString("CallID");
111 String state = b.getString("State");
112 Log.i(TAG, "callStateChanged" + cID + " " + state);
113 try {
114 updateLists();
115 } catch (RemoteException e) {
116 e.printStackTrace();
117 }
118 }
119
120 @Override
121 public void incomingText(Intent msg) {
122 Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext");
123 b.getString("CallID");
124 String from = b.getString("From");
125 String mess = b.getString("Msg");
126 Toast.makeText(getActivity(), "text from " + from + " : " + mess, Toast.LENGTH_LONG).show();
127 }
128
129 @Override
130 public void confCreated(Intent intent) {
131 try {
132 updateLists();
133 } catch (RemoteException e) {
134 e.printStackTrace();
135 }
136 }
137
138 @Override
139 public void confRemoved(Intent intent) {
140
141 }
142
143 @Override
144 public void confChanged(Intent intent) {
145
146 }
147
148 @Override
149 public void recordingChanged(Intent intent) {
150
151 }
152
alisionfde875f2013-05-28 17:01:54 -0400153 /**
154 * The Activity calling this fragment has to implement this interface
alisionfde875f2013-05-28 17:01:54 -0400155 */
156 public interface Callbacks {
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500157
alisionfde875f2013-05-28 17:01:54 -0400158 public ISipService getService();
alisionb1763882013-06-18 17:30:51 -0400159
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500160 public void selectedCall(Conference c);
alisionfde875f2013-05-28 17:01:54 -0400161
162 }
163
164 @Override
165 public void onAttach(Activity activity) {
166 super.onAttach(activity);
167
168 if (!(activity instanceof Callbacks)) {
169 throw new IllegalStateException("Activity must implement fragment's callbacks.");
170 }
171
172 mCallbacks = (Callbacks) activity;
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500173
174 }
175
176 private Runnable mUpdateTimeTask = new Runnable() {
177 public void run() {
178 final long start = SystemClock.uptimeMillis();
179 long millis = SystemClock.uptimeMillis() - start;
180 int seconds = (int) (millis / 1000);
181 int minutes = seconds / 60;
182 seconds = seconds % 60;
183
184 calls_adapter.notifyDataSetChanged();
185 confs_adapter.notifyDataSetChanged();
186 mHandler.postAtTime(this, start + (((minutes * 60) + seconds + 1) * 1000));
187 }
188 };
189
190 private Handler mHandler = new Handler();
191
192 @Override
193 public void onResume() {
194 super.onResume();
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500195 IntentFilter intentFilter = new IntentFilter();
196 intentFilter.addAction(CallManagerCallBack.INCOMING_CALL);
197 intentFilter.addAction(CallManagerCallBack.INCOMING_TEXT);
198 intentFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED);
199 getActivity().registerReceiver(callReceiver, intentFilter);
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500200 if (mCallbacks.getService() != null) {
201 try {
202 updateLists();
203 if (!calls_adapter.isEmpty() || !confs_adapter.isEmpty()) {
204 mHandler.postDelayed(mUpdateTimeTask, 0);
205 }
206
207 } catch (RemoteException e) {
208 Log.e(TAG, e.toString());
209 }
210 }
211
212 }
213
214 @SuppressWarnings("unchecked")
215 // No proper solution with HashMap runtime cast
216 public void updateLists() throws RemoteException {
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500217 HashMap<String, Conference> confs = (HashMap<String, Conference>) mCallbacks.getService().getConferenceList();
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500218 Log.i(TAG, "There are " + confs.size());
219 sortConferences(confs);
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500220 }
221
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500222 private void sortConferences(HashMap<String, Conference> conferences) {
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500223
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500224 ArrayList<Conference> multiConfs = new ArrayList<Conference>();
225 ArrayList<Conference> oneToOneConfs = new ArrayList<Conference>();
226 for (Conference conf : conferences.values()) {
227 if (conf.hasMultipleParticipants())
228 multiConfs.add(conf);
229 else
230 oneToOneConfs.add(conf);
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500231 }
232
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500233 nb_confs.setText("" + multiConfs.size());
234 nb_calls.setText("" + oneToOneConfs.size());
Alexandre Lision945e4612014-01-15 17:40:31 -0500235 confs_adapter.updateDataset(multiConfs);
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500236 calls_adapter.updateDataset(oneToOneConfs);
alisionfde875f2013-05-28 17:01:54 -0400237 }
238
239 @Override
240 public void onDetach() {
241 super.onDetach();
242 mCallbacks = sDummyCallbacks;
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500243
alisionfde875f2013-05-28 17:01:54 -0400244 }
245
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500246 @Override
247 public void onCreate(Bundle savedInstanceState) {
248 super.onCreate(savedInstanceState);
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500249 callReceiver = new CallReceiver(this);
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500250 }
251
252 @Override
253 public void onPause() {
254 super.onPause();
255 mHandler.removeCallbacks(mUpdateTimeTask);
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500256 getActivity().unregisterReceiver(callReceiver);
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500257 }
258
259 @Override
260 public void onActivityCreated(Bundle savedInstanceState) {
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500261 super.onActivityCreated(savedInstanceState);
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500262 }
alisionb1763882013-06-18 17:30:51 -0400263
alisionfde875f2013-05-28 17:01:54 -0400264 @Override
265 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500266 Log.i(TAG, "onCreateView");
267 View inflatedView = inflater.inflate(R.layout.frag_call_list, container, false);
alisionfde875f2013-05-28 17:01:54 -0400268
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500269 nb_calls = (TextView) inflatedView.findViewById(R.id.calls_counter);
270 nb_confs = (TextView) inflatedView.findViewById(R.id.confs_counter);
alisionb1763882013-06-18 17:30:51 -0400271
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500272 confs_adapter = new CallListAdapter(getActivity());
273 ((ListView) inflatedView.findViewById(R.id.confs_list)).setAdapter(confs_adapter);
alision465ceba2013-07-04 09:24:30 -0400274
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500275 calls_adapter = new CallListAdapter(getActivity());
276 ((ListView) inflatedView.findViewById(R.id.calls_list)).setAdapter(calls_adapter);
277 ((ListView) inflatedView.findViewById(R.id.calls_list)).setOnItemClickListener(callClickListener);
278 ((ListView) inflatedView.findViewById(R.id.confs_list)).setOnItemClickListener(callClickListener);
279
280 ((ListView) inflatedView.findViewById(R.id.calls_list)).setOnItemLongClickListener(mItemLongClickListener);
281 ((ListView) inflatedView.findViewById(R.id.confs_list)).setOnItemLongClickListener(mItemLongClickListener);
282
283 return inflatedView;
284 }
285
286 OnItemClickListener callClickListener = new OnItemClickListener() {
287
288 @Override
289 public void onItemClick(AdapterView<?> arg0, View v, int arg2, long arg3) {
290 mCallbacks.selectedCall((Conference) v.getTag());
291 }
292 };
293
294 private OnItemLongClickListener mItemLongClickListener = new OnItemLongClickListener() {
295
296 @Override
297 public boolean onItemLongClick(AdapterView<?> adptv, View view, int pos, long arg3) {
298 final Vibrator vibe = (Vibrator) view.getContext().getSystemService(Context.VIBRATOR_SERVICE);
299 vibe.vibrate(80);
300 Intent i = new Intent();
301 Bundle b = new Bundle();
302 b.putParcelable("conference", (Conference) adptv.getAdapter().getItem(pos));
303 i.putExtra("bconference", b);
304
305 DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
306 ClipData data = ClipData.newIntent("conference", i);
307 view.startDrag(data, shadowBuilder, view, 0);
308 return false;
309 }
310
311 };
312
313 public class CallListAdapter extends BaseAdapter implements Observer {
314
315 private ArrayList<Conference> calls;
316
317 private Context mContext;
318
319 public CallListAdapter(Context act) {
320 super();
321 mContext = act;
322 calls = new ArrayList<Conference>();
323
324 }
325
326 public ArrayList<Conference> getDataset() {
327 return calls;
328 }
329
330 public void remove(Conference transfer) {
331
332 }
333
334 public void updateDataset(ArrayList<Conference> list) {
335 calls.clear();
336 calls.addAll(list);
337 notifyDataSetChanged();
338 }
339
340 @Override
341 public int getCount() {
342 return calls.size();
343 }
344
345 @Override
346 public Conference getItem(int position) {
347 return calls.get(position);
348 }
349
350 @Override
351 public long getItemId(int position) {
352 return 0;
353 }
354
355 @Override
356 public View getView(int position, View convertView, ViewGroup parent) {
357 if (convertView == null)
358 convertView = LayoutInflater.from(mContext).inflate(R.layout.item_calllist, null);
359
360 Conference call = calls.get(position);
361 if (call.getParticipants().size() == 1) {
362 ((TextView) convertView.findViewById(R.id.call_title)).setText(call.getParticipants().get(0).getContact().getmDisplayName());
363
Alexandre Lision945e4612014-01-15 17:40:31 -0500364 long duration = System.currentTimeMillis() / 1000 - (call.getParticipants().get(0).getTimestampStart_());
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500365
366 ((TextView) convertView.findViewById(R.id.call_time)).setText(String.format("%d:%02d:%02d", duration / 3600, (duration % 3600) / 60,
367 (duration % 60)));
368 } else {
369// String tmp = "Conference with " + call.getParticipants().size() + " participants";
370 ((TextView) convertView.findViewById(R.id.call_title)).setText(getString(R.string.home_conf_item, call.getParticipants().size()));
371 }
372 // ((TextView) convertView.findViewById(R.id.num_participants)).setText("" + call.getParticipants().size());
373 ((TextView) convertView.findViewById(R.id.call_status)).setText(call.getState());
374
375 convertView.setOnDragListener(dragListener);
376 convertView.setTag(call);
377
378 return convertView;
379 }
380
381 @Override
382 public void update(Observable observable, Object data) {
383 Log.i(TAG, "Updating views...");
384 notifyDataSetChanged();
385 }
386
alisionfde875f2013-05-28 17:01:54 -0400387 }
388
alision465ceba2013-07-04 09:24:30 -0400389 OnDragListener dragListener = new OnDragListener() {
390
Alexandre Lisionf02190d2013-12-12 17:26:12 -0500391 @SuppressWarnings("deprecation")
392 // deprecated in API 16....
alision465ceba2013-07-04 09:24:30 -0400393 @Override
394 public boolean onDrag(View v, DragEvent event) {
395 switch (event.getAction()) {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500396 case DragEvent.ACTION_DRAG_STARTED:
397 // Do nothing
398 // Log.w(TAG, "ACTION_DRAG_STARTED");
399 break;
400 case DragEvent.ACTION_DRAG_ENTERED:
401 // Log.w(TAG, "ACTION_DRAG_ENTERED");
402 v.setBackgroundColor(Color.GREEN);
403 break;
404 case DragEvent.ACTION_DRAG_EXITED:
405 // Log.w(TAG, "ACTION_DRAG_EXITED");
406 v.setBackgroundDrawable(getResources().getDrawable(R.drawable.item_generic_selector));
407 break;
408 case DragEvent.ACTION_DROP:
409 // Log.w(TAG, "ACTION_DROP");
410 View view = (View) event.getLocalState();
alision465ceba2013-07-04 09:24:30 -0400411
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500412 Item i = event.getClipData().getItemAt(0);
413 Intent intent = i.getIntent();
414 intent.setExtrasClassLoader(Conference.class.getClassLoader());
alision465ceba2013-07-04 09:24:30 -0400415
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500416 Conference initial = (Conference) view.getTag();
417 Conference target = (Conference) v.getTag();
alisionf2ae4362013-07-05 16:16:12 -0400418
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500419 if (initial == target) {
420 return true;
421 }
alision465ceba2013-07-04 09:24:30 -0400422
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500423 DropActionsChoice dialog = DropActionsChoice.newInstance();
424 Bundle b = new Bundle();
425 b.putParcelable("call_initial", initial);
426 b.putParcelable("call_targeted", target);
427 dialog.setArguments(b);
428 dialog.setTargetFragment(CallListFragment.this, 0);
429 dialog.show(getChildFragmentManager(), "dialog");
alision465ceba2013-07-04 09:24:30 -0400430
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500431 // view.setBackgroundColor(Color.WHITE);
432 // v.setBackgroundColor(Color.BLACK);
433 break;
434 case DragEvent.ACTION_DRAG_ENDED:
435 // Log.w(TAG, "ACTION_DRAG_ENDED");
436 View view1 = (View) event.getLocalState();
437 view1.setVisibility(View.VISIBLE);
438 v.setBackgroundDrawable(getResources().getDrawable(R.drawable.item_generic_selector));
439 default:
440 break;
alision465ceba2013-07-04 09:24:30 -0400441 }
442 return true;
443 }
444
445 };
446
alisionb1763882013-06-18 17:30:51 -0400447 @Override
448 public void onActivityResult(int requestCode, int resultCode, Intent data) {
449 super.onActivityResult(requestCode, resultCode, data);
alisiondf1dac92013-06-27 17:35:53 -0400450 Conference transfer = null;
alision1005ba12013-06-19 13:52:44 -0400451 if (requestCode == REQUEST_TRANSFER) {
452 switch (resultCode) {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500453 case 0:
454 Conference c = data.getParcelableExtra("target");
455 transfer = data.getParcelableExtra("transfer");
456 try {
alisionb1763882013-06-18 17:30:51 -0400457
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500458 mCallbacks.getService().attendedTransfer(transfer.getParticipants().get(0).getCallId(), c.getParticipants().get(0).getCallId());
459 calls_adapter.remove(transfer);
460 calls_adapter.remove(c);
461 calls_adapter.notifyDataSetChanged();
462 } catch (RemoteException e) {
463 // TODO Auto-generated catch block
464 e.printStackTrace();
465 }
466 Toast.makeText(getActivity(), getString(R.string.home_transfer_complet), Toast.LENGTH_LONG).show();
467 break;
alision1005ba12013-06-19 13:52:44 -0400468
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500469 case 1:
470 String to = data.getStringExtra("to_number");
471 transfer = data.getParcelableExtra("transfer");
472 try {
473 Toast.makeText(getActivity(), getString(R.string.home_transfering, transfer.getParticipants().get(0).getContact().getmDisplayName(), to),
474 Toast.LENGTH_SHORT).show();
475 mCallbacks.getService().transfer(transfer.getParticipants().get(0).getCallId(), to);
476 mCallbacks.getService().hangUp(transfer.getParticipants().get(0).getCallId());
477 } catch (RemoteException e) {
478 // TODO Auto-generated catch block
479 e.printStackTrace();
480 }
481 break;
alision1005ba12013-06-19 13:52:44 -0400482
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500483 default:
484 break;
alisionb1763882013-06-18 17:30:51 -0400485 }
alision907bde72013-06-20 14:40:37 -0400486 } else if (requestCode == REQUEST_CONF) {
alision1005ba12013-06-19 13:52:44 -0400487 switch (resultCode) {
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500488 case 0:
489 Conference call_to_add = data.getParcelableExtra("transfer");
490 Conference call_target = data.getParcelableExtra("target");
alision1005ba12013-06-19 13:52:44 -0400491
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500492 bindCalls(call_to_add, call_target);
493 break;
alision1005ba12013-06-19 13:52:44 -0400494
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500495 default:
496 break;
alision1005ba12013-06-19 13:52:44 -0400497 }
alisionb1763882013-06-18 17:30:51 -0400498 }
499 }
500
alision465ceba2013-07-04 09:24:30 -0400501 private void bindCalls(Conference call_to_add, Conference call_target) {
502 try {
503
Alexandre Lisiona9ee4eb2014-01-15 16:20:35 -0500504 Log.i(TAG, "joining calls:"+ call_to_add.getId() + " and " + call_target.getId());
505
alision465ceba2013-07-04 09:24:30 -0400506 if (call_target.hasMultipleParticipants() && !call_to_add.hasMultipleParticipants()) {
507
508 mCallbacks.getService().addParticipant(call_to_add.getParticipants().get(0), call_target.getId());
509
510 } else if (call_target.hasMultipleParticipants() && call_to_add.hasMultipleParticipants()) {
511
512 // We join two conferences
513 mCallbacks.getService().joinConference(call_to_add.getId(), call_target.getId());
514
515 } else if (!call_target.hasMultipleParticipants() && call_to_add.hasMultipleParticipants()) {
516
517 mCallbacks.getService().addParticipant(call_target.getParticipants().get(0), call_to_add.getId());
518
519 } else {
520 // We join two single calls to create a conf
521 mCallbacks.getService().joinParticipant(call_to_add.getParticipants().get(0).getCallId(),
522 call_target.getParticipants().get(0).getCallId());
523 }
524
525 } catch (RemoteException e) {
526 // TODO Auto-generated catch block
527 e.printStackTrace();
528 }
529 }
530
alisionfde875f2013-05-28 17:01:54 -0400531}