blob: 25713727207e26bd96035dc27944c4638c4f0dce [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 Lisione2839d52013-10-01 09:37:37 -040081
Alexandre Lisionf1850c02013-09-23 14:19:34 -040082 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()) {
Alexandre Lision6d75d062013-09-13 14:18:34 -0400177 Conference confOne = new Conference("-1");
178 confOne.getParticipants().add(call);
179 conferences.add(confOne);
180 }
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400181
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400182 calls_adapter.updateDataset(conferences);
Alexandre Lision6d75d062013-09-13 14:18:34 -0400183
Alexandre Lision573045c2013-09-11 17:20:25 -0400184 }
185
alision9f7a6ec2013-05-24 16:26:26 -0400186 @Override
187 public void onDetach() {
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400188
alision9f7a6ec2013-05-24 16:26:26 -0400189 super.onDetach();
190 mCallbacks = sDummyCallbacks;
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400191
alision9f7a6ec2013-05-24 16:26:26 -0400192 }
alisionf76de3b2013-04-16 15:35:22 -0400193
alision9f7a6ec2013-05-24 16:26:26 -0400194 @Override
195 public void onCreate(Bundle savedInstanceState) {
196 super.onCreate(savedInstanceState);
Alexandre Lision0c384512013-09-17 17:15:57 -0400197 }
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400198
Alexandre Lision0c384512013-09-17 17:15:57 -0400199 @Override
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400200 public void onPause() {
Alexandre Lision0c384512013-09-17 17:15:57 -0400201 super.onPause();
202 mHandler.removeCallbacks(mUpdateTimeTask);
alision9f7a6ec2013-05-24 16:26:26 -0400203 }
alisionf76de3b2013-04-16 15:35:22 -0400204
alision9f7a6ec2013-05-24 16:26:26 -0400205 @Override
206 public void onActivityCreated(Bundle savedInstanceState) {
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400207
alision9f7a6ec2013-05-24 16:26:26 -0400208 super.onActivityCreated(savedInstanceState);
alisionf76de3b2013-04-16 15:35:22 -0400209
alision9f7a6ec2013-05-24 16:26:26 -0400210 // Give some text to display if there is no data. In a real
211 // application this would come from a resource.
212 // setEmptyText("No phone numbers");
alisionf76de3b2013-04-16 15:35:22 -0400213
alision9f7a6ec2013-05-24 16:26:26 -0400214 // We have a menu item to show in action bar.
215 setHasOptionsMenu(true);
alisionf76de3b2013-04-16 15:35:22 -0400216
alision9f7a6ec2013-05-24 16:26:26 -0400217 }
alision371b77e2013-04-23 14:51:26 -0400218
alision9f7a6ec2013-05-24 16:26:26 -0400219 @Override
220 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400221
alision9f7a6ec2013-05-24 16:26:26 -0400222 inflater.inflate(R.menu.call_element_menu, menu);
alisionf76de3b2013-04-16 15:35:22 -0400223
alision9f7a6ec2013-05-24 16:26:26 -0400224 }
alisionf76de3b2013-04-16 15:35:22 -0400225
alision9f7a6ec2013-05-24 16:26:26 -0400226 @Override
227 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
228 Log.i(TAG, "onCreateView");
alision465ceba2013-07-04 09:24:30 -0400229 View inflatedView = inflater.inflate(R.layout.frag_home, container, false);
alision43a9b362013-05-01 16:30:15 -0400230
Alexandre Lisionc51ccb12013-09-11 16:00:30 -0400231 nb_calls = (TextView) inflatedView.findViewById(R.id.calls_counter);
232 nb_confs = (TextView) inflatedView.findViewById(R.id.confs_counter);
Alexandre Lision6d75d062013-09-13 14:18:34 -0400233
234 confs_adapter = new CallListAdapter(getActivity());
235 ((ListView) inflatedView.findViewById(R.id.confs_list)).setAdapter(confs_adapter);
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400236
Alexandre Lision6d75d062013-09-13 14:18:34 -0400237 calls_adapter = new CallListAdapter(getActivity());
238 ((ListView) inflatedView.findViewById(R.id.calls_list)).setAdapter(calls_adapter);
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400239 ((ListView) inflatedView.findViewById(R.id.calls_list)).setOnItemClickListener(callClickListener);
240 ((ListView) inflatedView.findViewById(R.id.confs_list)).setOnItemClickListener(callClickListener);
alision43a9b362013-05-01 16:30:15 -0400241
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400242 ((ListView) inflatedView.findViewById(R.id.calls_list)).setOnItemLongClickListener(mItemLongClickListener);
243 ((ListView) inflatedView.findViewById(R.id.confs_list)).setOnItemLongClickListener(mItemLongClickListener);
244
alision9f7a6ec2013-05-24 16:26:26 -0400245 return inflatedView;
246 }
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400247
248 OnItemClickListener callClickListener = new OnItemClickListener() {
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400249
250 @Override
251 public void onItemClick(AdapterView<?> arg0, View v, int arg2, long arg3) {
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400252 mCallbacks.selectedCall((Conference) v.getTag());
Alexandre Lision1a9e3b12013-09-16 11:06:07 -0400253 }
254 };
alisione2a38e12013-04-25 14:20:20 -0400255
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400256 private OnItemLongClickListener mItemLongClickListener = new OnItemLongClickListener() {
257
258 @Override
259 public boolean onItemLongClick(AdapterView<?> adptv, View view, int pos, long arg3) {
260 final Vibrator vibe = (Vibrator) view.getContext().getSystemService(Context.VIBRATOR_SERVICE);
261 vibe.vibrate(80);
262 Intent i = new Intent();
263 Bundle b = new Bundle();
264 b.putParcelable("conference", (Conference) adptv.getAdapter().getItem(pos));
265 i.putExtra("bconference", b);
266
267 DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
268 ClipData data = ClipData.newIntent("conference", i);
269 view.startDrag(data, shadowBuilder, view, 0);
270 return false;
271 }
272
273 };
274
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400275 public class CallListAdapter extends BaseAdapter implements Observer {
Alexandre Lision6d75d062013-09-13 14:18:34 -0400276
277 private ArrayList<Conference> calls;
278
279 private Context mContext;
280
281 public CallListAdapter(Context act) {
282 super();
283 mContext = act;
284 calls = new ArrayList<Conference>();
285
286 }
287
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400288 public ArrayList<Conference> getDataset() {
289 return calls;
290 }
291
Alexandre Lision6d75d062013-09-13 14:18:34 -0400292 public void remove(Conference transfer) {
293
294 }
295
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400296 public void updateDataset(ArrayList<Conference> list) {
Alexandre Lision6d75d062013-09-13 14:18:34 -0400297 calls.clear();
298 calls.addAll(list);
299 notifyDataSetChanged();
300 }
301
302 @Override
303 public int getCount() {
304 return calls.size();
305 }
306
307 @Override
308 public Conference getItem(int position) {
309 return calls.get(position);
310 }
311
312 @Override
313 public long getItemId(int position) {
314 return 0;
315 }
316
317 @Override
318 public View getView(int position, View convertView, ViewGroup parent) {
319 if (convertView == null)
320 convertView = LayoutInflater.from(mContext).inflate(R.layout.item_calllist, null);
321
322 Conference call = calls.get(position);
323 if (call.getParticipants().size() == 1) {
324 ((TextView) convertView.findViewById(R.id.call_title)).setText(call.getParticipants().get(0).getContact().getmDisplayName());
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400325
326 long duration = System.currentTimeMillis() / 1000 - (call.getParticipants().get(0).getTimestamp_start());
327
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400328 ((TextView) convertView.findViewById(R.id.call_time)).setText(String.format("%d:%02d:%02d", duration / 3600, (duration % 3600) / 60,
329 (duration % 60)));
Alexandre Lision6d75d062013-09-13 14:18:34 -0400330 } else {
Alexandre Lision64d63232013-10-01 09:34:56 -0400331// String tmp = "Conference with " + call.getParticipants().size() + " participants";
332 ((TextView) convertView.findViewById(R.id.call_title)).setText(getString(R.string.home_conf_item, call.getParticipants().size()));
Alexandre Lision6d75d062013-09-13 14:18:34 -0400333 }
334 // ((TextView) convertView.findViewById(R.id.num_participants)).setText("" + call.getParticipants().size());
335 ((TextView) convertView.findViewById(R.id.call_status)).setText(call.getState());
336
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400337 convertView.setOnDragListener(dragListener);
Alexandre Lision6d75d062013-09-13 14:18:34 -0400338 convertView.setTag(call);
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400339
Alexandre Lision6d75d062013-09-13 14:18:34 -0400340 return convertView;
341 }
342
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400343 @Override
344 public void update(Observable observable, Object data) {
Alexandre Lisionebeb3662013-09-17 16:20:54 -0400345 Log.i(TAG, "Updating views...");
346 notifyDataSetChanged();
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400347 }
348
Alexandre Lision6d75d062013-09-13 14:18:34 -0400349 }
350
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400351 OnDragListener dragListener = new OnDragListener() {
352
353 @SuppressWarnings("deprecation")
354 // deprecated in API 16....
355 @Override
356 public boolean onDrag(View v, DragEvent event) {
357 switch (event.getAction()) {
358 case DragEvent.ACTION_DRAG_STARTED:
359 // Do nothing
Alexandre Lisione2839d52013-10-01 09:37:37 -0400360 // Log.w(TAG, "ACTION_DRAG_STARTED");
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400361 break;
362 case DragEvent.ACTION_DRAG_ENTERED:
Alexandre Lisione2839d52013-10-01 09:37:37 -0400363 // Log.w(TAG, "ACTION_DRAG_ENTERED");
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400364 v.setBackgroundColor(Color.GREEN);
365 break;
366 case DragEvent.ACTION_DRAG_EXITED:
Alexandre Lisione2839d52013-10-01 09:37:37 -0400367 // Log.w(TAG, "ACTION_DRAG_EXITED");
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400368 v.setBackgroundDrawable(getResources().getDrawable(R.drawable.item_call_selector));
369 break;
370 case DragEvent.ACTION_DROP:
Alexandre Lisione2839d52013-10-01 09:37:37 -0400371 // Log.w(TAG, "ACTION_DROP");
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400372 View view = (View) event.getLocalState();
373
374 Item i = event.getClipData().getItemAt(0);
375 Intent intent = i.getIntent();
376 intent.setExtrasClassLoader(Conference.class.getClassLoader());
377
378 Conference initial = (Conference) view.getTag();
379 Conference target = (Conference) v.getTag();
380
381 if (initial == target) {
382 return true;
383 }
384
385 DropActionsChoice dialog = DropActionsChoice.newInstance();
386 Bundle b = new Bundle();
387 b.putParcelable("call_initial", initial);
388 b.putParcelable("call_targeted", target);
389 dialog.setArguments(b);
390 dialog.setTargetFragment(HomeFragment.this, 0);
391 dialog.show(getFragmentManager(), "dialog");
392
393 // view.setBackgroundColor(Color.WHITE);
394 // v.setBackgroundColor(Color.BLACK);
395 break;
396 case DragEvent.ACTION_DRAG_ENDED:
Alexandre Lisione2839d52013-10-01 09:37:37 -0400397 // Log.w(TAG, "ACTION_DRAG_ENDED");
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400398 View view1 = (View) event.getLocalState();
399 view1.setVisibility(View.VISIBLE);
400 v.setBackgroundDrawable(getResources().getDrawable(R.drawable.item_call_selector));
401 default:
402 break;
403 }
404 return true;
405 }
406
407 };
Alexandre Lisione2839d52013-10-01 09:37:37 -0400408
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400409 @Override
410 public void onActivityResult(int requestCode, int resultCode, Intent data) {
411 super.onActivityResult(requestCode, resultCode, data);
412 Conference transfer = null;
413 if (requestCode == REQUEST_TRANSFER) {
414 switch (resultCode) {
415 case 0:
416 Conference c = data.getParcelableExtra("target");
417 transfer = data.getParcelableExtra("transfer");
418 try {
419
420 mCallbacks.getService().attendedTransfer(transfer.getParticipants().get(0).getCallId(), c.getParticipants().get(0).getCallId());
421 calls_adapter.remove(transfer);
422 calls_adapter.remove(c);
423 calls_adapter.notifyDataSetChanged();
424 } catch (RemoteException e) {
425 // TODO Auto-generated catch block
426 e.printStackTrace();
427 }
Alexandre Lision64d63232013-10-01 09:34:56 -0400428 Toast.makeText(getActivity(), getString(R.string.home_transfer_complet), Toast.LENGTH_LONG).show();
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400429 break;
430
431 case 1:
432 String to = data.getStringExtra("to_number");
433 transfer = data.getParcelableExtra("transfer");
434 try {
Alexandre Lision64d63232013-10-01 09:34:56 -0400435 Toast.makeText(getActivity(), getString(R.string.home_transfering,transfer.getParticipants().get(0).getContact().getmDisplayName(),to),
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400436 Toast.LENGTH_SHORT).show();
437 mCallbacks.getService().transfer(transfer.getParticipants().get(0).getCallId(), to);
438 mCallbacks.getService().hangUp(transfer.getParticipants().get(0).getCallId());
439 } catch (RemoteException e) {
440 // TODO Auto-generated catch block
441 e.printStackTrace();
442 }
443 break;
444
445 default:
446 break;
447 }
448 } else if (requestCode == REQUEST_CONF) {
449 switch (resultCode) {
450 case 0:
451 Conference call_to_add = data.getParcelableExtra("transfer");
452 Conference call_target = data.getParcelableExtra("target");
453
454 bindCalls(call_to_add, call_target);
455 break;
456
457 default:
458 break;
459 }
460 }
461 }
Alexandre Lisione2839d52013-10-01 09:37:37 -0400462
Alexandre Lisionf1850c02013-09-23 14:19:34 -0400463 private void bindCalls(Conference call_to_add, Conference call_target) {
464 try {
465
466 if (call_target.hasMultipleParticipants() && !call_to_add.hasMultipleParticipants()) {
467
468 mCallbacks.getService().addParticipant(call_to_add.getParticipants().get(0), call_target.getId());
469
470 } else if (call_target.hasMultipleParticipants() && call_to_add.hasMultipleParticipants()) {
471
472 // We join two conferences
473 mCallbacks.getService().joinConference(call_to_add.getId(), call_target.getId());
474
475 } else if (!call_target.hasMultipleParticipants() && call_to_add.hasMultipleParticipants()) {
476
477 mCallbacks.getService().addParticipant(call_target.getParticipants().get(0), call_to_add.getId());
478
479 } else {
480 // We join two single calls to create a conf
481 mCallbacks.getService().joinParticipant(call_to_add.getParticipants().get(0).getCallId(),
482 call_target.getParticipants().get(0).getCallId());
483 }
484
485 } catch (RemoteException e) {
486 // TODO Auto-generated catch block
487 e.printStackTrace();
488 }
489 }
490
alisionf76de3b2013-04-16 15:35:22 -0400491}