blob: 1072562bb96c8cbbfa056bb88ca39d16d3d83105 [file] [log] [blame]
alisionf76de3b2013-04-16 15:35:22 -04001/*
alision2ec64f92013-06-17 17:28:58 -04002 * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
alisionf76de3b2013-04-16 15:35:22 -04003 *
alision2ec64f92013-06-17 17:28:58 -04004 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
alisionf76de3b2013-04-16 15:35:22 -04005 *
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 */
31package com.savoirfairelinux.sflphone.fragments;
32
Alexandre Lision6d75d062013-09-13 14:18:34 -040033import java.util.ArrayList;
alision2cb99562013-05-30 17:02:20 -040034import java.util.HashMap;
Alexandre Lision3c6b7102013-09-16 16:56:46 -040035import java.util.Observable;
36import java.util.Observer;
alisionf76de3b2013-04-16 15:35:22 -040037
38import android.app.Activity;
alisionb1763882013-06-18 17:30:51 -040039import android.app.Fragment;
Alexandre Lisionf1850c02013-09-23 14:19:34 -040040import android.content.ClipData;
Alexandre Lision6d75d062013-09-13 14:18:34 -040041import android.content.Context;
Alexandre Lisionf1850c02013-09-23 14:19:34 -040042import android.content.Intent;
43import android.content.ClipData.Item;
44import android.graphics.Color;
alisionf76de3b2013-04-16 15:35:22 -040045import android.os.Bundle;
Alexandre Lisionebeb3662013-09-17 16:20:54 -040046import android.os.Handler;
alision2cb99562013-05-30 17:02:20 -040047import android.os.RemoteException;
Alexandre Lisionebeb3662013-09-17 16:20:54 -040048import android.os.SystemClock;
Alexandre Lisionf1850c02013-09-23 14:19:34 -040049import android.os.Vibrator;
alisionf76de3b2013-04-16 15:35:22 -040050import android.util.Log;
Alexandre Lisionf1850c02013-09-23 14:19:34 -040051import android.view.DragEvent;
alisionf76de3b2013-04-16 15:35:22 -040052import android.view.LayoutInflater;
alisiond8c83882013-05-17 17:00:42 -040053import android.view.Menu;
54import android.view.MenuInflater;
alisionf76de3b2013-04-16 15:35:22 -040055import android.view.View;
alision43a9b362013-05-01 16:30:15 -040056import android.view.ViewGroup;
Alexandre Lisionf1850c02013-09-23 14:19:34 -040057import android.view.View.DragShadowBuilder;
58import android.view.View.OnDragListener;
Alexandre Lision1a9e3b12013-09-16 11:06:07 -040059import android.widget.AdapterView;
60import android.widget.AdapterView.OnItemClickListener;
Alexandre Lisionf1850c02013-09-23 14:19:34 -040061import android.widget.AdapterView.OnItemLongClickListener;
Alexandre Lision6d75d062013-09-13 14:18:34 -040062import android.widget.BaseAdapter;
Alexandre Lision573045c2013-09-11 17:20:25 -040063import android.widget.ListView;
Alexandre Lisionc51ccb12013-09-11 16:00:30 -040064import android.widget.TextView;
Alexandre Lisionf1850c02013-09-23 14:19:34 -040065import android.widget.Toast;
alisionf76de3b2013-04-16 15:35:22 -040066
67import com.savoirfairelinux.sflphone.R;
Alexandre Lisionf1850c02013-09-23 14:19:34 -040068import com.savoirfairelinux.sflphone.fragments.CallListFragment.DropActionsChoice;
Alexandre Lision3c6b7102013-09-16 16:56:46 -040069import com.savoirfairelinux.sflphone.model.CallTimer;
alisiondf1dac92013-06-27 17:35:53 -040070import com.savoirfairelinux.sflphone.model.Conference;
alisionf76de3b2013-04-16 15:35:22 -040071import com.savoirfairelinux.sflphone.model.SipCall;
72import com.savoirfairelinux.sflphone.service.ISipService;
73
alisionb1763882013-06-18 17:30:51 -040074public class HomeFragment extends Fragment {
alision55c36cb2013-06-14 14:57:38 -040075 private static final String TAG = HomeFragment.class.getSimpleName();
alision907bde72013-06-20 14:40:37 -040076
alision9f7a6ec2013-05-24 16:26:26 -040077 private Callbacks mCallbacks = sDummyCallbacks;
Alexandre Lisionf1850c02013-09-23 14:19:34 -040078 private TextView nb_calls, nb_confs;
79 CallListAdapter confs_adapter, calls_adapter;
Alexandre Lisionebeb3662013-09-17 16:20:54 -040080 CallTimer timer;
Alexandre Lisionf1850c02013-09-23 14:19:34 -040081
82 public static final int REQUEST_TRANSFER = 10;
83 public static final int REQUEST_CONF = 20;
alision43a9b362013-05-01 16:30:15 -040084
alision9f7a6ec2013-05-24 16:26:26 -040085 /**
86 * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity.
87 */
88 private static Callbacks sDummyCallbacks = new Callbacks() {
alision371b77e2013-04-23 14:51:26 -040089
alision9f7a6ec2013-05-24 16:26:26 -040090 @Override
91 public ISipService getService() {
alision2cb99562013-05-30 17:02:20 -040092 Log.i(TAG, "I'm a dummy");
alision9f7a6ec2013-05-24 16:26:26 -040093 return null;
94 }
alisiondf1dac92013-06-27 17:35:53 -040095
96 @Override
Alexandre Lision1a9e3b12013-09-16 11:06:07 -040097 public void selectedCall(Conference c) {
alisiondf1dac92013-06-27 17:35:53 -040098 }
alision9f7a6ec2013-05-24 16:26:26 -040099 };
alision371b77e2013-04-23 14:51:26 -0400100
alision9f7a6ec2013-05-24 16:26:26 -0400101 /**
102 * The Activity calling this fragment has to implement this interface
103 *
104 */
105 public interface Callbacks {
alision371b77e2013-04-23 14:51:26 -0400106
alision9f7a6ec2013-05-24 16:26:26 -0400107 public ISipService getService();
alision43a9b362013-05-01 16:30:15 -0400108
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400109 public void selectedCall(Conference c);
alisiondf1dac92013-06-27 17:35:53 -0400110
alision9f7a6ec2013-05-24 16:26:26 -0400111 }
alisionf76de3b2013-04-16 15:35:22 -0400112
alision9f7a6ec2013-05-24 16:26:26 -0400113 @Override
114 public void onAttach(Activity activity) {
115 super.onAttach(activity);
alisionf76de3b2013-04-16 15:35:22 -0400116
alision9f7a6ec2013-05-24 16:26:26 -0400117 if (!(activity instanceof Callbacks)) {
118 throw new IllegalStateException("Activity must implement fragment's callbacks.");
119 }
alisionf76de3b2013-04-16 15:35:22 -0400120
alision9f7a6ec2013-05-24 16:26:26 -0400121 mCallbacks = (Callbacks) activity;
alisiondf1dac92013-06-27 17:35:53 -0400122
alision2cb99562013-05-30 17:02:20 -0400123 }
alisiondf1dac92013-06-27 17:35:53 -0400124
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400125 private Runnable mUpdateTimeTask = new Runnable() {
126 public void run() {
127 final long start = SystemClock.uptimeMillis();
128 long millis = SystemClock.uptimeMillis() - start;
129 int seconds = (int) (millis / 1000);
130 int minutes = seconds / 60;
131 seconds = seconds % 60;
132
133 calls_adapter.notifyDataSetChanged();
Alexandre Lision0c384512013-09-17 17:15:57 -0400134 confs_adapter.notifyDataSetChanged();
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400135 mHandler.postAtTime(this, start + (((minutes * 60) + seconds + 1) * 1000));
136 }
137 };
138
139 private Handler mHandler = new Handler();
140
alision2cb99562013-05-30 17:02:20 -0400141 @Override
alisiondf1dac92013-06-27 17:35:53 -0400142 public void onResume() {
alision2cb99562013-05-30 17:02:20 -0400143 super.onResume();
alision2cb99562013-05-30 17:02:20 -0400144 if (mCallbacks.getService() != null) {
145 try {
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400146 updateLists();
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400147 if (!calls_adapter.isEmpty() || !confs_adapter.isEmpty()) {
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400148 mHandler.postDelayed(mUpdateTimeTask, 0);
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400149 }
alision2cb99562013-05-30 17:02:20 -0400150
alision2cb99562013-05-30 17:02:20 -0400151 } catch (RemoteException e) {
152 Log.e(TAG, e.toString());
153 }
154 }
alisiondf1dac92013-06-27 17:35:53 -0400155
alision9f7a6ec2013-05-24 16:26:26 -0400156 }
alisionf76de3b2013-04-16 15:35:22 -0400157
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400158 @SuppressWarnings("unchecked")
159 // No proper solution with HashMap runtime cast
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400160 public void updateLists() throws RemoteException {
161 HashMap<String, SipCall> calls = (HashMap<String, SipCall>) mCallbacks.getService().getCallList();
162 HashMap<String, Conference> confs = (HashMap<String, Conference>) mCallbacks.getService().getConferenceList();
163
164 updateCallList(calls);
165 updateConferenceList(confs);
166 }
167
Alexandre Lision573045c2013-09-11 17:20:25 -0400168 private void updateConferenceList(HashMap<String, Conference> confs) {
Alexandre Lision6d75d062013-09-13 14:18:34 -0400169 nb_confs.setText("" + confs.size());
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400170 confs_adapter.updateDataset(new ArrayList<Conference>(confs.values()));
Alexandre Lision573045c2013-09-11 17:20:25 -0400171 }
172
173 private void updateCallList(HashMap<String, SipCall> calls) {
Alexandre Lision6d75d062013-09-13 14:18:34 -0400174 nb_calls.setText("" + calls.size());
175 ArrayList<Conference> conferences = new ArrayList<Conference>();
176 for (SipCall call : calls.values()) {
177 Log.w(TAG, "SimpleCall:" + call.getCallId());
178 Conference confOne = new Conference("-1");
179 confOne.getParticipants().add(call);
180 conferences.add(confOne);
181 }
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400182
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400183 calls_adapter.updateDataset(conferences);
Alexandre Lision6d75d062013-09-13 14:18:34 -0400184
Alexandre Lision573045c2013-09-11 17:20:25 -0400185 }
186
alision9f7a6ec2013-05-24 16:26:26 -0400187 @Override
188 public void onDetach() {
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400189
alision9f7a6ec2013-05-24 16:26:26 -0400190 super.onDetach();
191 mCallbacks = sDummyCallbacks;
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400192
alision9f7a6ec2013-05-24 16:26:26 -0400193 }
alisionf76de3b2013-04-16 15:35:22 -0400194
alision9f7a6ec2013-05-24 16:26:26 -0400195 @Override
196 public void onCreate(Bundle savedInstanceState) {
197 super.onCreate(savedInstanceState);
Alexandre Lision0c384512013-09-17 17:15:57 -0400198 }
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400199
Alexandre Lision0c384512013-09-17 17:15:57 -0400200 @Override
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400201 public void onPause() {
Alexandre Lision0c384512013-09-17 17:15:57 -0400202 super.onPause();
203 mHandler.removeCallbacks(mUpdateTimeTask);
alision9f7a6ec2013-05-24 16:26:26 -0400204 }
alisionf76de3b2013-04-16 15:35:22 -0400205
alision9f7a6ec2013-05-24 16:26:26 -0400206 @Override
207 public void onActivityCreated(Bundle savedInstanceState) {
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400208
alision9f7a6ec2013-05-24 16:26:26 -0400209 super.onActivityCreated(savedInstanceState);
alisionf76de3b2013-04-16 15:35:22 -0400210
alision9f7a6ec2013-05-24 16:26:26 -0400211 // Give some text to display if there is no data. In a real
212 // application this would come from a resource.
213 // setEmptyText("No phone numbers");
alisionf76de3b2013-04-16 15:35:22 -0400214
alision9f7a6ec2013-05-24 16:26:26 -0400215 // We have a menu item to show in action bar.
216 setHasOptionsMenu(true);
alisionf76de3b2013-04-16 15:35:22 -0400217
alision9f7a6ec2013-05-24 16:26:26 -0400218 }
alision371b77e2013-04-23 14:51:26 -0400219
alision9f7a6ec2013-05-24 16:26:26 -0400220 @Override
221 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400222
alision9f7a6ec2013-05-24 16:26:26 -0400223 inflater.inflate(R.menu.call_element_menu, menu);
alisionf76de3b2013-04-16 15:35:22 -0400224
alision9f7a6ec2013-05-24 16:26:26 -0400225 }
alisionf76de3b2013-04-16 15:35:22 -0400226
alision9f7a6ec2013-05-24 16:26:26 -0400227 @Override
228 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
229 Log.i(TAG, "onCreateView");
alision465ceba2013-07-04 09:24:30 -0400230 View inflatedView = inflater.inflate(R.layout.frag_home, container, false);
alision43a9b362013-05-01 16:30:15 -0400231
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400232 nb_calls = (TextView) inflatedView.findViewById(R.id.calls_counter);
233 nb_confs = (TextView) inflatedView.findViewById(R.id.confs_counter);
Alexandre Lision6d75d062013-09-13 14:18:34 -0400234
235 confs_adapter = new CallListAdapter(getActivity());
236 ((ListView) inflatedView.findViewById(R.id.confs_list)).setAdapter(confs_adapter);
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400237
Alexandre Lision6d75d062013-09-13 14:18:34 -0400238 calls_adapter = new CallListAdapter(getActivity());
239 ((ListView) inflatedView.findViewById(R.id.calls_list)).setAdapter(calls_adapter);
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400240 ((ListView) inflatedView.findViewById(R.id.calls_list)).setOnItemClickListener(callClickListener);
241 ((ListView) inflatedView.findViewById(R.id.confs_list)).setOnItemClickListener(callClickListener);
alision43a9b362013-05-01 16:30:15 -0400242
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400243 ((ListView) inflatedView.findViewById(R.id.calls_list)).setOnItemLongClickListener(mItemLongClickListener);
244 ((ListView) inflatedView.findViewById(R.id.confs_list)).setOnItemLongClickListener(mItemLongClickListener);
245
alision9f7a6ec2013-05-24 16:26:26 -0400246 return inflatedView;
247 }
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400248
249 OnItemClickListener callClickListener = new OnItemClickListener() {
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400250
251 @Override
252 public void onItemClick(AdapterView<?> arg0, View v, int arg2, long arg3) {
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400253 mCallbacks.selectedCall((Conference) v.getTag());
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400254 }
255 };
alisione2a38e12013-04-25 14:20:20 -0400256
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400257 private OnItemLongClickListener mItemLongClickListener = new OnItemLongClickListener() {
258
259 @Override
260 public boolean onItemLongClick(AdapterView<?> adptv, View view, int pos, long arg3) {
261 final Vibrator vibe = (Vibrator) view.getContext().getSystemService(Context.VIBRATOR_SERVICE);
262 vibe.vibrate(80);
263 Intent i = new Intent();
264 Bundle b = new Bundle();
265 b.putParcelable("conference", (Conference) adptv.getAdapter().getItem(pos));
266 i.putExtra("bconference", b);
267
268 DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
269 ClipData data = ClipData.newIntent("conference", i);
270 view.startDrag(data, shadowBuilder, view, 0);
271 return false;
272 }
273
274 };
275
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400276 public class CallListAdapter extends BaseAdapter implements Observer {
Alexandre Lision6d75d062013-09-13 14:18:34 -0400277
278 private ArrayList<Conference> calls;
279
280 private Context mContext;
281
282 public CallListAdapter(Context act) {
283 super();
284 mContext = act;
285 calls = new ArrayList<Conference>();
286
287 }
288
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400289 public ArrayList<Conference> getDataset() {
290 return calls;
291 }
292
Alexandre Lision6d75d062013-09-13 14:18:34 -0400293 public void remove(Conference transfer) {
294
295 }
296
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400297 public void updateDataset(ArrayList<Conference> list) {
Alexandre Lision6d75d062013-09-13 14:18:34 -0400298 calls.clear();
299 calls.addAll(list);
300 notifyDataSetChanged();
301 }
302
303 @Override
304 public int getCount() {
305 return calls.size();
306 }
307
308 @Override
309 public Conference getItem(int position) {
310 return calls.get(position);
311 }
312
313 @Override
314 public long getItemId(int position) {
315 return 0;
316 }
317
318 @Override
319 public View getView(int position, View convertView, ViewGroup parent) {
320 if (convertView == null)
321 convertView = LayoutInflater.from(mContext).inflate(R.layout.item_calllist, null);
322
323 Conference call = calls.get(position);
324 if (call.getParticipants().size() == 1) {
325 ((TextView) convertView.findViewById(R.id.call_title)).setText(call.getParticipants().get(0).getContact().getmDisplayName());
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400326
327 long duration = System.currentTimeMillis() / 1000 - (call.getParticipants().get(0).getTimestamp_start());
328
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400329 ((TextView) convertView.findViewById(R.id.call_time)).setText(String.format("%d:%02d:%02d", duration / 3600, (duration % 3600) / 60,
330 (duration % 60)));
Alexandre Lision6d75d062013-09-13 14:18:34 -0400331 } else {
332 String tmp = "Conference with " + call.getParticipants().size() + " participants";
Alexandre Lision6d75d062013-09-13 14:18:34 -0400333 ((TextView) convertView.findViewById(R.id.call_title)).setText(tmp);
334 }
335 // ((TextView) convertView.findViewById(R.id.num_participants)).setText("" + call.getParticipants().size());
336 ((TextView) convertView.findViewById(R.id.call_status)).setText(call.getState());
337
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400338 convertView.setOnDragListener(dragListener);
Alexandre Lision6d75d062013-09-13 14:18:34 -0400339 convertView.setTag(call);
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400340
Alexandre Lision6d75d062013-09-13 14:18:34 -0400341 return convertView;
342 }
343
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400344 @Override
345 public void update(Observable observable, Object data) {
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400346 Log.i(TAG, "Updating views...");
347 notifyDataSetChanged();
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400348 }
349
Alexandre Lision6d75d062013-09-13 14:18:34 -0400350 }
351
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400352 OnDragListener dragListener = new OnDragListener() {
353
354 @SuppressWarnings("deprecation")
355 // deprecated in API 16....
356 @Override
357 public boolean onDrag(View v, DragEvent event) {
358 switch (event.getAction()) {
359 case DragEvent.ACTION_DRAG_STARTED:
360 // Do nothing
361 Log.w(TAG, "ACTION_DRAG_STARTED");
362 break;
363 case DragEvent.ACTION_DRAG_ENTERED:
364 Log.w(TAG, "ACTION_DRAG_ENTERED");
365 v.setBackgroundColor(Color.GREEN);
366 break;
367 case DragEvent.ACTION_DRAG_EXITED:
368 Log.w(TAG, "ACTION_DRAG_EXITED");
369 v.setBackgroundDrawable(getResources().getDrawable(R.drawable.item_call_selector));
370 break;
371 case DragEvent.ACTION_DROP:
372 Log.w(TAG, "ACTION_DROP");
373 View view = (View) event.getLocalState();
374
375 Item i = event.getClipData().getItemAt(0);
376 Intent intent = i.getIntent();
377 intent.setExtrasClassLoader(Conference.class.getClassLoader());
378
379 Conference initial = (Conference) view.getTag();
380 Conference target = (Conference) v.getTag();
381
382 if (initial == target) {
383 return true;
384 }
385
386 DropActionsChoice dialog = DropActionsChoice.newInstance();
387 Bundle b = new Bundle();
388 b.putParcelable("call_initial", initial);
389 b.putParcelable("call_targeted", target);
390 dialog.setArguments(b);
391 dialog.setTargetFragment(HomeFragment.this, 0);
392 dialog.show(getFragmentManager(), "dialog");
393
394 // view.setBackgroundColor(Color.WHITE);
395 // v.setBackgroundColor(Color.BLACK);
396 break;
397 case DragEvent.ACTION_DRAG_ENDED:
398 Log.w(TAG, "ACTION_DRAG_ENDED");
399 View view1 = (View) event.getLocalState();
400 view1.setVisibility(View.VISIBLE);
401 v.setBackgroundDrawable(getResources().getDrawable(R.drawable.item_call_selector));
402 default:
403 break;
404 }
405 return true;
406 }
407
408 };
409
410 @Override
411 public void onActivityResult(int requestCode, int resultCode, Intent data) {
412 super.onActivityResult(requestCode, resultCode, data);
413 Conference transfer = null;
414 if (requestCode == REQUEST_TRANSFER) {
415 switch (resultCode) {
416 case 0:
417 Conference c = data.getParcelableExtra("target");
418 transfer = data.getParcelableExtra("transfer");
419 try {
420
421 mCallbacks.getService().attendedTransfer(transfer.getParticipants().get(0).getCallId(), c.getParticipants().get(0).getCallId());
422 calls_adapter.remove(transfer);
423 calls_adapter.remove(c);
424 calls_adapter.notifyDataSetChanged();
425 } catch (RemoteException e) {
426 // TODO Auto-generated catch block
427 e.printStackTrace();
428 }
429 Toast.makeText(getActivity(), "Transfer complete", Toast.LENGTH_LONG).show();
430 break;
431
432 case 1:
433 String to = data.getStringExtra("to_number");
434 transfer = data.getParcelableExtra("transfer");
435 try {
436 Toast.makeText(getActivity(), "Transferring " + transfer.getParticipants().get(0).getContact().getmDisplayName() + " to " + to,
437 Toast.LENGTH_SHORT).show();
438 mCallbacks.getService().transfer(transfer.getParticipants().get(0).getCallId(), to);
439 mCallbacks.getService().hangUp(transfer.getParticipants().get(0).getCallId());
440 } catch (RemoteException e) {
441 // TODO Auto-generated catch block
442 e.printStackTrace();
443 }
444 break;
445
446 default:
447 break;
448 }
449 } else if (requestCode == REQUEST_CONF) {
450 switch (resultCode) {
451 case 0:
452 Conference call_to_add = data.getParcelableExtra("transfer");
453 Conference call_target = data.getParcelableExtra("target");
454
455 bindCalls(call_to_add, call_target);
456 break;
457
458 default:
459 break;
460 }
461 }
462 }
463
464 private void bindCalls(Conference call_to_add, Conference call_target) {
465 try {
466
467 if (call_target.hasMultipleParticipants() && !call_to_add.hasMultipleParticipants()) {
468
469 mCallbacks.getService().addParticipant(call_to_add.getParticipants().get(0), call_target.getId());
470
471 } else if (call_target.hasMultipleParticipants() && call_to_add.hasMultipleParticipants()) {
472
473 // We join two conferences
474 mCallbacks.getService().joinConference(call_to_add.getId(), call_target.getId());
475
476 } else if (!call_target.hasMultipleParticipants() && call_to_add.hasMultipleParticipants()) {
477
478 mCallbacks.getService().addParticipant(call_target.getParticipants().get(0), call_to_add.getId());
479
480 } else {
481 // We join two single calls to create a conf
482 mCallbacks.getService().joinParticipant(call_to_add.getParticipants().get(0).getCallId(),
483 call_target.getParticipants().get(0).getCallId());
484 }
485
486 } catch (RemoteException e) {
487 // TODO Auto-generated catch block
488 e.printStackTrace();
489 }
490 }
491
alisionf76de3b2013-04-16 15:35:22 -0400492}