blob: 33ac5f6fb63ebddcfe2f924a23192d5d11602751 [file] [log] [blame]
Adrien Béraud04d822c2015-04-02 17:44:36 -04001/*
Adrien Béraudda712a42015-11-22 23:45:26 -05002 * Copyright (C) 2004-2015 Savoir-faire Linux Inc.
Adrien Béraud04d822c2015-04-02 17:44:36 -04003 *
4 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
Adrien Béraudda712a42015-11-22 23:45:26 -05005 * Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com>
Adrien Béraud04d822c2015-04-02 17:44:36 -04006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
Adrien Béraudda712a42015-11-22 23:45:26 -050019 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Adrien Béraud04d822c2015-04-02 17:44:36 -040020 */
21
22package cx.ring.fragments;
23
24import android.app.Activity;
Adrien Béraudda712a42015-11-22 23:45:26 -050025import android.graphics.Color;
Adrien Béraudb179bab2015-10-08 12:04:22 -040026import android.net.Uri;
Adrien Béraudb179bab2015-10-08 12:04:22 -040027import android.support.v4.app.NotificationCompat;
28import android.support.v4.app.NotificationManagerCompat;
Adrien Béraud04d822c2015-04-02 17:44:36 -040029import android.content.Context;
30import android.content.Intent;
Adrien Béraud04d822c2015-04-02 17:44:36 -040031import android.content.res.Resources;
32import android.graphics.Bitmap;
Adrien Béraud04d822c2015-04-02 17:44:36 -040033import android.os.Bundle;
34import android.os.PowerManager;
35import android.os.PowerManager.WakeLock;
36import android.os.RemoteException;
Adrien Bérauddde513c2015-10-22 11:21:52 -040037import android.support.v7.app.ActionBar;
Adrien Béraud04d822c2015-04-02 17:44:36 -040038import android.util.Log;
39import android.view.*;
Adrien Béraud04d822c2015-04-02 17:44:36 -040040import android.view.View.OnClickListener;
Adrien Béraud04d822c2015-04-02 17:44:36 -040041import android.widget.*;
42import android.widget.CompoundButton.OnCheckedChangeListener;
43import cx.ring.R;
Adrien Béraudb179bab2015-10-08 12:04:22 -040044import cx.ring.adapters.ContactPictureTask;
Adrien Béraudb179bab2015-10-08 12:04:22 -040045import cx.ring.client.ConversationActivity;
46import cx.ring.client.HomeActivity;
Adrien Béraud04d822c2015-04-02 17:44:36 -040047import cx.ring.interfaces.CallInterface;
Adrien Béraud04d822c2015-04-02 17:44:36 -040048
Adrien Béraud04d822c2015-04-02 17:44:36 -040049import java.util.Locale;
50
Adrien Béraud04d822c2015-04-02 17:44:36 -040051import cx.ring.model.CallContact;
52import cx.ring.model.Conference;
53import cx.ring.model.SecureSipCall;
54import cx.ring.model.SipCall;
Adrien Béraudb179bab2015-10-08 12:04:22 -040055import cx.ring.model.account.Account;
Adrien Béraud4c6d29b2015-11-19 18:10:35 -050056import cx.ring.service.DRingService;
Adrien Béraudb179bab2015-10-08 12:04:22 -040057import cx.ring.service.LocalService;
Adrien Béraud04d822c2015-04-02 17:44:36 -040058
Adrien Béraudb179bab2015-10-08 12:04:22 -040059public class CallFragment extends CallableWrapperFragment implements CallInterface {
Adrien Béraud04d822c2015-04-02 17:44:36 -040060
Adrien Béraudda712a42015-11-22 23:45:26 -050061 static private final String TAG = CallFragment.class.getSimpleName();
Adrien Béraud04d822c2015-04-02 17:44:36 -040062
Adrien Béraud04d822c2015-04-02 17:44:36 -040063 public static final int REQUEST_TRANSFER = 10;
64
65 // Screen wake lock for incoming call
66 private WakeLock mScreenWakeLock;
Adrien Béraudb179bab2015-10-08 12:04:22 -040067 private ImageView contactBubbleView;
68 private TextView contactBubbleTxt;
69 private View acceptButton;
70 private View refuseButton;
71 private View hangupButton;
Adrien Béraud04d822c2015-04-02 17:44:36 -040072
Adrien Béraudb179bab2015-10-08 12:04:22 -040073 private View securityIndicator;
74
Adrien Béraud04d822c2015-04-02 17:44:36 -040075 ViewSwitcher mSecuritySwitch;
76 private TextView mCallStatusTxt;
Adrien Béraudda712a42015-11-22 23:45:26 -050077 private boolean mSpeakerPhone = false;
78 //private ToggleButton mToggleSpeakers;
Adrien Béraud04d822c2015-04-02 17:44:36 -040079
80 public Callbacks mCallbacks = sDummyCallbacks;
Adrien Béraud04d822c2015-04-02 17:44:36 -040081
82 TransferDFragment editName;
Adrien Béraud04d822c2015-04-02 17:44:36 -040083
84 @Override
85 public void onCreate(Bundle savedBundle) {
Adrien Béraudb179bab2015-10-08 12:04:22 -040086 Log.i(TAG, "onCreate");
Adrien Béraud04d822c2015-04-02 17:44:36 -040087 super.onCreate(savedBundle);
88
89 Resources r = getResources();
Adrien Béraud04d822c2015-04-02 17:44:36 -040090
91 setHasOptionsMenu(true);
92 PowerManager powerManager = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE);
93 mScreenWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE,
Adrien Béraudb179bab2015-10-08 12:04:22 -040094 "cx.ring.onIncomingCall");
Adrien Béraud04d822c2015-04-02 17:44:36 -040095 mScreenWakeLock.setReferenceCounted(false);
96
97 Log.d(TAG, "Acquire wake up lock");
98 if (mScreenWakeLock != null && !mScreenWakeLock.isHeld()) {
99 mScreenWakeLock.acquire();
100 }
Adrien Béraud04d822c2015-04-02 17:44:36 -0400101 }
102
103 /**
Adrien Béraudb179bab2015-10-08 12:04:22 -0400104 * The Activity calling this fragment has to implement this interface
105 */
106 public interface Callbacks extends LocalService.Callbacks {
Adrien Béraudb179bab2015-10-08 12:04:22 -0400107 void startTimer();
108 void terminateCall();
109 Conference getDisplayedConference();
110 void updateDisplayedConference(Conference c);
Adrien Bérauddde513c2015-10-22 11:21:52 -0400111 ActionBar getSupportActionBar();
Adrien Béraudb179bab2015-10-08 12:04:22 -0400112 }
113
114 /**
Adrien Béraud04d822c2015-04-02 17:44:36 -0400115 * A dummy implementation of the {@link Callbacks} interface that does nothing. Used only when this fragment is not attached to an activity.
116 */
Adrien Béraudb179bab2015-10-08 12:04:22 -0400117 private static class DummyCallbacks extends LocalService.DummyCallbacks implements Callbacks {
Adrien Béraud04d822c2015-04-02 17:44:36 -0400118 @Override
Adrien Béraudb179bab2015-10-08 12:04:22 -0400119 public void terminateCall() {}
Adrien Béraud04d822c2015-04-02 17:44:36 -0400120 @Override
121 public Conference getDisplayedConference() {
122 return null;
123 }
Adrien Béraud04d822c2015-04-02 17:44:36 -0400124 @Override
Adrien Béraudb179bab2015-10-08 12:04:22 -0400125 public void updateDisplayedConference(Conference c) { }
Adrien Béraud04d822c2015-04-02 17:44:36 -0400126 @Override
Adrien Bérauddde513c2015-10-22 11:21:52 -0400127 public ActionBar getSupportActionBar() { return null; }
128 @Override
Adrien Béraudb179bab2015-10-08 12:04:22 -0400129 public void startTimer() { }
Adrien Béraud04d822c2015-04-02 17:44:36 -0400130 }
Adrien Béraudb179bab2015-10-08 12:04:22 -0400131 private static final Callbacks sDummyCallbacks = new DummyCallbacks();
Adrien Béraud04d822c2015-04-02 17:44:36 -0400132
133 @Override
134 public void onAttach(Activity activity) {
Adrien Béraudb179bab2015-10-08 12:04:22 -0400135 Log.i(TAG, "onAttach");
Adrien Béraud04d822c2015-04-02 17:44:36 -0400136 super.onAttach(activity);
137
138 if (!(activity instanceof Callbacks)) {
139 throw new IllegalStateException("Activity must implement fragment's callbacks.");
140 }
141
Adrien Béraud04d822c2015-04-02 17:44:36 -0400142 mCallbacks = (Callbacks) activity;
Adrien Béraud04d822c2015-04-02 17:44:36 -0400143 }
144
Adrien Béraudb179bab2015-10-08 12:04:22 -0400145 public void refreshState() {
146 Conference conf = getConference();
147 if (conf == null) {
148 contactBubbleView.setImageBitmap(null);
149 contactBubbleTxt.setText("");
150 acceptButton.setVisibility(View.GONE);
151 refuseButton.setVisibility(View.GONE);
152 hangupButton.setVisibility(View.GONE);
153 } else if (conf.getParticipants().size() == 1) {
154 SipCall call = conf.getParticipants().get(0);
155 if (call.isIncoming() && call.isRinging()) {
156 Log.w(TAG, "CallFragment refreshState INCOMING " + call.getCallId());
157 initIncomingCallDisplay();
158 } else if (conf.getParticipants().get(0).isRinging()) {
159 Log.w(TAG, "CallFragment refreshState RINGING " + call.getCallId());
160 initOutGoingCallDisplay();
161 } else if (call.isOngoing()) {
162 initNormalStateDisplay();
163 }
164 } else if (conf.getParticipants().size() > 1) {
165 initNormalStateDisplay();
166 }
167 }
168
Adrien Béraud04d822c2015-04-02 17:44:36 -0400169 @Override
170 public void onCreateOptionsMenu(Menu m, MenuInflater inf) {
Adrien Béraud04d822c2015-04-02 17:44:36 -0400171 inf.inflate(R.menu.ac_call, m);
Adrien Béraudda712a42015-11-22 23:45:26 -0500172 super.onCreateOptionsMenu(m, inf);
173 }
174
175 @Override
176 public void onPrepareOptionsMenu(Menu menu) {
177 super.onPrepareOptionsMenu(menu);
178 MenuItem it = menu.findItem(R.id.menuitem_speaker);
179 if (it != null) {
180 if (it.getIcon() != null)
181 it.getIcon().setAlpha(mSpeakerPhone ? 255 : 128);
182 it.setChecked(mSpeakerPhone);
183 }
Adrien Béraud04d822c2015-04-02 17:44:36 -0400184 }
185
186 @Override
187 public boolean onOptionsItemSelected(MenuItem item) {
188 super.onOptionsItemSelected(item);
189 switch (item.getItemId()) {
190 case R.id.menuitem_chat:
Adrien Béraudb179bab2015-10-08 12:04:22 -0400191 Intent intent = new Intent()
192 .setClass(getActivity(), ConversationActivity.class)
193 .setAction(Intent.ACTION_VIEW)
194 .setData(Uri.withAppendedPath(ConversationActivity.CONTENT_URI, getConference().getParticipants().get(0).getContact().getIds().get(0)));
195 intent.putExtra("resuming", true);
Adrien Béraudb179bab2015-10-08 12:04:22 -0400196 startActivityForResult(intent, HomeActivity.REQUEST_CODE_CONVERSATION);
Adrien Béraud04d822c2015-04-02 17:44:36 -0400197 break;
Adrien Béraudda712a42015-11-22 23:45:26 -0500198 case R.id.menuitem_addcontact:
199 break;
200 case R.id.menuitem_speaker:
201 mSpeakerPhone = !mSpeakerPhone;
202 //setActionBarCheckboxChecked(item, !item.isChecked());
203 try {
204 mCallbacks.getRemoteService().toggleSpeakerPhone(mSpeakerPhone);
205 } catch (RemoteException e) {
206 e.printStackTrace();
207 }
208 getActivity().invalidateOptionsMenu();
209 break;
Adrien Béraud04d822c2015-04-02 17:44:36 -0400210 }
211
212 return true;
213 }
214
215 @Override
216 public void onDetach() {
217 super.onDetach();
218 mCallbacks = sDummyCallbacks;
219 }
220
221 @Override
222 public void onStop() {
223 super.onStop();
224 }
225
226 @Override
227 public void onResume() {
Adrien Béraudda712a42015-11-22 23:45:26 -0500228 Log.w(TAG, "onResume()");
Adrien Béraud04d822c2015-04-02 17:44:36 -0400229 super.onResume();
Adrien Béraudda712a42015-11-22 23:45:26 -0500230 //initializeWiFiListener();
Adrien Béraudb179bab2015-10-08 12:04:22 -0400231 refreshState();
Adrien Béraudda712a42015-11-22 23:45:26 -0500232
233 Conference c = getConference();
234 if (c != null) {
235 c.mVisible = true;
236 NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getActivity());
237 notificationManager.cancel(c.notificationId);
238 }
Adrien Béraud04d822c2015-04-02 17:44:36 -0400239 }
240
241 @Override
242 public void onPause() {
Adrien Béraudda712a42015-11-22 23:45:26 -0500243 Log.w(TAG, "onPause()");
Adrien Béraud04d822c2015-04-02 17:44:36 -0400244 super.onPause();
Adrien Béraudda712a42015-11-22 23:45:26 -0500245 //getActivity().unregisterReceiver(wifiReceiver);
Adrien Béraud04d822c2015-04-02 17:44:36 -0400246 if (mScreenWakeLock != null && mScreenWakeLock.isHeld()) {
247 mScreenWakeLock.release();
248 }
Adrien Béraudda712a42015-11-22 23:45:26 -0500249 Conference c = getConference();
250 if (c != null) {
251 c.mVisible = false;
252 c.showCallNotification(getActivity());
253 }
254 }
255
256 public void confUpdate() {
257 LocalService service = mCallbacks.getService();
258 if (service == null)
259 return;
260
261 Conference c = service.getConference(getConference().getId());
262 mCallbacks.updateDisplayedConference(c);
263 if (c == null || c.getParticipants().isEmpty()) {
264 mCallbacks.terminateCall();
265 return;
266 }
267
268 String newState = c.getState();
269 if (c.isOnGoing()) {
270 initNormalStateDisplay();
271 } else if (c.isRinging()) {
272 mCallStatusTxt.setText(newState);
273
274 if (c.isIncoming()) {
275 initIncomingCallDisplay();
276 } else
277 initOutGoingCallDisplay();
278 } else {
279 NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getActivity());
280 notificationManager.cancel(c.notificationId);
281 mCallStatusTxt.setText(newState);
282 mCallbacks.terminateCall();
283 }
Adrien Béraud04d822c2015-04-02 17:44:36 -0400284 }
285
286 @Override
287 public void callStateChanged(Conference updated, String callID, String newState) {
Adrien Béraudb179bab2015-10-08 12:04:22 -0400288 Conference cur = getConference();
289 if (cur.getId().equals(callID) || cur.getCallById(callID) != null) {
290 mCallbacks.updateDisplayedConference(updated);
291 } else {
292 return;
293 }
294
Adrien Béraud04d822c2015-04-02 17:44:36 -0400295 Log.i(TAG, "Call :" + callID + " " + newState);
296
297 if (getConference().isOnGoing()) {
298 initNormalStateDisplay();
299 } else if (getConference().isRinging()) {
300 mCallStatusTxt.setText(newState);
301
302 if (getConference().isIncoming()) {
303 initIncomingCallDisplay();
304 } else
305 initOutGoingCallDisplay();
306 } else {
Adrien Béraudb179bab2015-10-08 12:04:22 -0400307 NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getActivity());
308 notificationManager.cancel(getConference().notificationId);
Adrien Béraud04d822c2015-04-02 17:44:36 -0400309 mCallStatusTxt.setText(newState);
310 mCallbacks.terminateCall();
311 }
312 }
313
314 @Override
315 public void secureZrtpOn(Conference updated, String id) {
316 Log.i(TAG, "secureZrtpOn");
317 mCallbacks.updateDisplayedConference(updated);
318 updateSecurityDisplay();
319 }
320
321 @Override
322 public void secureZrtpOff(Conference updated, String id) {
323 Log.i(TAG, "secureZrtpOff");
324 mCallbacks.updateDisplayedConference(updated);
325 updateSecurityDisplay();
326 }
327
328 @Override
329 public void displaySAS(Conference updated, final String securedCallID) {
330 Log.i(TAG, "displaySAS");
331 mCallbacks.updateDisplayedConference(updated);
332 updateSecurityDisplay();
333 }
334
335 @Override
336 public void zrtpNegotiationFailed(Conference c, String securedCallID) {
337 mCallbacks.updateDisplayedConference(c);
338 updateSecurityDisplay();
339 }
340
341 @Override
342 public void zrtpNotSupported(Conference c, String securedCallID) {
343 mCallbacks.updateDisplayedConference(c);
344 updateSecurityDisplay();
345 }
346
347 @Override
348 public void onActivityResult(int requestCode, int resultCode, Intent data) {
349 super.onActivityResult(requestCode, resultCode, data);
350 SipCall transfer;
351 if (requestCode == REQUEST_TRANSFER) {
352 switch (resultCode) {
353 case TransferDFragment.RESULT_TRANSFER_CONF:
354 Conference c = data.getParcelableExtra("target");
355 transfer = data.getParcelableExtra("transfer");
356 try {
357
Adrien Béraudb179bab2015-10-08 12:04:22 -0400358 mCallbacks.getRemoteService().attendedTransfer(transfer.getCallId(), c.getParticipants().get(0).getCallId());
Adrien Béraud04d822c2015-04-02 17:44:36 -0400359
360 } catch (RemoteException e) {
361 e.printStackTrace();
362 }
363 break;
364
365 case TransferDFragment.RESULT_TRANSFER_NUMBER:
366 String to = data.getStringExtra("to_number");
367 transfer = data.getParcelableExtra("transfer");
368 try {
Adrien Béraudb179bab2015-10-08 12:04:22 -0400369 mCallbacks.getRemoteService().transfer(transfer.getCallId(), to);
370 mCallbacks.getRemoteService().hangUp(transfer.getCallId());
Adrien Béraud04d822c2015-04-02 17:44:36 -0400371 } catch (RemoteException e) {
372 e.printStackTrace();
373 }
374 break;
375 case Activity.RESULT_CANCELED:
376 default:
Adrien Béraudb179bab2015-10-08 12:04:22 -0400377 /*synchronized (mBubbleModel) {
Adrien Béraud04d822c2015-04-02 17:44:36 -0400378 mBubbleModel.clear();
Adrien Béraudb179bab2015-10-08 12:04:22 -0400379 }*/
Adrien Béraud04d822c2015-04-02 17:44:36 -0400380 initNormalStateDisplay();
381 break;
382 }
383 }
384 }
385
386 @Override
387 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
388 Log.i(TAG, "onCreateView");
389 final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.frag_call, container, false);
390
Adrien Béraudb179bab2015-10-08 12:04:22 -0400391 contactBubbleView = (ImageView) rootView.findViewById(R.id.contact_bubble);
392 contactBubbleTxt = (TextView) rootView.findViewById(R.id.contact_bubble_txt);
393 acceptButton = rootView.findViewById(R.id.call_accept_btn);
394 refuseButton = rootView.findViewById(R.id.call_refuse_btn);
395 hangupButton = rootView.findViewById(R.id.call_hangup_btn);
Adrien Béraud04d822c2015-04-02 17:44:36 -0400396
397 mCallStatusTxt = (TextView) rootView.findViewById(R.id.call_status_txt);
398
399 mSecuritySwitch = (ViewSwitcher) rootView.findViewById(R.id.security_switcher);
Adrien Béraudda712a42015-11-22 23:45:26 -0500400 /*mToggleSpeakers = (ToggleButton) rootView.findViewById(R.id.speaker_toggle);
Adrien Béraud04d822c2015-04-02 17:44:36 -0400401
402 mToggleSpeakers.setOnCheckedChangeListener(new OnCheckedChangeListener() {
403
404 @Override
405 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
406 try {
Adrien Béraudb179bab2015-10-08 12:04:22 -0400407 mCallbacks.getRemoteService().toggleSpeakerPhone(isChecked);
Adrien Béraud04d822c2015-04-02 17:44:36 -0400408 } catch (RemoteException e) {
409 e.printStackTrace();
410 }
411
412 }
Adrien Béraudb179bab2015-10-08 12:04:22 -0400413 });*/
414
415 securityIndicator = rootView.findViewById(R.id.security_indicator);
Adrien Béraud04d822c2015-04-02 17:44:36 -0400416 return rootView;
417 }
418
419 public Conference getConference() {
420 return mCallbacks.getDisplayedConference();
421 }
422
423 private void initNormalStateDisplay() {
424 Log.i(TAG, "Start normal display");
Adrien Béraudb179bab2015-10-08 12:04:22 -0400425 mCallbacks.startTimer();
426 acceptButton.setVisibility(View.GONE);
427 refuseButton.setVisibility(View.GONE);
428
429 final SipCall call = getConference().getParticipants().get(0);
430 CallContact contact = call.getContact();
Adrien Béraudb179bab2015-10-08 12:04:22 -0400431 new ContactPictureTask(getActivity(), contactBubbleView, contact).run();
432 contactBubbleTxt.setText(contact.getDisplayName());
433
434 hangupButton.setVisibility(View.VISIBLE);
435 hangupButton.setOnClickListener(new OnClickListener() {
436 @Override
437 public void onClick(View v) {
438 try {
439 mCallbacks.getRemoteService().hangUp(call.getCallId());
440 mCallbacks.terminateCall();
441 } catch (RemoteException e) {
442 e.printStackTrace();
443 }
444 }
445 });
446
Adrien Bérauddde513c2015-10-22 11:21:52 -0400447 mCallbacks.getSupportActionBar().setTitle(contact.getDisplayName());
Adrien Béraud04d822c2015-04-02 17:44:36 -0400448 updateSecurityDisplay();
449 }
450
451 private void updateSecurityDisplay() {
Adrien Béraudda712a42015-11-22 23:45:26 -0500452 //First we check if all participants use a security layer.
453 boolean secure_call = !getConference().getParticipants().isEmpty();
Adrien Béraudb179bab2015-10-08 12:04:22 -0400454 for (SipCall c : getConference().getParticipants()) {
Adrien Béraudda712a42015-11-22 23:45:26 -0500455 //Account acc = mCallbacks.getService().getAccount(c.getAccount());
456 secure_call &= c instanceof SecureSipCall && ((SecureSipCall)c).isSecure();
Adrien Béraudb179bab2015-10-08 12:04:22 -0400457 }
458
459 securityIndicator.setVisibility(secure_call ? View.VISIBLE : View.GONE);
460 if (!secure_call)
Adrien Béraud04d822c2015-04-02 17:44:36 -0400461 return;
462
463 Log.i(TAG, "Enable security display");
464 if (getConference().hasMultipleParticipants()) {
465 //TODO What layout should we put?
466 } else {
467 final SecureSipCall secured = (SecureSipCall) getConference().getParticipants().get(0);
468 switch (secured.displayModule()) {
469 case SecureSipCall.DISPLAY_GREEN_LOCK:
470 Log.i(TAG, "DISPLAY_GREEN_LOCK");
471 showLock(R.drawable.green_lock);
472 break;
473 case SecureSipCall.DISPLAY_RED_LOCK:
474 Log.i(TAG, "DISPLAY_RED_LOCK");
475 showLock(R.drawable.red_lock);
476 break;
477 case SecureSipCall.DISPLAY_CONFIRM_SAS:
478 final Button sas = (Button) mSecuritySwitch.findViewById(R.id.confirm_sas);
479 Log.i(TAG, "Confirm SAS: " + secured.getSAS());
480 sas.setText("Confirm SAS: " + secured.getSAS());
481 sas.setOnClickListener(new View.OnClickListener() {
482 @Override
483 public void onClick(View v) {
484 try {
Adrien Béraudb179bab2015-10-08 12:04:22 -0400485 mCallbacks.getRemoteService().confirmSAS(secured.getCallId());
Adrien Béraud04d822c2015-04-02 17:44:36 -0400486 showLock(R.drawable.green_lock);
487 } catch (RemoteException e) {
488 e.printStackTrace();
489 }
490 }
491 });
492 mSecuritySwitch.setDisplayedChild(0);
493 mSecuritySwitch.setVisibility(View.VISIBLE);
494 break;
495 case SecureSipCall.DISPLAY_NONE:
496 break;
497 }
498 }
499 }
500
501 private void showLock(int resId) {
502 ImageView lock = (ImageView) mSecuritySwitch.findViewById(R.id.lock_image);
503 lock.setImageDrawable(getResources().getDrawable(resId));
504 mSecuritySwitch.setDisplayedChild(1);
505 mSecuritySwitch.setVisibility(View.VISIBLE);
506 }
507
Adrien Béraudb179bab2015-10-08 12:04:22 -0400508 protected Bitmap getContactPhoto(CallContact contact, int size) {
509 if (contact.getPhotoId() > 0) {
510 return ContactPictureTask.loadContactPhoto(getActivity().getContentResolver(), contact.getId());
511 } else {
512 return ContactPictureTask.decodeSampledBitmapFromResource(getResources(), R.drawable.ic_contact_picture, size, size);
513 }
514 }
515
Adrien Béraud04d822c2015-04-02 17:44:36 -0400516 private void initIncomingCallDisplay() {
517 Log.i(TAG, "Start incoming display");
Adrien Béraudb179bab2015-10-08 12:04:22 -0400518 if (mCallbacks.getService().getAccount(getConference().getParticipants().get(0).getAccount()).isAutoanswerEnabled()) {
Adrien Béraud04d822c2015-04-02 17:44:36 -0400519 try {
Adrien Béraudb179bab2015-10-08 12:04:22 -0400520 mCallbacks.getRemoteService().accept(getConference().getParticipants().get(0).getCallId());
Adrien Béraud04d822c2015-04-02 17:44:36 -0400521 } catch (RemoteException e) {
522 e.printStackTrace();
523 } catch (NullPointerException e) {
524 e.printStackTrace();
525 }
526 } else {
Adrien Béraudb179bab2015-10-08 12:04:22 -0400527 final SipCall call = getConference().getParticipants().get(0);
528 CallContact contact = call.getContact();
Adrien Béraudb179bab2015-10-08 12:04:22 -0400529 new ContactPictureTask(getActivity(), contactBubbleView, contact).run();
530 contactBubbleTxt.setText(contact.getDisplayName());
531 acceptButton.setVisibility(View.VISIBLE);
532 acceptButton.setOnClickListener(new OnClickListener() {
533 @Override
534 public void onClick(View v) {
535 acceptButton.setOnClickListener(null);
536 refuseButton.setOnClickListener(null);
537 try {
538 mCallbacks.getRemoteService().accept(call.getCallId());
539 } catch (RemoteException e) {
540 e.printStackTrace();
541 }
542 }
543 });
544 refuseButton.setVisibility(View.VISIBLE);
545 refuseButton.setOnClickListener(new OnClickListener() {
546 @Override
547 public void onClick(View v) {
548 acceptButton.setOnClickListener(null);
549 refuseButton.setOnClickListener(null);
550 try {
551 mCallbacks.getRemoteService().refuse(call.getCallId());
552 mCallbacks.terminateCall();
553 } catch (RemoteException e) {
554 e.printStackTrace();
555 }
556 }
557 });
558 hangupButton.setVisibility(View.GONE);
Adrien Bérauddde513c2015-10-22 11:21:52 -0400559 mCallbacks.getSupportActionBar().setTitle(contact.getDisplayName());
Adrien Béraud04d822c2015-04-02 17:44:36 -0400560 }
561 }
562
563 private void initOutGoingCallDisplay() {
564 Log.i(TAG, "Start outgoing display");
Adrien Béraudb179bab2015-10-08 12:04:22 -0400565
566 final SipCall call = getConference().getParticipants().get(0);
567 CallContact contact = call.getContact();
Adrien Béraudb179bab2015-10-08 12:04:22 -0400568 new ContactPictureTask(getActivity(), contactBubbleView, contact).run();
569 contactBubbleTxt.setText(contact.getDisplayName());
570
571 acceptButton.setVisibility(View.GONE);
572 refuseButton.setVisibility(View.GONE);
573
574 hangupButton.setVisibility(View.VISIBLE);
575 hangupButton.setOnClickListener(new OnClickListener() {
576 @Override
577 public void onClick(View v) {
578 try {
579 mCallbacks.getRemoteService().hangUp(call.getCallId());
580 mCallbacks.terminateCall();
581 } catch (RemoteException e) {
582 e.printStackTrace();
583 }
584 }
585 });
586
Adrien Bérauddde513c2015-10-22 11:21:52 -0400587 mCallbacks.getSupportActionBar().setTitle(contact.getDisplayName());
Adrien Béraud04d822c2015-04-02 17:44:36 -0400588 }
Adrien Béraudda712a42015-11-22 23:45:26 -0500589
Adrien Béraudb179bab2015-10-08 12:04:22 -0400590 /*
Adrien Béraud04d822c2015-04-02 17:44:36 -0400591 public void makeTransfer(BubbleContact contact) {
592 FragmentManager fm = getFragmentManager();
593 editName = TransferDFragment.newInstance();
594 Bundle b = new Bundle();
595 try {
Adrien Béraudb179bab2015-10-08 12:04:22 -0400596 b.putParcelableArrayList("calls", (ArrayList<Conference>) mCallbacks.getRemoteService().getConcurrentCalls());
Adrien Béraud04d822c2015-04-02 17:44:36 -0400597 b.putParcelable("call_selected", contact.associated_call);
598 editName.setArguments(b);
599 editName.setTargetFragment(this, REQUEST_TRANSFER);
600 editName.show(fm, "");
601 } catch (RemoteException e) {
602 Log.e(TAG, e.toString());
603 }
604
Adrien Béraudda712a42015-11-22 23:45:26 -0500605 }*/
Adrien Béraud4c6d29b2015-11-19 18:10:35 -0500606
Adrien Béraud04d822c2015-04-02 17:44:36 -0400607 public void updateTime() {
Adrien Béraudda712a42015-11-22 23:45:26 -0500608 if (getConference() != null && !getConference().getParticipants().isEmpty()) {
Adrien Béraudb179bab2015-10-08 12:04:22 -0400609 long duration = System.currentTimeMillis() - getConference().getParticipants().get(0).getTimestampStart();
Adrien Béraud04d822c2015-04-02 17:44:36 -0400610 duration = duration / 1000;
611 if (getConference().isOnGoing())
612 mCallStatusTxt.setText(String.format("%d:%02d:%02d", duration / 3600, duration % 3600 / 60, duration % 60));
613 }
614
615 }
616
617 public void onKeyUp(int keyCode, KeyEvent event) {
618 try {
619
620 switch (keyCode) {
621 case KeyEvent.KEYCODE_VOLUME_DOWN:
622 case KeyEvent.KEYCODE_VOLUME_UP:
623 break;
624 default:
625 String toSend = Character.toString(event.getDisplayLabel());
626 toSend = toSend.toUpperCase(Locale.getDefault());
627 Log.d(TAG, "toSend " + toSend);
Adrien Béraudb179bab2015-10-08 12:04:22 -0400628 mCallbacks.getRemoteService().playDtmf(toSend);
Adrien Béraud04d822c2015-04-02 17:44:36 -0400629 break;
630 }
631 } catch (RemoteException e) {
632 e.printStackTrace();
633 } catch (NullPointerException e) {
634 e.printStackTrace();
635 }
636 }
637}