blob: c625fe8ff89b132847dd960fd0f6d9f52bc8542e [file] [log] [blame]
alisionfde875f2013-05-28 17:01:54 -04001/*
alision2ec64f92013-06-17 17:28:58 -04002 * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
alisionfde875f2013-05-28 17:01:54 -04003 *
4 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * Additional permission under GNU GPL version 3 section 7:
21 *
22 * If you modify this program, or any covered work, by linking or
23 * combining it with the OpenSSL project's OpenSSL library (or a
24 * modified version of that library), containing parts covered by the
25 * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
26 * grants you additional permission to convey the resulting work.
27 * Corresponding Source for a non-source form of such a combination
28 * shall include the source code for the parts of OpenSSL used as well
29 * as that of the covered work.
30 */
31
alision84813a12013-05-27 17:40:39 -040032package com.savoirfairelinux.sflphone.fragments;
33
Alexandre Lision2b237922013-09-09 16:23:02 -040034import java.util.ArrayList;
35
alision84813a12013-05-27 17:40:39 -040036import android.app.Activity;
37import android.app.Fragment;
Alexandre Lision2b237922013-09-09 16:23:02 -040038import android.app.FragmentManager;
39import android.content.Intent;
alision84813a12013-05-27 17:40:39 -040040import android.graphics.Bitmap;
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +100041import android.graphics.BitmapFactory;
alision84813a12013-05-27 17:40:39 -040042import android.graphics.PointF;
43import android.os.Bundle;
44import android.os.RemoteException;
alision84813a12013-05-27 17:40:39 -040045import android.util.Log;
46import android.view.LayoutInflater;
Adrien Béraud13cde0b2013-05-30 20:27:20 +100047import android.view.SurfaceHolder;
48import android.view.SurfaceHolder.Callback;
alision84813a12013-05-27 17:40:39 -040049import android.view.View;
50import android.view.ViewGroup;
Alexandre Lision3c6b7102013-09-16 16:56:46 -040051import android.widget.TextView;
Alexandre Lisiona764c682013-09-09 10:02:07 -040052import android.widget.Toast;
alision84813a12013-05-27 17:40:39 -040053
54import com.savoirfairelinux.sflphone.R;
alision84813a12013-05-27 17:40:39 -040055import com.savoirfairelinux.sflphone.model.Attractor;
56import com.savoirfairelinux.sflphone.model.Bubble;
57import com.savoirfairelinux.sflphone.model.BubbleModel;
58import com.savoirfairelinux.sflphone.model.BubblesView;
alisiondf1dac92013-06-27 17:35:53 -040059import com.savoirfairelinux.sflphone.model.Conference;
alision84813a12013-05-27 17:40:39 -040060import com.savoirfairelinux.sflphone.model.SipCall;
alision84813a12013-05-27 17:40:39 -040061import com.savoirfairelinux.sflphone.service.ISipService;
62
Adrien Béraud13cde0b2013-05-30 20:27:20 +100063public class CallFragment extends Fragment implements Callback {
alision84813a12013-05-27 17:40:39 -040064
alision1005ba12013-06-19 13:52:44 -040065 static final String TAG = "CallFragment";
alision84813a12013-05-27 17:40:39 -040066
alisionf57d8a62013-07-02 09:37:12 -040067 float BUBBLE_SIZE = 75;
alision1005ba12013-06-19 13:52:44 -040068 static final float ATTRACTOR_SIZE = 40;
alision84813a12013-05-27 17:40:39 -040069
Alexandre Lision2b237922013-09-09 16:23:02 -040070 public static final int REQUEST_TRANSFER = 10;
71
alisiondf1dac92013-06-27 17:35:53 -040072 private Conference conf;
alision84813a12013-05-27 17:40:39 -040073
Alexandre Lision3c6b7102013-09-16 16:56:46 -040074 private TextView callStatusTxt;
alision1005ba12013-06-19 13:52:44 -040075 private BubblesView view;
76 private BubbleModel model;
alision84813a12013-05-27 17:40:39 -040077
alision1005ba12013-06-19 13:52:44 -040078 private Callbacks mCallbacks = sDummyCallbacks;
alision84813a12013-05-27 17:40:39 -040079
alision806e18e2013-06-21 15:30:17 -040080 private SipCall myself;
alision85704182013-05-29 15:23:03 -040081
Alexandre Lisiona764c682013-09-09 10:02:07 -040082 boolean accepted = false;
83
Alexandre Lision2b237922013-09-09 16:23:02 -040084 private Bitmap hangup_icon, transfer_icon;
alision1005ba12013-06-19 13:52:44 -040085 private Bitmap call_icon;
alision85704182013-05-29 15:23:03 -040086
alision1005ba12013-06-19 13:52:44 -040087 @Override
88 public void onCreate(Bundle savedBundle) {
89 super.onCreate(savedBundle);
alision1005ba12013-06-19 13:52:44 -040090 Bundle b = getArguments();
alisioncd8fb912013-06-28 14:43:51 -040091 conf = new Conference((Conference) b.getParcelable("conference"));
alisiondf1dac92013-06-27 17:35:53 -040092 model = new BubbleModel(getResources().getDisplayMetrics().density);
alision729b0a22013-07-02 11:57:33 -040093 BUBBLE_SIZE = getResources().getDimension(R.dimen.bubble_size);
Alexandre Lisiona764c682013-09-09 10:02:07 -040094 Log.e(TAG, "BUBBLE_SIZE " + BUBBLE_SIZE);
alision729b0a22013-07-02 11:57:33 -040095
alision1005ba12013-06-19 13:52:44 -040096 }
alision85992112013-05-29 12:18:08 -040097
alision1005ba12013-06-19 13:52:44 -040098 /**
99 * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity.
100 */
101 private static Callbacks sDummyCallbacks = new Callbacks() {
102 @Override
103 public void onSendMessage(SipCall call, String msg) {
104 }
alision85992112013-05-29 12:18:08 -0400105
alision1005ba12013-06-19 13:52:44 -0400106 @Override
107 public void callContact(SipCall call) {
108 }
alision85992112013-05-29 12:18:08 -0400109
alision1005ba12013-06-19 13:52:44 -0400110 @Override
111 public void onCallAccepted(SipCall call) {
112 }
alision85704182013-05-29 15:23:03 -0400113
alision1005ba12013-06-19 13:52:44 -0400114 @Override
115 public void onCallRejected(SipCall call) {
116 }
alision85992112013-05-29 12:18:08 -0400117
alision1005ba12013-06-19 13:52:44 -0400118 @Override
119 public void onCallEnded(SipCall call) {
120 }
alision85704182013-05-29 15:23:03 -0400121
alision1005ba12013-06-19 13:52:44 -0400122 @Override
123 public void onCallSuspended(SipCall call) {
124 }
alision85992112013-05-29 12:18:08 -0400125
alision1005ba12013-06-19 13:52:44 -0400126 @Override
127 public void onCallResumed(SipCall call) {
128 }
alision85704182013-05-29 15:23:03 -0400129
alision1005ba12013-06-19 13:52:44 -0400130 @Override
131 public void onCalltransfered(SipCall call, String to) {
132 }
alision85992112013-05-29 12:18:08 -0400133
alision1005ba12013-06-19 13:52:44 -0400134 @Override
135 public void onRecordCall(SipCall call) {
136 }
alision85704182013-05-29 15:23:03 -0400137
alision1005ba12013-06-19 13:52:44 -0400138 @Override
139 public ISipService getService() {
140 return null;
141 }
alisiondf1dac92013-06-27 17:35:53 -0400142
143 @Override
144 public void replaceCurrentCallDisplayed() {
145 }
Alexandre Lision0c384512013-09-17 17:15:57 -0400146
147 @Override
148 public void startTimer() {
149 }
alision1005ba12013-06-19 13:52:44 -0400150 };
alision907bde72013-06-20 14:40:37 -0400151
alision1005ba12013-06-19 13:52:44 -0400152 /**
153 * The Activity calling this fragment has to implement this interface
154 *
155 */
156 public interface Callbacks {
alision85992112013-05-29 12:18:08 -0400157
alision1005ba12013-06-19 13:52:44 -0400158 public ISipService getService();
alision85704182013-05-29 15:23:03 -0400159
alision1005ba12013-06-19 13:52:44 -0400160 public void callContact(SipCall call);
alision85992112013-05-29 12:18:08 -0400161
alision1005ba12013-06-19 13:52:44 -0400162 public void onCallAccepted(SipCall call);
alision85704182013-05-29 15:23:03 -0400163
alision1005ba12013-06-19 13:52:44 -0400164 public void onCallRejected(SipCall call);
alision85992112013-05-29 12:18:08 -0400165
alision1005ba12013-06-19 13:52:44 -0400166 public void onCallEnded(SipCall call);
alision85704182013-05-29 15:23:03 -0400167
alision1005ba12013-06-19 13:52:44 -0400168 public void onCallSuspended(SipCall call);
alision85704182013-05-29 15:23:03 -0400169
alision1005ba12013-06-19 13:52:44 -0400170 public void onCallResumed(SipCall call);
alision84813a12013-05-27 17:40:39 -0400171
alision1005ba12013-06-19 13:52:44 -0400172 public void onCalltransfered(SipCall call, String to);
alision84813a12013-05-27 17:40:39 -0400173
alision1005ba12013-06-19 13:52:44 -0400174 public void onRecordCall(SipCall call);
alision85704182013-05-29 15:23:03 -0400175
alision1005ba12013-06-19 13:52:44 -0400176 public void onSendMessage(SipCall call, String msg);
alisiondf1dac92013-06-27 17:35:53 -0400177
178 public void replaceCurrentCallDisplayed();
Alexandre Lision0c384512013-09-17 17:15:57 -0400179
180 public void startTimer();
alision1005ba12013-06-19 13:52:44 -0400181 }
alision85992112013-05-29 12:18:08 -0400182
alision1005ba12013-06-19 13:52:44 -0400183 @Override
184 public void onAttach(Activity activity) {
185 super.onAttach(activity);
alision85992112013-05-29 12:18:08 -0400186
alision1005ba12013-06-19 13:52:44 -0400187 if (!(activity instanceof Callbacks)) {
188 throw new IllegalStateException("Activity must implement fragment's callbacks.");
189 }
alision85992112013-05-29 12:18:08 -0400190
alision1005ba12013-06-19 13:52:44 -0400191 // rootView.requestDisallowInterceptTouchEvent(true);
alision85992112013-05-29 12:18:08 -0400192
alision1005ba12013-06-19 13:52:44 -0400193 mCallbacks = (Callbacks) activity;
alision50fa0722013-06-25 17:29:44 -0400194 myself = SipCall.SipCallBuilder.buildMyselfCall(activity.getContentResolver(), "Me");
Alexandre Lision0c384512013-09-17 17:15:57 -0400195
alision85992112013-05-29 12:18:08 -0400196
alision1005ba12013-06-19 13:52:44 -0400197 }
alision85992112013-05-29 12:18:08 -0400198
alision1005ba12013-06-19 13:52:44 -0400199 @Override
200 public void onDetach() {
201 super.onDetach();
202 mCallbacks = sDummyCallbacks;
203 // rootView.requestDisallowInterceptTouchEvent(false);
204 }
alision907bde72013-06-20 14:40:37 -0400205
alision1005ba12013-06-19 13:52:44 -0400206 @Override
alision907bde72013-06-20 14:40:37 -0400207 public void onStop() {
alision1005ba12013-06-19 13:52:44 -0400208 super.onStop();
209 }
alision85992112013-05-29 12:18:08 -0400210
alision1005ba12013-06-19 13:52:44 -0400211 @Override
Alexandre Lision2b237922013-09-09 16:23:02 -0400212 public void onActivityResult(int requestCode, int resultCode, Intent data) {
213 super.onActivityResult(requestCode, resultCode, data);
214 SipCall transfer = null;
215 if (requestCode == REQUEST_TRANSFER) {
216 switch (resultCode) {
217 case 0:
218 Conference c = data.getParcelableExtra("target");
219 transfer = data.getParcelableExtra("transfer");
220 try {
221
222 mCallbacks.getService().attendedTransfer(transfer.getCallId(), c.getParticipants().get(0).getCallId());
223
224 } catch (RemoteException e) {
225 // TODO Auto-generated catch block
226 e.printStackTrace();
227 }
228 Toast.makeText(getActivity(), "Transfer complete", Toast.LENGTH_LONG).show();
229 break;
230
231 case 1:
232 String to = data.getStringExtra("to_number");
233 transfer = data.getParcelableExtra("transfer");
234 try {
235 Toast.makeText(getActivity(), "Transferring " + transfer.getContact().getmDisplayName() + " to " + to, Toast.LENGTH_SHORT).show();
236 mCallbacks.getService().transfer(transfer.getCallId(), to);
237 mCallbacks.getService().hangUp(transfer.getCallId());
238 } catch (RemoteException e) {
239 // TODO Auto-generated catch block
240 e.printStackTrace();
241 }
242 break;
243
244 default:
245 break;
246 }
247 }
248 }
249
250 @Override
alision1005ba12013-06-19 13:52:44 -0400251 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
252 ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.frag_call, container, false);
alision85992112013-05-29 12:18:08 -0400253
alision1005ba12013-06-19 13:52:44 -0400254 view = (BubblesView) rootView.findViewById(R.id.main_view);
alision34673e62013-06-25 14:40:07 -0400255 view.setFragment(this);
alision1005ba12013-06-19 13:52:44 -0400256 view.setModel(model);
257 view.getHolder().addCallback(this);
alision84813a12013-05-27 17:40:39 -0400258
Alexandre Lision3c6b7102013-09-16 16:56:46 -0400259 callStatusTxt = (TextView) rootView.findViewById(R.id.call_status_txt);
alision84813a12013-05-27 17:40:39 -0400260
alision1005ba12013-06-19 13:52:44 -0400261 hangup_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_hangup);
262 call_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_call);
Alexandre Lision2b237922013-09-09 16:23:02 -0400263 transfer_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_phones_call_transfer_icon);
alision84813a12013-05-27 17:40:39 -0400264
alision1005ba12013-06-19 13:52:44 -0400265 // Do nothing here, the view is not initialized yet.
266 return rootView;
267 }
alision85992112013-05-29 12:18:08 -0400268
alision1005ba12013-06-19 13:52:44 -0400269 private void initNormalStateDisplay() {
270 Log.i(TAG, "Start normal display");
alision84813a12013-05-27 17:40:39 -0400271
Alexandre Lision0c384512013-09-17 17:15:57 -0400272 mCallbacks.startTimer();
alision84813a12013-05-27 17:40:39 -0400273
alision1005ba12013-06-19 13:52:44 -0400274 getBubbleFor(myself, model.width / 2, model.height / 2);
alision907bde72013-06-20 14:40:37 -0400275
alisiondf1dac92013-06-27 17:35:53 -0400276 int angle_part = 360 / conf.getParticipants().size();
alision806e18e2013-06-21 15:30:17 -0400277 double dX = 0;
278 double dY = 0;
alision465ceba2013-07-04 09:24:30 -0400279 int radiusCalls = (int) (model.width / 2 - BUBBLE_SIZE);
alisiondf1dac92013-06-27 17:35:53 -0400280 for (int i = 0; i < conf.getParticipants().size(); ++i) {
281
282 if (conf.getParticipants().get(i) == null) {
283 Log.i(TAG, i + " null ");
284 continue;
285 }
alision34673e62013-06-25 14:40:07 -0400286 dX = Math.cos(Math.toRadians(angle_part * i - 90)) * radiusCalls;
287 dY = Math.sin(Math.toRadians(angle_part * i - 90)) * radiusCalls;
alisiondf1dac92013-06-27 17:35:53 -0400288 getBubbleFor(conf.getParticipants().get(i), (int) (model.width / 2 + dX), (int) (model.height / 2 + dY));
alision806e18e2013-06-21 15:30:17 -0400289 }
alision1005ba12013-06-19 13:52:44 -0400290
291 model.clearAttractors();
Alexandre Lision2b237922013-09-09 16:23:02 -0400292 model.addAttractor(new Attractor(new PointF(model.width * .2f, model.height * 0.9f), ATTRACTOR_SIZE, new Attractor.Callback() {
alisiondf1dac92013-06-27 17:35:53 -0400293 @Override
294 public boolean onBubbleSucked(Bubble b) {
295 Log.w(TAG, "Bubble sucked ! ");
296
alisioncd8fb912013-06-28 14:43:51 -0400297 if (b.associated_call.getContact().isUser()) {
alisiondf1dac92013-06-27 17:35:53 -0400298
alisioncd8fb912013-06-28 14:43:51 -0400299 try {
300 if (conf.hasMultipleParticipants())
301 mCallbacks.getService().hangUpConference(conf.getId());
302 else
303 mCallbacks.onCallEnded(conf.getParticipants().get(0));
Alexandre Lision2b237922013-09-09 16:23:02 -0400304
305 model.clearAttractors();
alisioncd8fb912013-06-28 14:43:51 -0400306 } catch (RemoteException e) {
307 e.printStackTrace();
308 }
309
310 } else {
311 mCallbacks.onCallEnded(b.associated_call);
312 }
alisiondf1dac92013-06-27 17:35:53 -0400313 bubbleRemoved(b);
314 return true;
315 }
316 }, hangup_icon));
317
Alexandre Lision2b237922013-09-09 16:23:02 -0400318 model.addAttractor(new Attractor(new PointF(model.width * .8f, model.height * 0.9f), ATTRACTOR_SIZE, new Attractor.Callback() {
319 @Override
320 public boolean onBubbleSucked(Bubble b) {
321 Log.w(TAG, "Bubble sucked ! ");
322 makeTransfer(b);
323 return true;
324 }
325 }, transfer_icon));
326
alisiondf1dac92013-06-27 17:35:53 -0400327 // if (conf.hasMultipleParticipants()) {
328 // model.addAttractor(new Attractor(new PointF(model.width / 1.1f, model.height * .9f), ATTRACTOR_SIZE, new Attractor.Callback() {
329 // @Override
330 // public boolean onBubbleSucked(Bubble b) {
331 //
332 // try {
333 // mCallbacks.getService().detachParticipant(b.associated_call.getCallId());
334 // } catch (RemoteException e) {
335 // e.printStackTrace();
336 // }
337 //
338 // bubbleRemoved(b);
339 // return true;
340 // }
341 // }, separate_icon));
342 // }
343
344 // if(mCalls.size() == 1 && mCalls.get(0).isOnHold()){
345 // mCallbacks.onCallResumed(mCalls.get(0));
346 // }
alision84813a12013-05-27 17:40:39 -0400347
alision1005ba12013-06-19 13:52:44 -0400348 }
alision85704182013-05-29 15:23:03 -0400349
alision1005ba12013-06-19 13:52:44 -0400350 private void initIncomingCallDisplay() {
351 Log.i(TAG, "Start incoming display");
alision84813a12013-05-27 17:40:39 -0400352
Alexandre Lision0c384512013-09-17 17:15:57 -0400353 mCallbacks.startTimer();
alision84813a12013-05-27 17:40:39 -0400354
alisiondf1dac92013-06-27 17:35:53 -0400355 getBubbleFor(conf.getParticipants().get(0), model.width / 2, model.height / 2);
alision85704182013-05-29 15:23:03 -0400356
alision1005ba12013-06-19 13:52:44 -0400357 model.clearAttractors();
358 model.addAttractor(new Attractor(new PointF(4 * model.width / 5, model.height / 2), ATTRACTOR_SIZE, new Attractor.Callback() {
359 @Override
360 public boolean onBubbleSucked(Bubble b) {
Alexandre Lisiona764c682013-09-09 10:02:07 -0400361
362 if (!accepted) {
363 mCallbacks.onCallAccepted(conf.getParticipants().get(0));
364 accepted = true;
365 }
alision1005ba12013-06-19 13:52:44 -0400366 return false;
367 }
368 }, call_icon));
369 model.addAttractor(new Attractor(new PointF(model.width / 5, model.height / 2), ATTRACTOR_SIZE, new Attractor.Callback() {
370 @Override
371 public boolean onBubbleSucked(Bubble b) {
alisiondf1dac92013-06-27 17:35:53 -0400372 mCallbacks.onCallRejected(conf.getParticipants().get(0));
alision1005ba12013-06-19 13:52:44 -0400373 bubbleRemoved(b);
374 return true;
375 }
376 }, hangup_icon));
377 }
alision85704182013-05-29 15:23:03 -0400378
alision1005ba12013-06-19 13:52:44 -0400379 private void initOutGoingCallDisplay() {
380 Log.i(TAG, "Start outgoing display");
alision85704182013-05-29 15:23:03 -0400381
Alexandre Lision0c384512013-09-17 17:15:57 -0400382 mCallbacks.startTimer();
alision85704182013-05-29 15:23:03 -0400383
Alexandre Lisionb12f3b52013-09-09 10:50:51 -0400384 getBubbleFor(myself, model.width / 2, (float) (model.height / 2));
alision85704182013-05-29 15:23:03 -0400385
alisiondf1dac92013-06-27 17:35:53 -0400386 // TODO off-thread image loading
387 int angle_part = 360 / conf.getParticipants().size();
388 double dX = 0;
389 double dY = 0;
alision465ceba2013-07-04 09:24:30 -0400390 int radiusCalls = (int) ((model.width / 2 - BUBBLE_SIZE));
alisiondf1dac92013-06-27 17:35:53 -0400391 for (int i = 0; i < conf.getParticipants().size(); ++i) {
392 dX = Math.cos(Math.toRadians(angle_part * i - 90)) * radiusCalls;
393 dY = Math.sin(Math.toRadians(angle_part * i - 90)) * radiusCalls;
394 getBubbleFor(conf.getParticipants().get(i), (int) (model.width / 2 + dX), (int) (model.height / 2 + dY));
395 }
alision907bde72013-06-20 14:40:37 -0400396
alision1005ba12013-06-19 13:52:44 -0400397 model.clearAttractors();
Alexandre Lision2b237922013-09-09 16:23:02 -0400398
Alexandre Lisionb12f3b52013-09-09 10:50:51 -0400399 model.addAttractor(new Attractor(new PointF(model.width / 2f, model.height * .9f), 40, new Attractor.Callback() {
alision1005ba12013-06-19 13:52:44 -0400400 @Override
401 public boolean onBubbleSucked(Bubble b) {
402 Log.w(TAG, "Bubble sucked ! ");
alisiondf1dac92013-06-27 17:35:53 -0400403 mCallbacks.onCallEnded(conf.getParticipants().get(0));
alision1005ba12013-06-19 13:52:44 -0400404 bubbleRemoved(b);
405 return true;
406 }
407 }, hangup_icon));
408 }
alision85704182013-05-29 15:23:03 -0400409
alision1005ba12013-06-19 13:52:44 -0400410 /**
411 * Retrieves or create a bubble for a given contact. If the bubble exists, it is moved to the new location.
412 *
alision806e18e2013-06-21 15:30:17 -0400413 * @param call
414 * The call associated to a contact
alision1005ba12013-06-19 13:52:44 -0400415 * @param x
416 * Initial or new x position.
417 * @param y
418 * Initial or new y position.
419 * @return Bubble corresponding to the contact.
420 */
alision806e18e2013-06-21 15:30:17 -0400421 private Bubble getBubbleFor(SipCall call, float x, float y) {
alisiondf1dac92013-06-27 17:35:53 -0400422 Bubble contact_bubble = model.getBubble(call);
alision1005ba12013-06-19 13:52:44 -0400423 if (contact_bubble != null) {
424 contact_bubble.attractor.set(x, y);
425 return contact_bubble;
426 }
alision84813a12013-05-27 17:40:39 -0400427
alision34673e62013-06-25 14:40:07 -0400428 contact_bubble = new Bubble(getActivity(), call, x, y, BUBBLE_SIZE);
alision84813a12013-05-27 17:40:39 -0400429
alision1005ba12013-06-19 13:52:44 -0400430 model.addBubble(contact_bubble);
alision1005ba12013-06-19 13:52:44 -0400431 return contact_bubble;
432 }
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000433
alision1005ba12013-06-19 13:52:44 -0400434 /**
435 * Should be called when a bubble is removed from the model
436 */
437 void bubbleRemoved(Bubble b) {
alision806e18e2013-06-21 15:30:17 -0400438 if (b.associated_call == null) {
alision1005ba12013-06-19 13:52:44 -0400439 return;
440 }
alision1005ba12013-06-19 13:52:44 -0400441 }
Adrien Béraudc9c424d2013-05-30 17:47:35 +1000442
alision1005ba12013-06-19 13:52:44 -0400443 public void changeCallState(String callID, String newState) {
alisioncd8fb912013-06-28 14:43:51 -0400444 Log.w(TAG, "Call :" + callID + newState);
alisiondf1dac92013-06-27 17:35:53 -0400445 if (newState.contentEquals("FAILURE")) {
446 try {
447 mCallbacks.getService().hangUp(callID);
448 } catch (RemoteException e) {
449 e.printStackTrace();
alision806e18e2013-06-21 15:30:17 -0400450 }
alision1005ba12013-06-19 13:52:44 -0400451 }
alisiondf1dac92013-06-27 17:35:53 -0400452 if (conf.getParticipants() == null) {
alisioncd8fb912013-06-28 14:43:51 -0400453 Log.w(TAG, "IT IS NULL");
alisiondf1dac92013-06-27 17:35:53 -0400454 return;
455 }
456
alisioncd8fb912013-06-28 14:43:51 -0400457 Log.w(TAG, "conf.getParticipants().size():" + conf.getParticipants().size());
alisiondf1dac92013-06-27 17:35:53 -0400458 for (int i = 0; i < conf.getParticipants().size(); ++i) {
459 // conf.getParticipants().get(i).printCallInfo();
alisioncd8fb912013-06-28 14:43:51 -0400460 Log.w(TAG, "Call id:" + conf.getParticipants().get(i).getCallId());
461 Log.w(TAG, "Searching:" + callID);
alisiondf1dac92013-06-27 17:35:53 -0400462 if (callID.equals(conf.getParticipants().get(i).getCallId())) {
463 if (newState.contentEquals("HUNGUP")) {
alisioncd8fb912013-06-28 14:43:51 -0400464 Log.w(TAG, "Call hungup:" + conf.getParticipants().get(i).getContact().getmDisplayName());
alisiondf1dac92013-06-27 17:35:53 -0400465 model.removeBubble(conf.getParticipants().get(i));
466 conf.getParticipants().remove(i);
467 } else {
alisioncd8fb912013-06-28 14:43:51 -0400468 Log.w(TAG, "Call:" + conf.getParticipants().get(i).getContact().getmDisplayName() + " state:" + newState);
alisiondf1dac92013-06-27 17:35:53 -0400469 conf.getParticipants().get(i).setCallState(newState);
470 }
471 }
472 }
473
474 if (conf.isOnGoing())
475 initNormalStateDisplay();
476
477 if (conf.getParticipants().size() == 0) {
478 mCallbacks.replaceCurrentCallDisplayed();
479 }
480
alision1005ba12013-06-19 13:52:44 -0400481 }
alision84813a12013-05-27 17:40:39 -0400482
alision1005ba12013-06-19 13:52:44 -0400483 public boolean draggingBubble() {
484 return view == null ? false : view.isDraggingBubble();
485 }
Adrien Béraudc9c424d2013-05-30 17:47:35 +1000486
alision1005ba12013-06-19 13:52:44 -0400487 @Override
488 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Adrien Béraud13cde0b2013-05-30 20:27:20 +1000489
alisiondf1dac92013-06-27 17:35:53 -0400490 if (conf.getParticipants().size() == 1) {
Adrien Béraud13cde0b2013-05-30 20:27:20 +1000491
alisiondf1dac92013-06-27 17:35:53 -0400492 if (conf.getParticipants().get(0).isIncoming() && conf.getParticipants().get(0).isRinging()) {
alision806e18e2013-06-21 15:30:17 -0400493 initIncomingCallDisplay();
494 } else {
alisiondf1dac92013-06-27 17:35:53 -0400495 if (conf.getParticipants().get(0).isRinging()) {
alision1005ba12013-06-19 13:52:44 -0400496 initOutGoingCallDisplay();
497 }
alision806e18e2013-06-21 15:30:17 -0400498 try {
alisiondf1dac92013-06-27 17:35:53 -0400499 if (conf.getParticipants().get(0).isOutGoing()
500 && mCallbacks.getService().getCall(conf.getParticipants().get(0).getCallId()) == null) {
501 mCallbacks.getService().placeCall(conf.getParticipants().get(0));
alision806e18e2013-06-21 15:30:17 -0400502 initOutGoingCallDisplay();
alisiondf1dac92013-06-27 17:35:53 -0400503 } else if (conf.getParticipants().get(0).isOutGoing() && conf.getParticipants().get(0).isRinging()) {
alision806e18e2013-06-21 15:30:17 -0400504 initOutGoingCallDisplay();
505 }
506 } catch (RemoteException e) {
507 Log.e(TAG, e.toString());
508 }
alision1005ba12013-06-19 13:52:44 -0400509 }
alisiondf1dac92013-06-27 17:35:53 -0400510 if (conf.getParticipants().get(0).isOngoing()) {
alision806e18e2013-06-21 15:30:17 -0400511 initNormalStateDisplay();
512 }
alisiondf1dac92013-06-27 17:35:53 -0400513 } else if (conf.getParticipants().size() > 1) {
alision1005ba12013-06-19 13:52:44 -0400514 initNormalStateDisplay();
515 }
Adrien Béraud13cde0b2013-05-30 20:27:20 +1000516
alision1005ba12013-06-19 13:52:44 -0400517 }
Adrien Béraud13cde0b2013-05-30 20:27:20 +1000518
Alexandre Lision2b237922013-09-09 16:23:02 -0400519 public void makeTransfer(Bubble contact) {
520 FragmentManager fm = getFragmentManager();
521 TransferDFragment editName = new TransferDFragment();
522
523 Bundle b = new Bundle();
524 b.putParcelableArrayList("calls", new ArrayList<Conference>());
525 b.putParcelable("call_selected", contact.associated_call);
526 editName.setArguments(b);
527 editName.setTargetFragment(this, REQUEST_TRANSFER);
528 editName.show(fm, "");
529
530 }
531
alision1005ba12013-06-19 13:52:44 -0400532 @Override
533 public void surfaceCreated(SurfaceHolder holder) {
534 }
Adrien Béraud13cde0b2013-05-30 20:27:20 +1000535
alision1005ba12013-06-19 13:52:44 -0400536 @Override
537 public void surfaceDestroyed(SurfaceHolder holder) {
538 }
Adrien Béraud13cde0b2013-05-30 20:27:20 +1000539
alisione38001f2013-06-04 14:14:39 -0400540 public BubblesView getBubbleView() {
541 return view;
alisione38001f2013-06-04 14:14:39 -0400542
alision1005ba12013-06-19 13:52:44 -0400543 }
Alexandre Lision0c384512013-09-17 17:15:57 -0400544
545 public void updateTime() {
546 long duration = System.currentTimeMillis() / 1000 - (this.conf.getParticipants().get(0).getTimestamp_start());
547 callStatusTxt.setText(String.format("%d:%02d:%02d", duration/3600, (duration%3600)/60, (duration%60)));
548
549 }
alision84813a12013-05-27 17:40:39 -0400550}