blob: 7dd4f0e1d7535acf2e0c335a1d27386beaaa9b4a [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 Lisiona764c682013-09-09 10:02:07 -040051import android.widget.Toast;
alision84813a12013-05-27 17:40:39 -040052
53import com.savoirfairelinux.sflphone.R;
alision84813a12013-05-27 17:40:39 -040054import com.savoirfairelinux.sflphone.model.Attractor;
55import com.savoirfairelinux.sflphone.model.Bubble;
56import com.savoirfairelinux.sflphone.model.BubbleModel;
57import com.savoirfairelinux.sflphone.model.BubblesView;
alisiondf1dac92013-06-27 17:35:53 -040058import com.savoirfairelinux.sflphone.model.Conference;
alision84813a12013-05-27 17:40:39 -040059import com.savoirfairelinux.sflphone.model.SipCall;
alision84813a12013-05-27 17:40:39 -040060import com.savoirfairelinux.sflphone.service.ISipService;
alision50fa0722013-06-25 17:29:44 -040061import com.savoirfairelinux.sflphone.views.CounterTextView;
alision84813a12013-05-27 17:40:39 -040062
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
alision50fa0722013-06-25 17:29:44 -040074 private CounterTextView 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 }
alision1005ba12013-06-19 13:52:44 -0400146 };
alision907bde72013-06-20 14:40:37 -0400147
alision1005ba12013-06-19 13:52:44 -0400148 /**
149 * The Activity calling this fragment has to implement this interface
150 *
151 */
152 public interface Callbacks {
alision85992112013-05-29 12:18:08 -0400153
alision1005ba12013-06-19 13:52:44 -0400154 public ISipService getService();
alision85704182013-05-29 15:23:03 -0400155
alision1005ba12013-06-19 13:52:44 -0400156 public void callContact(SipCall call);
alision85992112013-05-29 12:18:08 -0400157
alision1005ba12013-06-19 13:52:44 -0400158 public void onCallAccepted(SipCall call);
alision85704182013-05-29 15:23:03 -0400159
alision1005ba12013-06-19 13:52:44 -0400160 public void onCallRejected(SipCall call);
alision85992112013-05-29 12:18:08 -0400161
alision1005ba12013-06-19 13:52:44 -0400162 public void onCallEnded(SipCall call);
alision85704182013-05-29 15:23:03 -0400163
alision1005ba12013-06-19 13:52:44 -0400164 public void onCallSuspended(SipCall call);
alision85704182013-05-29 15:23:03 -0400165
alision1005ba12013-06-19 13:52:44 -0400166 public void onCallResumed(SipCall call);
alision84813a12013-05-27 17:40:39 -0400167
alision1005ba12013-06-19 13:52:44 -0400168 public void onCalltransfered(SipCall call, String to);
alision84813a12013-05-27 17:40:39 -0400169
alision1005ba12013-06-19 13:52:44 -0400170 public void onRecordCall(SipCall call);
alision85704182013-05-29 15:23:03 -0400171
alision1005ba12013-06-19 13:52:44 -0400172 public void onSendMessage(SipCall call, String msg);
alisiondf1dac92013-06-27 17:35:53 -0400173
174 public void replaceCurrentCallDisplayed();
alision1005ba12013-06-19 13:52:44 -0400175 }
alision85992112013-05-29 12:18:08 -0400176
alision1005ba12013-06-19 13:52:44 -0400177 @Override
178 public void onAttach(Activity activity) {
179 super.onAttach(activity);
alision85992112013-05-29 12:18:08 -0400180
alision1005ba12013-06-19 13:52:44 -0400181 if (!(activity instanceof Callbacks)) {
182 throw new IllegalStateException("Activity must implement fragment's callbacks.");
183 }
alision85992112013-05-29 12:18:08 -0400184
alision1005ba12013-06-19 13:52:44 -0400185 // rootView.requestDisallowInterceptTouchEvent(true);
alision85992112013-05-29 12:18:08 -0400186
alision1005ba12013-06-19 13:52:44 -0400187 mCallbacks = (Callbacks) activity;
alision50fa0722013-06-25 17:29:44 -0400188 myself = SipCall.SipCallBuilder.buildMyselfCall(activity.getContentResolver(), "Me");
alision85992112013-05-29 12:18:08 -0400189
alision1005ba12013-06-19 13:52:44 -0400190 }
alision85992112013-05-29 12:18:08 -0400191
alision1005ba12013-06-19 13:52:44 -0400192 @Override
193 public void onDetach() {
194 super.onDetach();
195 mCallbacks = sDummyCallbacks;
196 // rootView.requestDisallowInterceptTouchEvent(false);
197 }
alision907bde72013-06-20 14:40:37 -0400198
alision1005ba12013-06-19 13:52:44 -0400199 @Override
alision907bde72013-06-20 14:40:37 -0400200 public void onStop() {
alision1005ba12013-06-19 13:52:44 -0400201 super.onStop();
202 }
alision85992112013-05-29 12:18:08 -0400203
alision1005ba12013-06-19 13:52:44 -0400204 @Override
Alexandre Lision2b237922013-09-09 16:23:02 -0400205 public void onActivityResult(int requestCode, int resultCode, Intent data) {
206 super.onActivityResult(requestCode, resultCode, data);
207 SipCall transfer = null;
208 if (requestCode == REQUEST_TRANSFER) {
209 switch (resultCode) {
210 case 0:
211 Conference c = data.getParcelableExtra("target");
212 transfer = data.getParcelableExtra("transfer");
213 try {
214
215 mCallbacks.getService().attendedTransfer(transfer.getCallId(), c.getParticipants().get(0).getCallId());
216
217 } catch (RemoteException e) {
218 // TODO Auto-generated catch block
219 e.printStackTrace();
220 }
221 Toast.makeText(getActivity(), "Transfer complete", Toast.LENGTH_LONG).show();
222 break;
223
224 case 1:
225 String to = data.getStringExtra("to_number");
226 transfer = data.getParcelableExtra("transfer");
227 try {
228 Toast.makeText(getActivity(), "Transferring " + transfer.getContact().getmDisplayName() + " to " + to, Toast.LENGTH_SHORT).show();
229 mCallbacks.getService().transfer(transfer.getCallId(), to);
230 mCallbacks.getService().hangUp(transfer.getCallId());
231 } catch (RemoteException e) {
232 // TODO Auto-generated catch block
233 e.printStackTrace();
234 }
235 break;
236
237 default:
238 break;
239 }
240 }
241 }
242
243 @Override
alision1005ba12013-06-19 13:52:44 -0400244 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
245 ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.frag_call, container, false);
alision85992112013-05-29 12:18:08 -0400246
alision1005ba12013-06-19 13:52:44 -0400247 view = (BubblesView) rootView.findViewById(R.id.main_view);
alision34673e62013-06-25 14:40:07 -0400248 view.setFragment(this);
alision1005ba12013-06-19 13:52:44 -0400249 view.setModel(model);
250 view.getHolder().addCallback(this);
alision84813a12013-05-27 17:40:39 -0400251
alision50fa0722013-06-25 17:29:44 -0400252 callStatusTxt = (CounterTextView) rootView.findViewById(R.id.call_status_txt);
alision84813a12013-05-27 17:40:39 -0400253
alision1005ba12013-06-19 13:52:44 -0400254 hangup_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_hangup);
255 call_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_call);
Alexandre Lision2b237922013-09-09 16:23:02 -0400256 transfer_icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_phones_call_transfer_icon);
alision84813a12013-05-27 17:40:39 -0400257
alision1005ba12013-06-19 13:52:44 -0400258 // Do nothing here, the view is not initialized yet.
259 return rootView;
260 }
alision85992112013-05-29 12:18:08 -0400261
alision1005ba12013-06-19 13:52:44 -0400262 private void initNormalStateDisplay() {
263 Log.i(TAG, "Start normal display");
alision84813a12013-05-27 17:40:39 -0400264
alision1005ba12013-06-19 13:52:44 -0400265 callStatusTxt.setText("0 min");
alision84813a12013-05-27 17:40:39 -0400266
alision1005ba12013-06-19 13:52:44 -0400267 getBubbleFor(myself, model.width / 2, model.height / 2);
alision907bde72013-06-20 14:40:37 -0400268
alisiondf1dac92013-06-27 17:35:53 -0400269 int angle_part = 360 / conf.getParticipants().size();
alision806e18e2013-06-21 15:30:17 -0400270 double dX = 0;
271 double dY = 0;
alision465ceba2013-07-04 09:24:30 -0400272 int radiusCalls = (int) (model.width / 2 - BUBBLE_SIZE);
alisiondf1dac92013-06-27 17:35:53 -0400273 for (int i = 0; i < conf.getParticipants().size(); ++i) {
274
275 if (conf.getParticipants().get(i) == null) {
276 Log.i(TAG, i + " null ");
277 continue;
278 }
alision34673e62013-06-25 14:40:07 -0400279 dX = Math.cos(Math.toRadians(angle_part * i - 90)) * radiusCalls;
280 dY = Math.sin(Math.toRadians(angle_part * i - 90)) * radiusCalls;
alisiondf1dac92013-06-27 17:35:53 -0400281 getBubbleFor(conf.getParticipants().get(i), (int) (model.width / 2 + dX), (int) (model.height / 2 + dY));
alision806e18e2013-06-21 15:30:17 -0400282 }
alision1005ba12013-06-19 13:52:44 -0400283
284 model.clearAttractors();
Alexandre Lision2b237922013-09-09 16:23:02 -0400285 model.addAttractor(new Attractor(new PointF(model.width * .2f, model.height * 0.9f), ATTRACTOR_SIZE, new Attractor.Callback() {
alisiondf1dac92013-06-27 17:35:53 -0400286 @Override
287 public boolean onBubbleSucked(Bubble b) {
288 Log.w(TAG, "Bubble sucked ! ");
289
alisioncd8fb912013-06-28 14:43:51 -0400290 if (b.associated_call.getContact().isUser()) {
alisiondf1dac92013-06-27 17:35:53 -0400291
alisioncd8fb912013-06-28 14:43:51 -0400292 try {
293 if (conf.hasMultipleParticipants())
294 mCallbacks.getService().hangUpConference(conf.getId());
295 else
296 mCallbacks.onCallEnded(conf.getParticipants().get(0));
Alexandre Lision2b237922013-09-09 16:23:02 -0400297
298 model.clearAttractors();
alisioncd8fb912013-06-28 14:43:51 -0400299 } catch (RemoteException e) {
300 e.printStackTrace();
301 }
302
303 } else {
304 mCallbacks.onCallEnded(b.associated_call);
305 }
alisiondf1dac92013-06-27 17:35:53 -0400306 bubbleRemoved(b);
307 return true;
308 }
309 }, hangup_icon));
310
Alexandre Lision2b237922013-09-09 16:23:02 -0400311 model.addAttractor(new Attractor(new PointF(model.width * .8f, model.height * 0.9f), ATTRACTOR_SIZE, new Attractor.Callback() {
312 @Override
313 public boolean onBubbleSucked(Bubble b) {
314 Log.w(TAG, "Bubble sucked ! ");
315 makeTransfer(b);
316 return true;
317 }
318 }, transfer_icon));
319
alisiondf1dac92013-06-27 17:35:53 -0400320 // if (conf.hasMultipleParticipants()) {
321 // model.addAttractor(new Attractor(new PointF(model.width / 1.1f, model.height * .9f), ATTRACTOR_SIZE, new Attractor.Callback() {
322 // @Override
323 // public boolean onBubbleSucked(Bubble b) {
324 //
325 // try {
326 // mCallbacks.getService().detachParticipant(b.associated_call.getCallId());
327 // } catch (RemoteException e) {
328 // e.printStackTrace();
329 // }
330 //
331 // bubbleRemoved(b);
332 // return true;
333 // }
334 // }, separate_icon));
335 // }
336
337 // if(mCalls.size() == 1 && mCalls.get(0).isOnHold()){
338 // mCallbacks.onCallResumed(mCalls.get(0));
339 // }
alision84813a12013-05-27 17:40:39 -0400340
alision1005ba12013-06-19 13:52:44 -0400341 }
alision85704182013-05-29 15:23:03 -0400342
alision1005ba12013-06-19 13:52:44 -0400343 private void initIncomingCallDisplay() {
344 Log.i(TAG, "Start incoming display");
alision84813a12013-05-27 17:40:39 -0400345
alisiondf1dac92013-06-27 17:35:53 -0400346 callStatusTxt.setText("Incoming call");
alision84813a12013-05-27 17:40:39 -0400347
alisiondf1dac92013-06-27 17:35:53 -0400348 getBubbleFor(conf.getParticipants().get(0), model.width / 2, model.height / 2);
alision85704182013-05-29 15:23:03 -0400349
alision1005ba12013-06-19 13:52:44 -0400350 model.clearAttractors();
351 model.addAttractor(new Attractor(new PointF(4 * model.width / 5, model.height / 2), ATTRACTOR_SIZE, new Attractor.Callback() {
352 @Override
353 public boolean onBubbleSucked(Bubble b) {
Alexandre Lisiona764c682013-09-09 10:02:07 -0400354
355 if (!accepted) {
356 mCallbacks.onCallAccepted(conf.getParticipants().get(0));
357 accepted = true;
358 }
alision1005ba12013-06-19 13:52:44 -0400359 return false;
360 }
361 }, call_icon));
362 model.addAttractor(new Attractor(new PointF(model.width / 5, model.height / 2), ATTRACTOR_SIZE, new Attractor.Callback() {
363 @Override
364 public boolean onBubbleSucked(Bubble b) {
alisiondf1dac92013-06-27 17:35:53 -0400365 mCallbacks.onCallRejected(conf.getParticipants().get(0));
alision1005ba12013-06-19 13:52:44 -0400366 bubbleRemoved(b);
367 return true;
368 }
369 }, hangup_icon));
370 }
alision85704182013-05-29 15:23:03 -0400371
alision1005ba12013-06-19 13:52:44 -0400372 private void initOutGoingCallDisplay() {
373 Log.i(TAG, "Start outgoing display");
alision85704182013-05-29 15:23:03 -0400374
alision1005ba12013-06-19 13:52:44 -0400375 callStatusTxt.setText("Calling...");
alision85704182013-05-29 15:23:03 -0400376
Alexandre Lisionb12f3b52013-09-09 10:50:51 -0400377 getBubbleFor(myself, model.width / 2, (float) (model.height / 2));
alision85704182013-05-29 15:23:03 -0400378
alisiondf1dac92013-06-27 17:35:53 -0400379 // TODO off-thread image loading
380 int angle_part = 360 / conf.getParticipants().size();
381 double dX = 0;
382 double dY = 0;
alision465ceba2013-07-04 09:24:30 -0400383 int radiusCalls = (int) ((model.width / 2 - BUBBLE_SIZE));
alisiondf1dac92013-06-27 17:35:53 -0400384 for (int i = 0; i < conf.getParticipants().size(); ++i) {
385 dX = Math.cos(Math.toRadians(angle_part * i - 90)) * radiusCalls;
386 dY = Math.sin(Math.toRadians(angle_part * i - 90)) * radiusCalls;
387 getBubbleFor(conf.getParticipants().get(i), (int) (model.width / 2 + dX), (int) (model.height / 2 + dY));
388 }
alision907bde72013-06-20 14:40:37 -0400389
alision1005ba12013-06-19 13:52:44 -0400390 model.clearAttractors();
Alexandre Lision2b237922013-09-09 16:23:02 -0400391
Alexandre Lisionb12f3b52013-09-09 10:50:51 -0400392 model.addAttractor(new Attractor(new PointF(model.width / 2f, model.height * .9f), 40, new Attractor.Callback() {
alision1005ba12013-06-19 13:52:44 -0400393 @Override
394 public boolean onBubbleSucked(Bubble b) {
395 Log.w(TAG, "Bubble sucked ! ");
alisiondf1dac92013-06-27 17:35:53 -0400396 mCallbacks.onCallEnded(conf.getParticipants().get(0));
alision1005ba12013-06-19 13:52:44 -0400397 bubbleRemoved(b);
398 return true;
399 }
400 }, hangup_icon));
401 }
alision85704182013-05-29 15:23:03 -0400402
alision1005ba12013-06-19 13:52:44 -0400403 /**
404 * Retrieves or create a bubble for a given contact. If the bubble exists, it is moved to the new location.
405 *
alision806e18e2013-06-21 15:30:17 -0400406 * @param call
407 * The call associated to a contact
alision1005ba12013-06-19 13:52:44 -0400408 * @param x
409 * Initial or new x position.
410 * @param y
411 * Initial or new y position.
412 * @return Bubble corresponding to the contact.
413 */
alision806e18e2013-06-21 15:30:17 -0400414 private Bubble getBubbleFor(SipCall call, float x, float y) {
alisiondf1dac92013-06-27 17:35:53 -0400415 Bubble contact_bubble = model.getBubble(call);
alision1005ba12013-06-19 13:52:44 -0400416 if (contact_bubble != null) {
417 contact_bubble.attractor.set(x, y);
418 return contact_bubble;
419 }
alision84813a12013-05-27 17:40:39 -0400420
alision34673e62013-06-25 14:40:07 -0400421 contact_bubble = new Bubble(getActivity(), call, x, y, BUBBLE_SIZE);
alision84813a12013-05-27 17:40:39 -0400422
alision1005ba12013-06-19 13:52:44 -0400423 model.addBubble(contact_bubble);
alision1005ba12013-06-19 13:52:44 -0400424 return contact_bubble;
425 }
Adrien Béraud0c9bd8f2013-05-30 16:16:57 +1000426
alision1005ba12013-06-19 13:52:44 -0400427 /**
428 * Should be called when a bubble is removed from the model
429 */
430 void bubbleRemoved(Bubble b) {
alision806e18e2013-06-21 15:30:17 -0400431 if (b.associated_call == null) {
alision1005ba12013-06-19 13:52:44 -0400432 return;
433 }
alision1005ba12013-06-19 13:52:44 -0400434 }
Adrien Béraudc9c424d2013-05-30 17:47:35 +1000435
alision1005ba12013-06-19 13:52:44 -0400436 public void changeCallState(String callID, String newState) {
alisioncd8fb912013-06-28 14:43:51 -0400437 Log.w(TAG, "Call :" + callID + newState);
alisiondf1dac92013-06-27 17:35:53 -0400438 if (newState.contentEquals("FAILURE")) {
439 try {
440 mCallbacks.getService().hangUp(callID);
441 } catch (RemoteException e) {
442 e.printStackTrace();
alision806e18e2013-06-21 15:30:17 -0400443 }
alision1005ba12013-06-19 13:52:44 -0400444 }
alisiondf1dac92013-06-27 17:35:53 -0400445 if (conf.getParticipants() == null) {
alisioncd8fb912013-06-28 14:43:51 -0400446 Log.w(TAG, "IT IS NULL");
alisiondf1dac92013-06-27 17:35:53 -0400447 return;
448 }
449
alisioncd8fb912013-06-28 14:43:51 -0400450 Log.w(TAG, "conf.getParticipants().size():" + conf.getParticipants().size());
alisiondf1dac92013-06-27 17:35:53 -0400451 for (int i = 0; i < conf.getParticipants().size(); ++i) {
452 // conf.getParticipants().get(i).printCallInfo();
alisioncd8fb912013-06-28 14:43:51 -0400453 Log.w(TAG, "Call id:" + conf.getParticipants().get(i).getCallId());
454 Log.w(TAG, "Searching:" + callID);
alisiondf1dac92013-06-27 17:35:53 -0400455 if (callID.equals(conf.getParticipants().get(i).getCallId())) {
456 if (newState.contentEquals("HUNGUP")) {
alisioncd8fb912013-06-28 14:43:51 -0400457 Log.w(TAG, "Call hungup:" + conf.getParticipants().get(i).getContact().getmDisplayName());
alisiondf1dac92013-06-27 17:35:53 -0400458 model.removeBubble(conf.getParticipants().get(i));
459 conf.getParticipants().remove(i);
460 } else {
alisioncd8fb912013-06-28 14:43:51 -0400461 Log.w(TAG, "Call:" + conf.getParticipants().get(i).getContact().getmDisplayName() + " state:" + newState);
alisiondf1dac92013-06-27 17:35:53 -0400462 conf.getParticipants().get(i).setCallState(newState);
463 }
464 }
465 }
466
467 if (conf.isOnGoing())
468 initNormalStateDisplay();
469
470 if (conf.getParticipants().size() == 0) {
471 mCallbacks.replaceCurrentCallDisplayed();
472 }
473
alision1005ba12013-06-19 13:52:44 -0400474 }
alision84813a12013-05-27 17:40:39 -0400475
alision1005ba12013-06-19 13:52:44 -0400476 public boolean draggingBubble() {
477 return view == null ? false : view.isDraggingBubble();
478 }
Adrien Béraudc9c424d2013-05-30 17:47:35 +1000479
alision1005ba12013-06-19 13:52:44 -0400480 @Override
481 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Adrien Béraud13cde0b2013-05-30 20:27:20 +1000482
alisiondf1dac92013-06-27 17:35:53 -0400483 if (conf.getParticipants().size() == 1) {
Adrien Béraud13cde0b2013-05-30 20:27:20 +1000484
alisiondf1dac92013-06-27 17:35:53 -0400485 if (conf.getParticipants().get(0).isIncoming() && conf.getParticipants().get(0).isRinging()) {
alision806e18e2013-06-21 15:30:17 -0400486 initIncomingCallDisplay();
487 } else {
alisiondf1dac92013-06-27 17:35:53 -0400488 if (conf.getParticipants().get(0).isRinging()) {
alision1005ba12013-06-19 13:52:44 -0400489 initOutGoingCallDisplay();
490 }
alision806e18e2013-06-21 15:30:17 -0400491 try {
alisiondf1dac92013-06-27 17:35:53 -0400492 if (conf.getParticipants().get(0).isOutGoing()
493 && mCallbacks.getService().getCall(conf.getParticipants().get(0).getCallId()) == null) {
494 mCallbacks.getService().placeCall(conf.getParticipants().get(0));
alision806e18e2013-06-21 15:30:17 -0400495 initOutGoingCallDisplay();
alisiondf1dac92013-06-27 17:35:53 -0400496 } else if (conf.getParticipants().get(0).isOutGoing() && conf.getParticipants().get(0).isRinging()) {
alision806e18e2013-06-21 15:30:17 -0400497 initOutGoingCallDisplay();
498 }
499 } catch (RemoteException e) {
500 Log.e(TAG, e.toString());
501 }
alision1005ba12013-06-19 13:52:44 -0400502 }
Adrien Béraud13cde0b2013-05-30 20:27:20 +1000503
alisiondf1dac92013-06-27 17:35:53 -0400504 if (conf.getParticipants().get(0).isOngoing()) {
alision806e18e2013-06-21 15:30:17 -0400505 initNormalStateDisplay();
506 }
alisiondf1dac92013-06-27 17:35:53 -0400507 } else if (conf.getParticipants().size() > 1) {
alision1005ba12013-06-19 13:52:44 -0400508 initNormalStateDisplay();
509 }
Adrien Béraud13cde0b2013-05-30 20:27:20 +1000510
alision1005ba12013-06-19 13:52:44 -0400511 }
Adrien Béraud13cde0b2013-05-30 20:27:20 +1000512
Alexandre Lision2b237922013-09-09 16:23:02 -0400513 public void makeTransfer(Bubble contact) {
514 FragmentManager fm = getFragmentManager();
515 TransferDFragment editName = new TransferDFragment();
516
517 Bundle b = new Bundle();
518 b.putParcelableArrayList("calls", new ArrayList<Conference>());
519 b.putParcelable("call_selected", contact.associated_call);
520 editName.setArguments(b);
521 editName.setTargetFragment(this, REQUEST_TRANSFER);
522 editName.show(fm, "");
523
524 }
525
alision1005ba12013-06-19 13:52:44 -0400526 @Override
527 public void surfaceCreated(SurfaceHolder holder) {
528 }
Adrien Béraud13cde0b2013-05-30 20:27:20 +1000529
alision1005ba12013-06-19 13:52:44 -0400530 @Override
531 public void surfaceDestroyed(SurfaceHolder holder) {
532 }
Adrien Béraud13cde0b2013-05-30 20:27:20 +1000533
alisione38001f2013-06-04 14:14:39 -0400534 public BubblesView getBubbleView() {
535 return view;
alisione38001f2013-06-04 14:14:39 -0400536
alision1005ba12013-06-19 13:52:44 -0400537 }
alision84813a12013-05-27 17:40:39 -0400538}