blob: 03eb086967383c99fccd8641400a4b969fa9e7cc [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 */
Alexandre Lision064e1e02013-10-01 16:18:42 -040031package org.sflphone.fragments;
alisionf76de3b2013-04-16 15:35:22 -040032
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
Alexandre Lision064e1e02013-10-01 16:18:42 -040038import org.sflphone.R;
39import org.sflphone.fragments.CallListFragment.DropActionsChoice;
40import org.sflphone.model.CallTimer;
41import org.sflphone.model.Conference;
42import org.sflphone.model.SipCall;
43import org.sflphone.service.ISipService;
44
alisionf76de3b2013-04-16 15:35:22 -040045import android.app.Activity;
alisionb1763882013-06-18 17:30:51 -040046import android.app.Fragment;
Alexandre Lisionf1850c02013-09-23 14:19:34 -040047import android.content.ClipData;
Alexandre Lision064e1e02013-10-01 16:18:42 -040048import android.content.ClipData.Item;
Alexandre Lision6d75d062013-09-13 14:18:34 -040049import android.content.Context;
Alexandre Lisionf1850c02013-09-23 14:19:34 -040050import android.content.Intent;
Alexandre Lisionf1850c02013-09-23 14:19:34 -040051import android.graphics.Color;
alisionf76de3b2013-04-16 15:35:22 -040052import android.os.Bundle;
Alexandre Lisionebeb3662013-09-17 16:20:54 -040053import android.os.Handler;
alision2cb99562013-05-30 17:02:20 -040054import android.os.RemoteException;
Alexandre Lisionebeb3662013-09-17 16:20:54 -040055import android.os.SystemClock;
Alexandre Lisionf1850c02013-09-23 14:19:34 -040056import android.os.Vibrator;
alisionf76de3b2013-04-16 15:35:22 -040057import android.util.Log;
Alexandre Lisionf1850c02013-09-23 14:19:34 -040058import android.view.DragEvent;
alisionf76de3b2013-04-16 15:35:22 -040059import android.view.LayoutInflater;
60import android.view.View;
Alexandre Lisionf1850c02013-09-23 14:19:34 -040061import android.view.View.DragShadowBuilder;
62import android.view.View.OnDragListener;
Alexandre Lision064e1e02013-10-01 16:18:42 -040063import android.view.ViewGroup;
Alexandre Lision1a9e3b12013-09-16 11:06:07 -040064import android.widget.AdapterView;
65import android.widget.AdapterView.OnItemClickListener;
Alexandre Lisionf1850c02013-09-23 14:19:34 -040066import android.widget.AdapterView.OnItemLongClickListener;
Alexandre Lision6d75d062013-09-13 14:18:34 -040067import android.widget.BaseAdapter;
Alexandre Lision573045c2013-09-11 17:20:25 -040068import android.widget.ListView;
Alexandre Lisionc51ccb12013-09-11 16:00:30 -040069import android.widget.TextView;
Alexandre Lisionf1850c02013-09-23 14:19:34 -040070import android.widget.Toast;
alisionf76de3b2013-04-16 15:35:22 -040071
alisionb1763882013-06-18 17:30:51 -040072public class HomeFragment extends Fragment {
alision55c36cb2013-06-14 14:57:38 -040073 private static final String TAG = HomeFragment.class.getSimpleName();
alision907bde72013-06-20 14:40:37 -040074
alision9f7a6ec2013-05-24 16:26:26 -040075 private Callbacks mCallbacks = sDummyCallbacks;
Alexandre Lisionf1850c02013-09-23 14:19:34 -040076 private TextView nb_calls, nb_confs;
77 CallListAdapter confs_adapter, calls_adapter;
Alexandre Lisionebeb3662013-09-17 16:20:54 -040078 CallTimer timer;
Alexandre Lisione2839d52013-10-01 09:37:37 -040079
Alexandre Lisionf1850c02013-09-23 14:19:34 -040080 public static final int REQUEST_TRANSFER = 10;
81 public static final int REQUEST_CONF = 20;
alision43a9b362013-05-01 16:30:15 -040082
alision9f7a6ec2013-05-24 16:26:26 -040083 /**
84 * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity.
85 */
86 private static Callbacks sDummyCallbacks = new Callbacks() {
alision371b77e2013-04-23 14:51:26 -040087
alision9f7a6ec2013-05-24 16:26:26 -040088 @Override
89 public ISipService getService() {
alision2cb99562013-05-30 17:02:20 -040090 Log.i(TAG, "I'm a dummy");
alision9f7a6ec2013-05-24 16:26:26 -040091 return null;
92 }
alisiondf1dac92013-06-27 17:35:53 -040093
94 @Override
Alexandre Lision1a9e3b12013-09-16 11:06:07 -040095 public void selectedCall(Conference c) {
alisiondf1dac92013-06-27 17:35:53 -040096 }
alision9f7a6ec2013-05-24 16:26:26 -040097 };
alision371b77e2013-04-23 14:51:26 -040098
alision9f7a6ec2013-05-24 16:26:26 -040099 /**
100 * The Activity calling this fragment has to implement this interface
101 *
102 */
103 public interface Callbacks {
alision371b77e2013-04-23 14:51:26 -0400104
alision9f7a6ec2013-05-24 16:26:26 -0400105 public ISipService getService();
alision43a9b362013-05-01 16:30:15 -0400106
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400107 public void selectedCall(Conference c);
alisiondf1dac92013-06-27 17:35:53 -0400108
alision9f7a6ec2013-05-24 16:26:26 -0400109 }
alisionf76de3b2013-04-16 15:35:22 -0400110
alision9f7a6ec2013-05-24 16:26:26 -0400111 @Override
112 public void onAttach(Activity activity) {
113 super.onAttach(activity);
alisionf76de3b2013-04-16 15:35:22 -0400114
alision9f7a6ec2013-05-24 16:26:26 -0400115 if (!(activity instanceof Callbacks)) {
116 throw new IllegalStateException("Activity must implement fragment's callbacks.");
117 }
alisionf76de3b2013-04-16 15:35:22 -0400118
alision9f7a6ec2013-05-24 16:26:26 -0400119 mCallbacks = (Callbacks) activity;
alisiondf1dac92013-06-27 17:35:53 -0400120
alision2cb99562013-05-30 17:02:20 -0400121 }
alisiondf1dac92013-06-27 17:35:53 -0400122
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400123 private Runnable mUpdateTimeTask = new Runnable() {
124 public void run() {
125 final long start = SystemClock.uptimeMillis();
126 long millis = SystemClock.uptimeMillis() - start;
127 int seconds = (int) (millis / 1000);
128 int minutes = seconds / 60;
129 seconds = seconds % 60;
130
131 calls_adapter.notifyDataSetChanged();
Alexandre Lision0c384512013-09-17 17:15:57 -0400132 confs_adapter.notifyDataSetChanged();
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400133 mHandler.postAtTime(this, start + (((minutes * 60) + seconds + 1) * 1000));
134 }
135 };
136
137 private Handler mHandler = new Handler();
138
alision2cb99562013-05-30 17:02:20 -0400139 @Override
alisiondf1dac92013-06-27 17:35:53 -0400140 public void onResume() {
alision2cb99562013-05-30 17:02:20 -0400141 super.onResume();
alision2cb99562013-05-30 17:02:20 -0400142 if (mCallbacks.getService() != null) {
143 try {
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400144 updateLists();
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400145 if (!calls_adapter.isEmpty() || !confs_adapter.isEmpty()) {
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400146 mHandler.postDelayed(mUpdateTimeTask, 0);
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400147 }
alision2cb99562013-05-30 17:02:20 -0400148
alision2cb99562013-05-30 17:02:20 -0400149 } catch (RemoteException e) {
150 Log.e(TAG, e.toString());
151 }
152 }
alisiondf1dac92013-06-27 17:35:53 -0400153
alision9f7a6ec2013-05-24 16:26:26 -0400154 }
alisionf76de3b2013-04-16 15:35:22 -0400155
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400156 @SuppressWarnings("unchecked")
157 // No proper solution with HashMap runtime cast
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400158 public void updateLists() throws RemoteException {
159 HashMap<String, SipCall> calls = (HashMap<String, SipCall>) mCallbacks.getService().getCallList();
160 HashMap<String, Conference> confs = (HashMap<String, Conference>) mCallbacks.getService().getConferenceList();
161
162 updateCallList(calls);
163 updateConferenceList(confs);
164 }
165
Alexandre Lision573045c2013-09-11 17:20:25 -0400166 private void updateConferenceList(HashMap<String, Conference> confs) {
Alexandre Lision6d75d062013-09-13 14:18:34 -0400167 nb_confs.setText("" + confs.size());
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400168 confs_adapter.updateDataset(new ArrayList<Conference>(confs.values()));
Alexandre Lision573045c2013-09-11 17:20:25 -0400169 }
170
171 private void updateCallList(HashMap<String, SipCall> calls) {
Alexandre Lision6d75d062013-09-13 14:18:34 -0400172 nb_calls.setText("" + calls.size());
173 ArrayList<Conference> conferences = new ArrayList<Conference>();
174 for (SipCall call : calls.values()) {
Alexandre Lision6d75d062013-09-13 14:18:34 -0400175 Conference confOne = new Conference("-1");
176 confOne.getParticipants().add(call);
177 conferences.add(confOne);
178 }
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400179
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400180 calls_adapter.updateDataset(conferences);
Alexandre Lision6d75d062013-09-13 14:18:34 -0400181
Alexandre Lision573045c2013-09-11 17:20:25 -0400182 }
183
alision9f7a6ec2013-05-24 16:26:26 -0400184 @Override
185 public void onDetach() {
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400186
alision9f7a6ec2013-05-24 16:26:26 -0400187 super.onDetach();
188 mCallbacks = sDummyCallbacks;
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400189
alision9f7a6ec2013-05-24 16:26:26 -0400190 }
alisionf76de3b2013-04-16 15:35:22 -0400191
alision9f7a6ec2013-05-24 16:26:26 -0400192 @Override
193 public void onCreate(Bundle savedInstanceState) {
194 super.onCreate(savedInstanceState);
Alexandre Lision0c384512013-09-17 17:15:57 -0400195 }
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400196
Alexandre Lision0c384512013-09-17 17:15:57 -0400197 @Override
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400198 public void onPause() {
Alexandre Lision0c384512013-09-17 17:15:57 -0400199 super.onPause();
200 mHandler.removeCallbacks(mUpdateTimeTask);
alision9f7a6ec2013-05-24 16:26:26 -0400201 }
alisionf76de3b2013-04-16 15:35:22 -0400202
alision9f7a6ec2013-05-24 16:26:26 -0400203 @Override
204 public void onActivityCreated(Bundle savedInstanceState) {
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400205
alision9f7a6ec2013-05-24 16:26:26 -0400206 super.onActivityCreated(savedInstanceState);
alisionf76de3b2013-04-16 15:35:22 -0400207
alision9f7a6ec2013-05-24 16:26:26 -0400208 // Give some text to display if there is no data. In a real
209 // application this would come from a resource.
210 // setEmptyText("No phone numbers");
alisionf76de3b2013-04-16 15:35:22 -0400211
alision9f7a6ec2013-05-24 16:26:26 -0400212 // We have a menu item to show in action bar.
213 setHasOptionsMenu(true);
alisionf76de3b2013-04-16 15:35:22 -0400214
alision9f7a6ec2013-05-24 16:26:26 -0400215 }
alision371b77e2013-04-23 14:51:26 -0400216
alision9f7a6ec2013-05-24 16:26:26 -0400217 @Override
alision9f7a6ec2013-05-24 16:26:26 -0400218 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
219 Log.i(TAG, "onCreateView");
alision465ceba2013-07-04 09:24:30 -0400220 View inflatedView = inflater.inflate(R.layout.frag_home, container, false);
alision43a9b362013-05-01 16:30:15 -0400221
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400222 nb_calls = (TextView) inflatedView.findViewById(R.id.calls_counter);
223 nb_confs = (TextView) inflatedView.findViewById(R.id.confs_counter);
Alexandre Lision6d75d062013-09-13 14:18:34 -0400224
225 confs_adapter = new CallListAdapter(getActivity());
226 ((ListView) inflatedView.findViewById(R.id.confs_list)).setAdapter(confs_adapter);
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400227
Alexandre Lision6d75d062013-09-13 14:18:34 -0400228 calls_adapter = new CallListAdapter(getActivity());
229 ((ListView) inflatedView.findViewById(R.id.calls_list)).setAdapter(calls_adapter);
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400230 ((ListView) inflatedView.findViewById(R.id.calls_list)).setOnItemClickListener(callClickListener);
231 ((ListView) inflatedView.findViewById(R.id.confs_list)).setOnItemClickListener(callClickListener);
alision43a9b362013-05-01 16:30:15 -0400232
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400233 ((ListView) inflatedView.findViewById(R.id.calls_list)).setOnItemLongClickListener(mItemLongClickListener);
234 ((ListView) inflatedView.findViewById(R.id.confs_list)).setOnItemLongClickListener(mItemLongClickListener);
235
alision9f7a6ec2013-05-24 16:26:26 -0400236 return inflatedView;
237 }
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400238
239 OnItemClickListener callClickListener = new OnItemClickListener() {
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400240
241 @Override
242 public void onItemClick(AdapterView<?> arg0, View v, int arg2, long arg3) {
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400243 mCallbacks.selectedCall((Conference) v.getTag());
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400244 }
245 };
alisione2a38e12013-04-25 14:20:20 -0400246
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400247 private OnItemLongClickListener mItemLongClickListener = new OnItemLongClickListener() {
248
249 @Override
250 public boolean onItemLongClick(AdapterView<?> adptv, View view, int pos, long arg3) {
251 final Vibrator vibe = (Vibrator) view.getContext().getSystemService(Context.VIBRATOR_SERVICE);
252 vibe.vibrate(80);
253 Intent i = new Intent();
254 Bundle b = new Bundle();
255 b.putParcelable("conference", (Conference) adptv.getAdapter().getItem(pos));
256 i.putExtra("bconference", b);
257
258 DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
259 ClipData data = ClipData.newIntent("conference", i);
260 view.startDrag(data, shadowBuilder, view, 0);
261 return false;
262 }
263
264 };
265
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400266 public class CallListAdapter extends BaseAdapter implements Observer {
Alexandre Lision6d75d062013-09-13 14:18:34 -0400267
268 private ArrayList<Conference> calls;
269
270 private Context mContext;
271
272 public CallListAdapter(Context act) {
273 super();
274 mContext = act;
275 calls = new ArrayList<Conference>();
276
277 }
278
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400279 public ArrayList<Conference> getDataset() {
280 return calls;
281 }
282
Alexandre Lision6d75d062013-09-13 14:18:34 -0400283 public void remove(Conference transfer) {
284
285 }
286
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400287 public void updateDataset(ArrayList<Conference> list) {
Alexandre Lision6d75d062013-09-13 14:18:34 -0400288 calls.clear();
289 calls.addAll(list);
290 notifyDataSetChanged();
291 }
292
293 @Override
294 public int getCount() {
295 return calls.size();
296 }
297
298 @Override
299 public Conference getItem(int position) {
300 return calls.get(position);
301 }
302
303 @Override
304 public long getItemId(int position) {
305 return 0;
306 }
307
308 @Override
309 public View getView(int position, View convertView, ViewGroup parent) {
310 if (convertView == null)
311 convertView = LayoutInflater.from(mContext).inflate(R.layout.item_calllist, null);
312
313 Conference call = calls.get(position);
314 if (call.getParticipants().size() == 1) {
315 ((TextView) convertView.findViewById(R.id.call_title)).setText(call.getParticipants().get(0).getContact().getmDisplayName());
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400316
317 long duration = System.currentTimeMillis() / 1000 - (call.getParticipants().get(0).getTimestamp_start());
318
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400319 ((TextView) convertView.findViewById(R.id.call_time)).setText(String.format("%d:%02d:%02d", duration / 3600, (duration % 3600) / 60,
320 (duration % 60)));
Alexandre Lision6d75d062013-09-13 14:18:34 -0400321 } else {
Alexandre Lision64d63232013-10-01 09:34:56 -0400322// String tmp = "Conference with " + call.getParticipants().size() + " participants";
323 ((TextView) convertView.findViewById(R.id.call_title)).setText(getString(R.string.home_conf_item, call.getParticipants().size()));
Alexandre Lision6d75d062013-09-13 14:18:34 -0400324 }
325 // ((TextView) convertView.findViewById(R.id.num_participants)).setText("" + call.getParticipants().size());
326 ((TextView) convertView.findViewById(R.id.call_status)).setText(call.getState());
327
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400328 convertView.setOnDragListener(dragListener);
Alexandre Lision6d75d062013-09-13 14:18:34 -0400329 convertView.setTag(call);
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400330
Alexandre Lision6d75d062013-09-13 14:18:34 -0400331 return convertView;
332 }
333
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400334 @Override
335 public void update(Observable observable, Object data) {
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400336 Log.i(TAG, "Updating views...");
337 notifyDataSetChanged();
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400338 }
339
Alexandre Lision6d75d062013-09-13 14:18:34 -0400340 }
341
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400342 OnDragListener dragListener = new OnDragListener() {
343
344 @SuppressWarnings("deprecation")
345 // deprecated in API 16....
346 @Override
347 public boolean onDrag(View v, DragEvent event) {
348 switch (event.getAction()) {
349 case DragEvent.ACTION_DRAG_STARTED:
350 // Do nothing
Alexandre Lisione2839d52013-10-01 09:37:37 -0400351 // Log.w(TAG, "ACTION_DRAG_STARTED");
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400352 break;
353 case DragEvent.ACTION_DRAG_ENTERED:
Alexandre Lisione2839d52013-10-01 09:37:37 -0400354 // Log.w(TAG, "ACTION_DRAG_ENTERED");
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400355 v.setBackgroundColor(Color.GREEN);
356 break;
357 case DragEvent.ACTION_DRAG_EXITED:
Alexandre Lisione2839d52013-10-01 09:37:37 -0400358 // Log.w(TAG, "ACTION_DRAG_EXITED");
Alexandre Lisionbdef65e2013-10-09 17:11:15 -0400359 v.setBackgroundDrawable(getResources().getDrawable(R.drawable.item_generic_selector));
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400360 break;
361 case DragEvent.ACTION_DROP:
Alexandre Lisione2839d52013-10-01 09:37:37 -0400362 // Log.w(TAG, "ACTION_DROP");
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400363 View view = (View) event.getLocalState();
364
365 Item i = event.getClipData().getItemAt(0);
366 Intent intent = i.getIntent();
367 intent.setExtrasClassLoader(Conference.class.getClassLoader());
368
369 Conference initial = (Conference) view.getTag();
370 Conference target = (Conference) v.getTag();
371
372 if (initial == target) {
373 return true;
374 }
375
376 DropActionsChoice dialog = DropActionsChoice.newInstance();
377 Bundle b = new Bundle();
378 b.putParcelable("call_initial", initial);
379 b.putParcelable("call_targeted", target);
380 dialog.setArguments(b);
381 dialog.setTargetFragment(HomeFragment.this, 0);
382 dialog.show(getFragmentManager(), "dialog");
383
384 // view.setBackgroundColor(Color.WHITE);
385 // v.setBackgroundColor(Color.BLACK);
386 break;
387 case DragEvent.ACTION_DRAG_ENDED:
Alexandre Lisione2839d52013-10-01 09:37:37 -0400388 // Log.w(TAG, "ACTION_DRAG_ENDED");
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400389 View view1 = (View) event.getLocalState();
390 view1.setVisibility(View.VISIBLE);
Alexandre Lisionbdef65e2013-10-09 17:11:15 -0400391 v.setBackgroundDrawable(getResources().getDrawable(R.drawable.item_generic_selector));
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400392 default:
393 break;
394 }
395 return true;
396 }
397
398 };
Alexandre Lisione2839d52013-10-01 09:37:37 -0400399
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400400 @Override
401 public void onActivityResult(int requestCode, int resultCode, Intent data) {
402 super.onActivityResult(requestCode, resultCode, data);
403 Conference transfer = null;
404 if (requestCode == REQUEST_TRANSFER) {
405 switch (resultCode) {
406 case 0:
407 Conference c = data.getParcelableExtra("target");
408 transfer = data.getParcelableExtra("transfer");
409 try {
410
411 mCallbacks.getService().attendedTransfer(transfer.getParticipants().get(0).getCallId(), c.getParticipants().get(0).getCallId());
412 calls_adapter.remove(transfer);
413 calls_adapter.remove(c);
414 calls_adapter.notifyDataSetChanged();
415 } catch (RemoteException e) {
416 // TODO Auto-generated catch block
417 e.printStackTrace();
418 }
Alexandre Lision64d63232013-10-01 09:34:56 -0400419 Toast.makeText(getActivity(), getString(R.string.home_transfer_complet), Toast.LENGTH_LONG).show();
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400420 break;
421
422 case 1:
423 String to = data.getStringExtra("to_number");
424 transfer = data.getParcelableExtra("transfer");
425 try {
Alexandre Lision64d63232013-10-01 09:34:56 -0400426 Toast.makeText(getActivity(), getString(R.string.home_transfering,transfer.getParticipants().get(0).getContact().getmDisplayName(),to),
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400427 Toast.LENGTH_SHORT).show();
428 mCallbacks.getService().transfer(transfer.getParticipants().get(0).getCallId(), to);
429 mCallbacks.getService().hangUp(transfer.getParticipants().get(0).getCallId());
430 } catch (RemoteException e) {
431 // TODO Auto-generated catch block
432 e.printStackTrace();
433 }
434 break;
435
436 default:
437 break;
438 }
439 } else if (requestCode == REQUEST_CONF) {
440 switch (resultCode) {
441 case 0:
442 Conference call_to_add = data.getParcelableExtra("transfer");
443 Conference call_target = data.getParcelableExtra("target");
444
445 bindCalls(call_to_add, call_target);
446 break;
447
448 default:
449 break;
450 }
451 }
452 }
Alexandre Lisione2839d52013-10-01 09:37:37 -0400453
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400454 private void bindCalls(Conference call_to_add, Conference call_target) {
455 try {
456
457 if (call_target.hasMultipleParticipants() && !call_to_add.hasMultipleParticipants()) {
458
459 mCallbacks.getService().addParticipant(call_to_add.getParticipants().get(0), call_target.getId());
460
461 } else if (call_target.hasMultipleParticipants() && call_to_add.hasMultipleParticipants()) {
462
463 // We join two conferences
464 mCallbacks.getService().joinConference(call_to_add.getId(), call_target.getId());
465
466 } else if (!call_target.hasMultipleParticipants() && call_to_add.hasMultipleParticipants()) {
467
468 mCallbacks.getService().addParticipant(call_target.getParticipants().get(0), call_to_add.getId());
469
470 } else {
471 // We join two single calls to create a conf
472 mCallbacks.getService().joinParticipant(call_to_add.getParticipants().get(0).getCallId(),
473 call_target.getParticipants().get(0).getCallId());
474 }
475
476 } catch (RemoteException e) {
477 // TODO Auto-generated catch block
478 e.printStackTrace();
479 }
480 }
481
alisionf76de3b2013-04-16 15:35:22 -0400482}