Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 1 | /* |
Adrien Béraud | ec528bb | 2016-01-14 16:52:51 -0500 | [diff] [blame] | 2 | * Copyright (C) 2004-2016 Savoir-faire Linux Inc. |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 3 | * |
| 4 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 5 | * Author: Adrien Béraud <adrien.beraud@savoirfairelinux.com> |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 6 | * |
| 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éraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | package cx.ring.fragments; |
| 23 | |
| 24 | import android.app.Activity; |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 25 | import android.app.Fragment; |
| 26 | import android.content.BroadcastReceiver; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 27 | import android.content.Context; |
| 28 | import android.content.Intent; |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 29 | import android.content.IntentFilter; |
| 30 | import android.content.res.Configuration; |
| 31 | import android.graphics.PixelFormat; |
Adrien Béraud | 8d6a483 | 2016-04-12 18:06:11 -0400 | [diff] [blame] | 32 | import android.hardware.display.DisplayManager; |
Adrien Béraud | fdff91d | 2015-12-09 17:54:16 -0500 | [diff] [blame] | 33 | import android.media.AudioManager; |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 34 | import android.net.Uri; |
Adrien Béraud | 8d6a483 | 2016-04-12 18:06:11 -0400 | [diff] [blame] | 35 | import android.os.Build; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 36 | import android.os.Bundle; |
| 37 | import android.os.PowerManager; |
| 38 | import android.os.PowerManager.WakeLock; |
| 39 | import android.os.RemoteException; |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 40 | import android.support.annotation.Nullable; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 41 | import android.support.v4.app.NotificationManagerCompat; |
Romain Bertozzi | 64a6678 | 2016-08-02 12:10:38 -0400 | [diff] [blame^] | 42 | import android.support.v4.content.res.ResourcesCompat; |
Adrien Béraud | dde513c | 2015-10-22 11:21:52 -0400 | [diff] [blame] | 43 | import android.support.v7.app.ActionBar; |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 44 | import android.text.Editable; |
Romain Bertozzi | 64a6678 | 2016-08-02 12:10:38 -0400 | [diff] [blame^] | 45 | import android.text.TextUtils; |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 46 | import android.text.TextWatcher; |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 47 | import android.util.DisplayMetrics; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 48 | import android.util.Log; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 49 | import android.view.LayoutInflater; |
| 50 | import android.view.Menu; |
| 51 | import android.view.MenuInflater; |
| 52 | import android.view.MenuItem; |
| 53 | import android.view.SurfaceHolder; |
| 54 | import android.view.SurfaceView; |
| 55 | import android.view.View; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 56 | import android.view.ViewGroup; |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 57 | import android.view.inputmethod.InputMethodManager; |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 58 | import android.widget.EditText; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 59 | import android.widget.FrameLayout; |
| 60 | import android.widget.ImageView; |
| 61 | import android.widget.RelativeLayout; |
| 62 | import android.widget.TextView; |
| 63 | import android.widget.ViewSwitcher; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 64 | |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 65 | import com.skyfishjy.library.RippleBackground; |
| 66 | |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 67 | import java.lang.ref.WeakReference; |
| 68 | import java.util.HashMap; |
Romain Bertozzi | 64a6678 | 2016-08-02 12:10:38 -0400 | [diff] [blame^] | 69 | import java.util.Locale; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 70 | |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 71 | import butterknife.BindView; |
| 72 | import butterknife.ButterKnife; |
| 73 | import butterknife.OnClick; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 74 | import cx.ring.R; |
| 75 | import cx.ring.adapters.ContactPictureTask; |
| 76 | import cx.ring.client.ConversationActivity; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 77 | import cx.ring.interfaces.CallInterface; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 78 | import cx.ring.model.CallContact; |
| 79 | import cx.ring.model.Conference; |
| 80 | import cx.ring.model.SecureSipCall; |
| 81 | import cx.ring.model.SipCall; |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 82 | import cx.ring.service.CallManagerCallBack; |
| 83 | import cx.ring.service.DRingService; |
| 84 | import cx.ring.service.IDRingService; |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 85 | import cx.ring.service.LocalService; |
Romain Bertozzi | 64a6678 | 2016-08-02 12:10:38 -0400 | [diff] [blame^] | 86 | import cx.ring.utils.CropImageUtils; |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 87 | import cx.ring.utils.KeyboardVisibilityManager; |
Romain Bertozzi | 64a6678 | 2016-08-02 12:10:38 -0400 | [diff] [blame^] | 88 | import cx.ring.utils.VCardUtils; |
| 89 | import ezvcard.VCard; |
| 90 | import ezvcard.property.Photo; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 91 | |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 92 | public class CallFragment extends Fragment implements CallInterface { |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 93 | |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 94 | static final private String TAG = CallFragment.class.getSimpleName(); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 95 | |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 96 | public static final int REQUEST_TRANSFER = 10; |
| 97 | |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 98 | //~ Regular expression to match DTMF supported characters : 0 to 9, A, B, C, D, * and # |
| 99 | public static final String DTMF_SUPPORTED_CHARS_REGEX = "^[a-dA-D0-9#*]*$"; |
| 100 | |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 101 | // Screen wake lock for incoming call |
| 102 | private WakeLock mScreenWakeLock; |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 103 | |
| 104 | @BindView(R.id.contact_bubble_layout) |
| 105 | View contactBubbleLayout; |
| 106 | |
| 107 | @BindView(R.id.contact_bubble) |
| 108 | ImageView contactBubbleView; |
| 109 | |
| 110 | @BindView(R.id.contact_bubble_txt) |
| 111 | TextView contactBubbleTxt; |
| 112 | |
| 113 | @BindView(R.id.contact_bubble_num_txt) |
| 114 | TextView contactBubbleNumTxt; |
| 115 | |
| 116 | @BindView(R.id.call_accept_btn) |
| 117 | View acceptButton; |
| 118 | |
| 119 | @BindView(R.id.call_refuse_btn) |
| 120 | View refuseButton; |
| 121 | |
| 122 | @BindView(R.id.call_hangup_btn) |
| 123 | View hangupButton; |
| 124 | |
| 125 | @BindView(R.id.call_status_txt) |
| 126 | TextView mCallStatusTxt; |
| 127 | |
| 128 | @BindView(R.id.security_indicator) |
| 129 | View securityIndicator; |
| 130 | |
| 131 | @BindView(R.id.security_switcher) |
| 132 | ViewSwitcher mSecuritySwitch; |
| 133 | |
| 134 | @BindView(R.id.dialpad_edit_text) |
| 135 | EditText mNumeralDialEditText; |
| 136 | |
| 137 | @BindView(R.id.ripple_animation) |
| 138 | RippleBackground mPulseAnimation; |
| 139 | |
| 140 | @BindView(R.id.video_preview_surface) |
| 141 | SurfaceView mVideoSurface = null; |
| 142 | |
Adrien Béraud | da2eb1a | 2016-01-11 13:15:12 -0500 | [diff] [blame] | 143 | private MenuItem speakerPhoneBtn = null; |
| 144 | private MenuItem addContactBtn = null; |
Adrien Béraud | f54c4ef | 2016-03-14 14:41:47 -0400 | [diff] [blame] | 145 | private MenuItem flipCameraBtn = null; |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 146 | private MenuItem dialPadBtn = null; |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 147 | |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 148 | @BindView(R.id.camera_preview_surface) |
| 149 | SurfaceView videoPreview = null; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 150 | |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 151 | public ConversationCallbacks mCallbacks = sDummyCallbacks; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 152 | |
Adrien Béraud | fdff91d | 2015-12-09 17:54:16 -0500 | [diff] [blame] | 153 | private AudioManager audioManager; |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 154 | private boolean haveVideo = false; |
| 155 | private int videoWidth = -1, videoHeight = -1; |
| 156 | private int previewWidth = -1, previewHeight = -1; |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 157 | |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 158 | private boolean lastVideoSource = true; |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 159 | private Conference mCachedConference = null; |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 160 | |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 161 | private boolean ongoingCall = false; |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 162 | |
Adrien Béraud | 8d6a483 | 2016-04-12 18:06:11 -0400 | [diff] [blame] | 163 | private DisplayManager.DisplayListener displayListener; |
| 164 | |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 165 | @Override |
| 166 | public void onAttach(Activity activity) { |
| 167 | Log.i(TAG, "onAttach"); |
| 168 | super.onAttach(activity); |
| 169 | |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 170 | if (!(activity instanceof ConversationCallbacks)) { |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 171 | throw new IllegalStateException("Activity must implement fragment's callbacks."); |
| 172 | } |
| 173 | |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 174 | mCallbacks = (ConversationCallbacks) activity; |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 175 | |
| 176 | IntentFilter intentFilter = new IntentFilter(); |
| 177 | intentFilter.addAction(CallManagerCallBack.RECORD_STATE_CHANGED); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 178 | intentFilter.addAction(CallManagerCallBack.RTCP_REPORT_RECEIVED); |
Romain Bertozzi | 64a6678 | 2016-08-02 12:10:38 -0400 | [diff] [blame^] | 179 | intentFilter.addAction(CallManagerCallBack.VCARD_COMPLETED); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 180 | |
| 181 | intentFilter.addAction(DRingService.VIDEO_EVENT); |
| 182 | |
| 183 | intentFilter.addAction(LocalService.ACTION_CONF_UPDATE); |
| 184 | |
| 185 | getActivity().registerReceiver(mReceiver, intentFilter); |
| 186 | } |
| 187 | |
| 188 | @Override |
| 189 | public void onDetach() { |
| 190 | Log.i(TAG, "onDetach"); |
| 191 | getActivity().unregisterReceiver(mReceiver); |
| 192 | mCallbacks = sDummyCallbacks; |
| 193 | super.onDetach(); |
| 194 | } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 195 | |
| 196 | @Override |
| 197 | public void onCreate(Bundle savedBundle) { |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 198 | Log.i(TAG, "onCreate"); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 199 | super.onCreate(savedBundle); |
| 200 | |
Adrien Béraud | fdff91d | 2015-12-09 17:54:16 -0500 | [diff] [blame] | 201 | audioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 202 | |
| 203 | setHasOptionsMenu(true); |
| 204 | PowerManager powerManager = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE); |
Adrien Béraud | 8d6a483 | 2016-04-12 18:06:11 -0400 | [diff] [blame] | 205 | mScreenWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "cx.ring.onIncomingCall"); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 206 | mScreenWakeLock.setReferenceCounted(false); |
| 207 | |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 208 | if (mScreenWakeLock != null && !mScreenWakeLock.isHeld()) { |
| 209 | mScreenWakeLock.acquire(); |
| 210 | } |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 211 | |
Adrien Béraud | 8d6a483 | 2016-04-12 18:06:11 -0400 | [diff] [blame] | 212 | if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { |
| 213 | displayListener = new DisplayManager.DisplayListener() { |
| 214 | @Override |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 215 | public void onDisplayAdded(int displayId) { |
| 216 | } |
Adrien Béraud | 8d6a483 | 2016-04-12 18:06:11 -0400 | [diff] [blame] | 217 | |
| 218 | @Override |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 219 | public void onDisplayRemoved(int displayId) { |
| 220 | } |
Adrien Béraud | 8d6a483 | 2016-04-12 18:06:11 -0400 | [diff] [blame] | 221 | |
| 222 | @Override |
| 223 | public void onDisplayChanged(int displayId) { |
| 224 | getActivity().runOnUiThread(new Runnable() { |
| 225 | @Override |
| 226 | public void run() { |
| 227 | try { |
| 228 | mCallbacks.getRemoteService().switchInput(getConference().getId(), lastVideoSource); |
| 229 | } catch (RemoteException e) { |
| 230 | e.printStackTrace(); |
| 231 | } |
| 232 | } |
| 233 | }); |
| 234 | } |
| 235 | }; |
| 236 | } |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | @Override |
| 240 | public void onDestroy() { |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 241 | super.onDestroy(); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 242 | Log.i(TAG, "onDestroy"); |
| 243 | if (mScreenWakeLock != null && mScreenWakeLock.isHeld()) { |
| 244 | mScreenWakeLock.release(); |
| 245 | } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | /** |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 249 | * The Activity calling this fragment has to implement this interface |
| 250 | */ |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 251 | public interface ConversationCallbacks extends LocalService.Callbacks { |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 252 | void startTimer(); |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 253 | |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 254 | void terminateCall(); |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 255 | |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 256 | Conference getDisplayedConference(); |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 257 | |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 258 | void updateDisplayedConference(Conference c); |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 259 | |
Adrien Béraud | dde513c | 2015-10-22 11:21:52 -0400 | [diff] [blame] | 260 | ActionBar getSupportActionBar(); |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 261 | } |
| 262 | |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 263 | private static final ConversationCallbacks sDummyCallbacks = new ConversationCallbacks() { |
| 264 | @Override |
| 265 | public void startTimer() { |
| 266 | //Dummy implementation |
| 267 | } |
| 268 | |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 269 | @Override |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 270 | public void terminateCall() { |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 271 | //Dummy implementation |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 272 | } |
| 273 | |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 274 | @Override |
| 275 | public Conference getDisplayedConference() { |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 276 | //Dummy implementation |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 277 | return null; |
| 278 | } |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 279 | |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 280 | @Override |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 281 | public void updateDisplayedConference(Conference c) { |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 282 | //Dummy implementation |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 283 | } |
| 284 | |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 285 | @Override |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 286 | public ActionBar getSupportActionBar() { |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 287 | //Dummy implementation |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 288 | return null; |
| 289 | } |
| 290 | |
Adrien Béraud | dde513c | 2015-10-22 11:21:52 -0400 | [diff] [blame] | 291 | @Override |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 292 | public IDRingService getRemoteService() { |
| 293 | //Dummy implementation |
| 294 | return null; |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 295 | } |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 296 | |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 297 | @Override |
| 298 | public LocalService getService() { |
| 299 | //Dummy implementation |
| 300 | return null; |
| 301 | } |
| 302 | }; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 303 | |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 304 | public class CallReceiver extends BroadcastReceiver { |
| 305 | private final String TAG = CallReceiver.class.getSimpleName(); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 306 | |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 307 | @Override |
| 308 | public void onReceive(Context context, Intent intent) { |
| 309 | String action = intent.getAction(); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 310 | if (action.contentEquals(LocalService.ACTION_CONF_UPDATE)) { |
| 311 | confUpdate(); |
| 312 | } else if (action.contentEquals(DRingService.VIDEO_EVENT)) { |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 313 | if (mVideoSurface == null) |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 314 | return; |
| 315 | Conference conf = getConference(); |
| 316 | if (intent.hasExtra("start")) { |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 317 | mVideoSurface.setVisibility(View.VISIBLE); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 318 | videoPreview.setVisibility(View.VISIBLE); |
| 319 | } else if (intent.hasExtra("camera")) { |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 320 | previewWidth = intent.getIntExtra("width", 0); |
| 321 | previewHeight = intent.getIntExtra("height", 0); |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 322 | } else if (conf != null && conf.getId().equals(intent.getStringExtra("call"))) { |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 323 | if (mVideoSurface != null) { |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 324 | haveVideo = intent.getBooleanExtra("started", false); |
| 325 | if (haveVideo) { |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 326 | mVideoSurface.setVisibility(View.VISIBLE); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 327 | videoPreview.setVisibility(View.VISIBLE); |
| 328 | videoWidth = intent.getIntExtra("width", 0); |
| 329 | videoHeight = intent.getIntExtra("height", 0); |
| 330 | } else { |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 331 | mVideoSurface.setVisibility(View.GONE); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 332 | videoPreview.setVisibility(View.GONE); |
| 333 | } |
| 334 | } |
| 335 | refreshState(); |
| 336 | } |
| 337 | resetVideoSizes(); |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 338 | } else if (action.contentEquals(CallManagerCallBack.RECORD_STATE_CHANGED)) { |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 339 | recordingChanged((Conference) intent.getParcelableExtra("conference"), intent.getStringExtra("call"), intent.getStringExtra("file")); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 340 | } else if (action.contentEquals(CallManagerCallBack.RTCP_REPORT_RECEIVED)) { |
| 341 | rtcpReportReceived(null, null); // FIXME |
Romain Bertozzi | 64a6678 | 2016-08-02 12:10:38 -0400 | [diff] [blame^] | 342 | } else if (action.contentEquals(CallManagerCallBack.VCARD_COMPLETED)) { |
| 343 | updateContactBubble(); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 344 | } else { |
| 345 | Log.e(TAG, "Unknown action: " + intent.getAction()); |
| 346 | } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 347 | } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 348 | } |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 349 | |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 350 | private final CallReceiver mReceiver = new CallReceiver(); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 351 | |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 352 | public void refreshState() { |
| 353 | Conference conf = getConference(); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 354 | |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 355 | if (conf == null) { |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 356 | contactBubbleView.setImageBitmap(null); |
| 357 | contactBubbleTxt.setText(""); |
Adrien Béraud | 6c4cedb | 2015-12-11 14:34:20 -0500 | [diff] [blame] | 358 | contactBubbleNumTxt.setText(""); |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 359 | acceptButton.setVisibility(View.GONE); |
| 360 | refuseButton.setVisibility(View.GONE); |
| 361 | hangupButton.setVisibility(View.GONE); |
| 362 | } else if (conf.getParticipants().size() == 1) { |
| 363 | SipCall call = conf.getParticipants().get(0); |
| 364 | if (call.isIncoming() && call.isRinging()) { |
| 365 | Log.w(TAG, "CallFragment refreshState INCOMING " + call.getCallId()); |
| 366 | initIncomingCallDisplay(); |
| 367 | } else if (conf.getParticipants().get(0).isRinging()) { |
| 368 | Log.w(TAG, "CallFragment refreshState RINGING " + call.getCallId()); |
| 369 | initOutGoingCallDisplay(); |
| 370 | } else if (call.isOngoing()) { |
| 371 | initNormalStateDisplay(); |
| 372 | } |
| 373 | } else if (conf.getParticipants().size() > 1) { |
| 374 | initNormalStateDisplay(); |
| 375 | } |
Adrien Béraud | 329aee7 | 2016-03-14 14:40:14 -0400 | [diff] [blame] | 376 | |
| 377 | getActivity().invalidateOptionsMenu(); |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 378 | } |
| 379 | |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 380 | @Override |
| 381 | public void onCreateOptionsMenu(Menu m, MenuInflater inf) { |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 382 | super.onCreateOptionsMenu(m, inf); |
Adrien Béraud | da2eb1a | 2016-01-11 13:15:12 -0500 | [diff] [blame] | 383 | inf.inflate(R.menu.ac_call, m); |
| 384 | speakerPhoneBtn = m.findItem(R.id.menuitem_speaker); |
| 385 | addContactBtn = m.findItem(R.id.menuitem_addcontact); |
Adrien Béraud | f54c4ef | 2016-03-14 14:41:47 -0400 | [diff] [blame] | 386 | flipCameraBtn = m.findItem(R.id.menuitem_camera_flip); |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 387 | dialPadBtn = m.findItem(R.id.menuitem_dialpad); |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | @Override |
| 391 | public void onPrepareOptionsMenu(Menu menu) { |
| 392 | super.onPrepareOptionsMenu(menu); |
Adrien Béraud | da2eb1a | 2016-01-11 13:15:12 -0500 | [diff] [blame] | 393 | if (speakerPhoneBtn != null) { |
Adrien Béraud | fdff91d | 2015-12-09 17:54:16 -0500 | [diff] [blame] | 394 | boolean speakerPhone = audioManager.isSpeakerphoneOn(); |
Adrien Béraud | da2eb1a | 2016-01-11 13:15:12 -0500 | [diff] [blame] | 395 | if (speakerPhoneBtn.getIcon() != null) |
| 396 | speakerPhoneBtn.getIcon().setAlpha(speakerPhone ? 255 : 128); |
| 397 | speakerPhoneBtn.setChecked(speakerPhone); |
| 398 | } |
| 399 | if (addContactBtn != null) { |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 400 | SipCall call = (getConference() != null && !getConference().getParticipants().isEmpty()) ? getFirstParticipant() : null; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 401 | addContactBtn.setVisible(call != null && null != call.getContact() && call.getContact().isUnknown()); |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 402 | } |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 403 | |
Adrien Béraud | f54c4ef | 2016-03-14 14:41:47 -0400 | [diff] [blame] | 404 | flipCameraBtn.setVisible(haveVideo); |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 405 | |
| 406 | if (dialPadBtn != null) { |
| 407 | dialPadBtn.setVisible(ongoingCall && getConference() != null && !getConference().isIncoming()); |
| 408 | } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | @Override |
| 412 | public boolean onOptionsItemSelected(MenuItem item) { |
| 413 | super.onOptionsItemSelected(item); |
| 414 | switch (item.getItemId()) { |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 415 | case android.R.id.home: |
| 416 | mCallbacks.terminateCall(); |
| 417 | break; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 418 | case R.id.menuitem_chat: |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 419 | Intent intent = new Intent() |
| 420 | .setClass(getActivity(), ConversationActivity.class) |
| 421 | .setAction(Intent.ACTION_VIEW) |
Alexandre Lision | 57314dd | 2016-09-17 01:44:37 -0400 | [diff] [blame] | 422 | .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP) |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 423 | .setData(Uri.withAppendedPath(ConversationActivity.CONTENT_URI, getFirstParticipant().getContact().getIds().get(0))); |
Alexandre Lision | 57314dd | 2016-09-17 01:44:37 -0400 | [diff] [blame] | 424 | startActivity(intent); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 425 | break; |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 426 | case R.id.menuitem_addcontact: |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 427 | startActivityForResult(getFirstParticipant().getContact().getAddNumberIntent(), ConversationActivity.REQ_ADD_CONTACT); |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 428 | break; |
| 429 | case R.id.menuitem_speaker: |
Adrien Béraud | fdff91d | 2015-12-09 17:54:16 -0500 | [diff] [blame] | 430 | audioManager.setSpeakerphoneOn(!audioManager.isSpeakerphoneOn()); |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 431 | getActivity().invalidateOptionsMenu(); |
| 432 | break; |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 433 | case R.id.menuitem_camera_flip: |
| 434 | lastVideoSource = !lastVideoSource; |
| 435 | try { |
| 436 | mCallbacks.getRemoteService().switchInput(getConference().getId(), lastVideoSource); |
| 437 | } catch (RemoteException e) { |
| 438 | e.printStackTrace(); |
| 439 | } |
| 440 | item.setIcon(lastVideoSource ? R.drawable.ic_camera_front_white_24dp : R.drawable.ic_camera_rear_white_24dp); |
| 441 | break; |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 442 | case R.id.menuitem_dialpad: |
| 443 | KeyboardVisibilityManager.showKeyboard(getActivity(), |
| 444 | mNumeralDialEditText, |
| 445 | InputMethodManager.SHOW_IMPLICIT); |
| 446 | break; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 447 | } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 448 | return true; |
| 449 | } |
| 450 | |
| 451 | @Override |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 452 | public void onStop() { |
Adrien Béraud | 8d6a483 | 2016-04-12 18:06:11 -0400 | [diff] [blame] | 453 | super.onStop(); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 454 | |
| 455 | Conference c = getConference(); |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 456 | Log.w(TAG, "onStop() haveVideo=" + haveVideo); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 457 | |
Adrien Béraud | 8d6a483 | 2016-04-12 18:06:11 -0400 | [diff] [blame] | 458 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { |
| 459 | DisplayManager displayManager = (DisplayManager) getActivity().getSystemService(Context.DISPLAY_SERVICE); |
| 460 | displayManager.unregisterDisplayListener(displayListener); |
| 461 | } |
| 462 | |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 463 | DRingService.videoSurfaces.remove(c.getId()); |
| 464 | DRingService.mCameraPreviewSurface.clear(); |
| 465 | try { |
| 466 | IDRingService service = mCallbacks.getRemoteService(); |
| 467 | if (service != null) { |
| 468 | service.videoSurfaceRemoved(c.getId()); |
| 469 | service.videoPreviewSurfaceRemoved(); |
| 470 | } |
| 471 | } catch (RemoteException e) { |
| 472 | e.printStackTrace(); |
| 473 | } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | @Override |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 477 | public void onStart() { |
| 478 | super.onStart(); |
Adrien Béraud | 8d6a483 | 2016-04-12 18:06:11 -0400 | [diff] [blame] | 479 | |
| 480 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { |
| 481 | DisplayManager displayManager = (DisplayManager) getActivity().getSystemService(Context.DISPLAY_SERVICE); |
| 482 | displayManager.registerDisplayListener(displayListener, null); |
| 483 | } |
| 484 | |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 485 | Conference c = getConference(); |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 486 | if (c != null && mVideoSurface != null && c.resumeVideo) { |
| 487 | Log.i(TAG, "Resuming video"); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 488 | haveVideo = true; |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 489 | mVideoSurface.setVisibility(View.VISIBLE); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 490 | videoPreview.setVisibility(View.VISIBLE); |
| 491 | c.resumeVideo = false; |
| 492 | } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | @Override |
| 496 | public void onResume() { |
| 497 | super.onResume(); |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 498 | Log.i(TAG, "onResume()"); |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 499 | Conference c = getConference(); |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 500 | |
| 501 | this.confUpdate(); |
| 502 | |
| 503 | if (getActivity() != null) { |
| 504 | getActivity().invalidateOptionsMenu(); |
| 505 | } |
| 506 | |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 507 | if (c != null) { |
| 508 | c.mVisible = true; |
| 509 | NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getActivity()); |
| 510 | notificationManager.cancel(c.notificationId); |
Adrien Béraud | ecaa205 | 2016-03-22 17:23:44 -0400 | [diff] [blame] | 511 | if (c.resumeVideo) { |
| 512 | Log.w(TAG, "Resuming video"); |
| 513 | haveVideo = true; |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 514 | mVideoSurface.setVisibility(View.VISIBLE); |
Adrien Béraud | ecaa205 | 2016-03-22 17:23:44 -0400 | [diff] [blame] | 515 | videoPreview.setVisibility(View.VISIBLE); |
| 516 | c.resumeVideo = false; |
| 517 | } |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 518 | } |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 519 | |
| 520 | refreshState(); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | @Override |
| 524 | public void onPause() { |
Adrien Béraud | ecaa205 | 2016-03-22 17:23:44 -0400 | [diff] [blame] | 525 | Log.w(TAG, "onPause() haveVideo=" + haveVideo); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 526 | super.onPause(); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 527 | |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 528 | Conference c = getConference(); |
| 529 | if (c != null) { |
| 530 | c.mVisible = false; |
Adrien Béraud | ecaa205 | 2016-03-22 17:23:44 -0400 | [diff] [blame] | 531 | c.resumeVideo = haveVideo; |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 532 | c.showCallNotification(getActivity()); |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | public void confUpdate() { |
Adrien Béraud | da2eb1a | 2016-01-11 13:15:12 -0500 | [diff] [blame] | 537 | Log.w(TAG, "confUpdate()"); |
| 538 | |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 539 | LocalService service = mCallbacks.getService(); |
| 540 | if (service == null) |
| 541 | return; |
| 542 | |
| 543 | Conference c = service.getConference(getConference().getId()); |
| 544 | mCallbacks.updateDisplayedConference(c); |
| 545 | if (c == null || c.getParticipants().isEmpty()) { |
| 546 | mCallbacks.terminateCall(); |
| 547 | return; |
| 548 | } |
| 549 | |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 550 | int newState = c.getHumanState(); |
| 551 | String newStateString = (newState == R.string.call_human_state_none || |
| 552 | newState == R.string.conference_human_state_default) |
| 553 | ? "" : |
| 554 | getString(newState); |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 555 | if (c.isOnGoing()) { |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 556 | ongoingCall = true; |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 557 | initNormalStateDisplay(); |
| 558 | } else if (c.isRinging()) { |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 559 | ongoingCall = false; |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 560 | mCallStatusTxt.setText(newStateString); |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 561 | |
| 562 | if (c.isIncoming()) { |
| 563 | initIncomingCallDisplay(); |
| 564 | } else |
| 565 | initOutGoingCallDisplay(); |
| 566 | } else { |
| 567 | NotificationManagerCompat notificationManager = NotificationManagerCompat.from(getActivity()); |
| 568 | notificationManager.cancel(c.notificationId); |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 569 | mCallStatusTxt.setText(newStateString); |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 570 | mCallbacks.terminateCall(); |
| 571 | } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | @Override |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 575 | public void recordingChanged(Conference c, String callID, String filename) { |
| 576 | |
| 577 | } |
| 578 | |
| 579 | @Override |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 580 | public void rtcpReportReceived(Conference c, HashMap<String, Integer> stats) { |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 581 | // No implementation yet |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | @Override |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 585 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 586 | super.onActivityResult(requestCode, resultCode, data); |
| 587 | SipCall transfer; |
| 588 | if (requestCode == REQUEST_TRANSFER) { |
| 589 | switch (resultCode) { |
| 590 | case TransferDFragment.RESULT_TRANSFER_CONF: |
| 591 | Conference c = data.getParcelableExtra("target"); |
| 592 | transfer = data.getParcelableExtra("transfer"); |
| 593 | try { |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 594 | mCallbacks.getRemoteService().attendedTransfer(transfer.getCallId(), c.getParticipants().get(0).getCallId()); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 595 | } catch (RemoteException e) { |
| 596 | e.printStackTrace(); |
| 597 | } |
| 598 | break; |
| 599 | |
| 600 | case TransferDFragment.RESULT_TRANSFER_NUMBER: |
| 601 | String to = data.getStringExtra("to_number"); |
| 602 | transfer = data.getParcelableExtra("transfer"); |
| 603 | try { |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 604 | mCallbacks.getRemoteService().transfer(transfer.getCallId(), to); |
| 605 | mCallbacks.getRemoteService().hangUp(transfer.getCallId()); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 606 | } catch (RemoteException e) { |
| 607 | e.printStackTrace(); |
| 608 | } |
| 609 | break; |
| 610 | case Activity.RESULT_CANCELED: |
| 611 | default: |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 612 | confUpdate(); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 613 | break; |
| 614 | } |
| 615 | } |
| 616 | } |
| 617 | |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 618 | void resetVideoSizes() { |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 619 | ViewGroup rootView = (ViewGroup) getView(); |
| 620 | if (rootView == null) |
| 621 | return; |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 622 | |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 623 | double videoRatio = videoWidth / (double) videoHeight; |
| 624 | double screenRatio = getView().getWidth() / (double) getView().getHeight(); |
| 625 | |
| 626 | FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mVideoSurface.getLayoutParams(); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 627 | int oldW = params.width; |
| 628 | int oldH = params.height; |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 629 | if (videoRatio >= screenRatio) { |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 630 | params.width = RelativeLayout.LayoutParams.MATCH_PARENT; |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 631 | params.height = (int) (videoHeight * (double) rootView.getWidth() / (double) videoWidth); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 632 | } else { |
| 633 | params.height = RelativeLayout.LayoutParams.MATCH_PARENT; |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 634 | params.width = (int) (videoWidth * (double) rootView.getHeight() / (double) videoHeight); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | if (oldW != params.width || oldH != params.height) { |
| 638 | Log.w(TAG, "onLayoutChange " + params.width + " x " + params.height); |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 639 | mVideoSurface.setLayoutParams(params); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | DisplayMetrics metrics = getResources().getDisplayMetrics(); |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 643 | FrameLayout.LayoutParams paramsPreview = (FrameLayout.LayoutParams) videoPreview.getLayoutParams(); |
| 644 | oldW = paramsPreview.width; |
| 645 | oldH = paramsPreview.height; |
| 646 | double previewMaxDim = Math.max(previewWidth, previewHeight); |
| 647 | double previewRatio = metrics.density * 160. / previewMaxDim; |
| 648 | paramsPreview.width = (int) (previewWidth * previewRatio); |
| 649 | paramsPreview.height = (int) (previewHeight * previewRatio); |
| 650 | if (oldW != paramsPreview.width || oldH != paramsPreview.height) { |
| 651 | Log.i(TAG, "onLayoutChange " + paramsPreview.width + " x " + paramsPreview.height); |
| 652 | videoPreview.setLayoutParams(paramsPreview); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 653 | } |
| 654 | } |
| 655 | |
| 656 | @Override |
| 657 | public void onConfigurationChanged(Configuration newConfig) { |
| 658 | if (videoPreview.getVisibility() == View.VISIBLE) { |
| 659 | try { |
Adrien Béraud | 8d6a483 | 2016-04-12 18:06:11 -0400 | [diff] [blame] | 660 | mCallbacks.getRemoteService().setPreviewSettings(); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 661 | mCallbacks.getRemoteService().videoPreviewSurfaceAdded(); |
| 662 | } catch (RemoteException e) { |
| 663 | e.printStackTrace(); |
| 664 | } |
| 665 | } |
| 666 | } |
| 667 | |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 668 | @Override |
| 669 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
| 670 | Log.i(TAG, "onCreateView"); |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 671 | View rootView = inflater.inflate(R.layout.frag_call, container, false); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 672 | |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 673 | ButterKnife.bind(this, rootView); |
| 674 | |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 675 | mNumeralDialEditText.requestFocus(); |
| 676 | mNumeralDialEditText.addTextChangedListener(new TextWatcher() { |
| 677 | @Override |
| 678 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| 679 | //~ Empty |
| 680 | } |
| 681 | |
| 682 | @Override |
| 683 | public void onTextChanged(CharSequence s, int start, int before, int count) { |
| 684 | String editTextString = s.toString(); |
| 685 | String lastChar = editTextString.substring(start, start + count); |
| 686 | if (lastChar.matches(DTMF_SUPPORTED_CHARS_REGEX)) { |
| 687 | try { |
| 688 | Log.d(TAG, "Sending DTMF: " + lastChar.toUpperCase()); |
| 689 | mCallbacks.getRemoteService().playDtmf(lastChar.toUpperCase()); |
| 690 | } catch (RemoteException exc) { |
| 691 | exc.printStackTrace(); |
| 692 | } |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | @Override |
| 697 | public void afterTextChanged(Editable s) { |
| 698 | //~ Empty |
| 699 | } |
| 700 | }); |
| 701 | |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 702 | |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 703 | mVideoSurface.getHolder().setFormat(PixelFormat.RGBA_8888); |
| 704 | mVideoSurface.getHolder().addCallback(new SurfaceHolder.Callback() { |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 705 | @Override |
| 706 | public void surfaceCreated(SurfaceHolder holder) { |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 707 | contactBubbleLayout.setVisibility(View.GONE); |
| 708 | Conference c = getConference(); |
| 709 | DRingService.videoSurfaces.put(c.getId(), new WeakReference<>(holder)); |
| 710 | try { |
| 711 | mCallbacks.getRemoteService().videoSurfaceAdded(c.getId()); |
| 712 | } catch (RemoteException e) { |
| 713 | e.printStackTrace(); |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | @Override |
| 718 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
| 719 | Log.i(TAG, "video surfaceChanged " + format + ", " + width + " x " + height); |
| 720 | } |
| 721 | |
| 722 | @Override |
| 723 | public void surfaceDestroyed(SurfaceHolder holder) { |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 724 | Conference c = getConference(); |
| 725 | DRingService.videoSurfaces.remove(c.getId()); |
| 726 | try { |
| 727 | IDRingService service = mCallbacks.getRemoteService(); |
| 728 | if (service != null) |
| 729 | service.videoSurfaceRemoved(c.getId()); |
| 730 | } catch (RemoteException e) { |
| 731 | e.printStackTrace(); |
| 732 | } |
| 733 | } |
| 734 | }); |
| 735 | |
| 736 | rootView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { |
| 737 | @Override |
| 738 | public void onLayoutChange(View parent, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { |
| 739 | resetVideoSizes(); |
| 740 | } |
| 741 | }); |
| 742 | rootView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { |
| 743 | @Override |
| 744 | public void onSystemUiVisibilityChange(int visibility) { |
| 745 | boolean ui = (visibility & (View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN)) == 0; |
| 746 | if (ongoingCall) { |
| 747 | hangupButton.setVisibility(ui ? View.VISIBLE : View.GONE); |
| 748 | } |
| 749 | } |
| 750 | }); |
| 751 | |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 752 | videoPreview.getHolder().setFormat(PixelFormat.RGBA_8888); |
| 753 | videoPreview.getHolder().addCallback(new SurfaceHolder.Callback() { |
| 754 | @Override |
| 755 | public void surfaceCreated(SurfaceHolder holder) { |
| 756 | DRingService.mCameraPreviewSurface = new WeakReference<>(holder); |
| 757 | try { |
| 758 | mCallbacks.getRemoteService().videoPreviewSurfaceAdded(); |
| 759 | } catch (RemoteException e) { |
| 760 | e.printStackTrace(); |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | @Override |
| 765 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
| 766 | Log.i(TAG, "videoPreview surfaceChanged " + format + ", " + width + " x " + height); |
| 767 | } |
| 768 | |
| 769 | @Override |
| 770 | public void surfaceDestroyed(SurfaceHolder holder) { |
| 771 | if (videoPreview != null && DRingService.mCameraPreviewSurface.get() == holder) { |
| 772 | DRingService.mCameraPreviewSurface.clear(); |
| 773 | } |
| 774 | try { |
| 775 | IDRingService service = mCallbacks.getRemoteService(); |
| 776 | if (service != null) |
| 777 | service.videoPreviewSurfaceRemoved(); |
| 778 | } catch (RemoteException e) { |
| 779 | e.printStackTrace(); |
| 780 | } |
| 781 | } |
| 782 | }); |
| 783 | videoPreview.setZOrderMediaOverlay(true); |
| 784 | |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 785 | return rootView; |
| 786 | } |
| 787 | |
| 788 | public Conference getConference() { |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 789 | Conference c = mCallbacks.getDisplayedConference(); |
| 790 | if (c != null) { |
| 791 | if (mCachedConference != c) |
| 792 | mCachedConference = c; |
| 793 | return c; |
| 794 | } |
| 795 | return mCachedConference; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 796 | } |
| 797 | |
Adrien Béraud | 6c4cedb | 2015-12-11 14:34:20 -0500 | [diff] [blame] | 798 | private void initContactDisplay(final SipCall call) { |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 799 | |
Adrien Béraud | 6c4cedb | 2015-12-11 14:34:20 -0500 | [diff] [blame] | 800 | CallContact contact = call.getContact(); |
| 801 | final String name = contact.getDisplayName(); |
| 802 | contactBubbleTxt.setText(name); |
| 803 | if (call.getNumber().contentEquals(name)) { |
| 804 | contactBubbleNumTxt.setVisibility(View.GONE); |
| 805 | } else { |
| 806 | contactBubbleNumTxt.setVisibility(View.VISIBLE); |
| 807 | contactBubbleNumTxt.setText(call.getNumber()); |
| 808 | } |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 809 | |
| 810 | mPulseAnimation.startRippleAnimation(); |
| 811 | |
Romain Bertozzi | 64a6678 | 2016-08-02 12:10:38 -0400 | [diff] [blame^] | 812 | updateContactBubble(); |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 813 | |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 814 | ActionBar ab = mCallbacks.getSupportActionBar(); |
| 815 | ab.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE); |
| 816 | ab.setTitle(name); |
Adrien Béraud | 6c4cedb | 2015-12-11 14:34:20 -0500 | [diff] [blame] | 817 | } |
| 818 | |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 819 | private void initNormalStateDisplay() { |
| 820 | Log.i(TAG, "Start normal display"); |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 821 | mCallbacks.startTimer(); |
| 822 | acceptButton.setVisibility(View.GONE); |
| 823 | refuseButton.setVisibility(View.GONE); |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 824 | hangupButton.setVisibility(View.VISIBLE); |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 825 | |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 826 | final SipCall call = getFirstParticipant(); |
Adrien Béraud | 6c4cedb | 2015-12-11 14:34:20 -0500 | [diff] [blame] | 827 | initContactDisplay(call); |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 828 | |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 829 | if (getActivity() != null) { |
| 830 | getActivity().invalidateOptionsMenu(); |
| 831 | } |
| 832 | |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 833 | contactBubbleLayout.setVisibility(haveVideo ? View.GONE : View.VISIBLE); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 834 | updateSecurityDisplay(); |
| 835 | } |
| 836 | |
| 837 | private void updateSecurityDisplay() { |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 838 | //First we check if all participants use a security layer. |
Romain Bertozzi | 64a6678 | 2016-08-02 12:10:38 -0400 | [diff] [blame^] | 839 | boolean secureCall = !getConference().getParticipants().isEmpty(); |
Adrien Béraud | 6c4cedb | 2015-12-11 14:34:20 -0500 | [diff] [blame] | 840 | for (SipCall c : getConference().getParticipants()) |
Romain Bertozzi | 64a6678 | 2016-08-02 12:10:38 -0400 | [diff] [blame^] | 841 | secureCall &= c instanceof SecureSipCall && ((SecureSipCall) c).isSecure(); |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 842 | |
Romain Bertozzi | 64a6678 | 2016-08-02 12:10:38 -0400 | [diff] [blame^] | 843 | securityIndicator.setVisibility(secureCall ? View.VISIBLE : View.GONE); |
| 844 | if (!secureCall) |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 845 | return; |
| 846 | |
| 847 | Log.i(TAG, "Enable security display"); |
| 848 | if (getConference().hasMultipleParticipants()) { |
| 849 | //TODO What layout should we put? |
| 850 | } else { |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 851 | final SecureSipCall secured = (SecureSipCall) getFirstParticipant(); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 852 | switch (secured.displayModule()) { |
| 853 | case SecureSipCall.DISPLAY_GREEN_LOCK: |
| 854 | Log.i(TAG, "DISPLAY_GREEN_LOCK"); |
| 855 | showLock(R.drawable.green_lock); |
| 856 | break; |
| 857 | case SecureSipCall.DISPLAY_RED_LOCK: |
| 858 | Log.i(TAG, "DISPLAY_RED_LOCK"); |
| 859 | showLock(R.drawable.red_lock); |
| 860 | break; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 861 | case SecureSipCall.DISPLAY_NONE: |
| 862 | break; |
| 863 | } |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | private void showLock(int resId) { |
| 868 | ImageView lock = (ImageView) mSecuritySwitch.findViewById(R.id.lock_image); |
Romain Bertozzi | 64a6678 | 2016-08-02 12:10:38 -0400 | [diff] [blame^] | 869 | lock.setImageDrawable(ResourcesCompat.getDrawable(getResources(), resId, null)); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 870 | mSecuritySwitch.setDisplayedChild(1); |
| 871 | mSecuritySwitch.setVisibility(View.VISIBLE); |
| 872 | } |
| 873 | |
| 874 | private void initIncomingCallDisplay() { |
| 875 | Log.i(TAG, "Start incoming display"); |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 876 | final SipCall call = getFirstParticipant(); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 877 | if (mCallbacks.getService().getAccount(call.getAccount()).isAutoanswerEnabled()) { |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 878 | try { |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 879 | mCallbacks.getRemoteService().accept(call.getCallId()); |
| 880 | } catch (Exception e) { |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 881 | e.printStackTrace(); |
| 882 | } |
| 883 | } else { |
Adrien Béraud | 6c4cedb | 2015-12-11 14:34:20 -0500 | [diff] [blame] | 884 | initContactDisplay(call); |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 885 | acceptButton.setVisibility(View.VISIBLE); |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 886 | refuseButton.setVisibility(View.VISIBLE); |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 887 | hangupButton.setVisibility(View.GONE); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 888 | } |
| 889 | } |
| 890 | |
| 891 | private void initOutGoingCallDisplay() { |
| 892 | Log.i(TAG, "Start outgoing display"); |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 893 | |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 894 | final SipCall call = getFirstParticipant(); |
Adrien Béraud | 6c4cedb | 2015-12-11 14:34:20 -0500 | [diff] [blame] | 895 | initContactDisplay(call); |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 896 | |
| 897 | acceptButton.setVisibility(View.GONE); |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 898 | refuseButton.setVisibility(View.VISIBLE); |
| 899 | hangupButton.setVisibility(View.GONE); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 900 | } |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 901 | |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 902 | public void updateTime() { |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 903 | if (getConference() != null && !getConference().getParticipants().isEmpty()) { |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 904 | long duration = System.currentTimeMillis() - getFirstParticipant().getTimestampStart(); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 905 | duration = duration / 1000; |
| 906 | if (getConference().isOnGoing()) |
Romain Bertozzi | 64a6678 | 2016-08-02 12:10:38 -0400 | [diff] [blame^] | 907 | mCallStatusTxt.setText(String.format(Locale.getDefault(), "%d:%02d:%02d", duration / 3600, duration % 3600 / 60, duration % 60)); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 908 | } |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 909 | } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 910 | |
Romain Bertozzi | 64a6678 | 2016-08-02 12:10:38 -0400 | [diff] [blame^] | 911 | /** |
| 912 | * Updates the bubble contact image with the vcard image, the contact image or by default the |
| 913 | * contact picture drawable. |
| 914 | */ |
| 915 | private void updateContactBubble() { |
| 916 | Conference conference = this.getConference(); |
| 917 | Context context = getActivity(); |
| 918 | if (conference == null || context == null) { |
| 919 | return; |
| 920 | } |
| 921 | |
| 922 | SipCall participant = getFirstParticipant(); |
| 923 | if (participant == null) { |
| 924 | return; |
| 925 | } |
| 926 | |
| 927 | VCard vcard; |
| 928 | String username = participant.getNumberUri().username; |
| 929 | vcard = VCardUtils.loadFromDisk(username + ".vcf", context); |
| 930 | if (vcard == null) { |
| 931 | Log.d(TAG, "No vcard."); |
| 932 | setDefaultPhoto(); |
| 933 | return; |
| 934 | } else { |
| 935 | Log.d(TAG, "VCard found: " + vcard); |
| 936 | } |
| 937 | |
| 938 | if (!vcard.getPhotos().isEmpty()) { |
| 939 | Photo tmp = vcard.getPhotos().get(0); |
| 940 | contactBubbleView.setImageBitmap(CropImageUtils.cropImageToCircle(tmp.getData())); |
| 941 | } else { |
| 942 | setDefaultPhoto(); |
| 943 | } |
| 944 | |
| 945 | if (TextUtils.isEmpty(vcard.getFormattedName().getValue())) { |
| 946 | return; |
| 947 | } |
| 948 | contactBubbleTxt.setText(vcard.getFormattedName().getValue()); |
| 949 | if (participant.getNumber().contentEquals(vcard.getFormattedName().getValue())) { |
| 950 | contactBubbleNumTxt.setVisibility(View.GONE); |
| 951 | } else { |
| 952 | contactBubbleNumTxt.setVisibility(View.VISIBLE); |
| 953 | contactBubbleNumTxt.setText(participant.getNumber()); |
| 954 | } |
| 955 | } |
| 956 | |
| 957 | |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 958 | @OnClick({R.id.call_hangup_btn, R.id.call_refuse_btn}) |
| 959 | public void hangUpClicked() { |
| 960 | try { |
| 961 | final SipCall call = getFirstParticipant(); |
| 962 | if (call == null) { |
| 963 | return; |
| 964 | } |
| 965 | final String callId = call.getCallId(); |
| 966 | mCallbacks.getRemoteService().hangUp(callId); |
| 967 | mCallbacks.terminateCall(); |
| 968 | } catch (RemoteException e) { |
| 969 | e.printStackTrace(); |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | @OnClick(R.id.call_accept_btn) |
| 974 | public void acceptClicked() { |
| 975 | final SipCall call = getFirstParticipant(); |
| 976 | if (call == null) { |
| 977 | return; |
| 978 | } |
| 979 | try { |
| 980 | mCallbacks.getRemoteService().accept(call.getCallId()); |
| 981 | } catch (RemoteException e) { |
| 982 | e.printStackTrace(); |
| 983 | } |
| 984 | } |
| 985 | |
| 986 | /** |
| 987 | * Helper accessor that check nullity or emptiness of components to access first call participant |
Romain Bertozzi | 64a6678 | 2016-08-02 12:10:38 -0400 | [diff] [blame^] | 988 | * |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 989 | * @return the first participant or null |
| 990 | */ |
| 991 | @Nullable |
| 992 | private SipCall getFirstParticipant() { |
| 993 | if (getConference() == null || getConference().getParticipants() == null || getConference().getParticipants().isEmpty()) { |
| 994 | return null; |
| 995 | } |
| 996 | return getConference().getParticipants().get(0); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 997 | } |
Romain Bertozzi | 64a6678 | 2016-08-02 12:10:38 -0400 | [diff] [blame^] | 998 | |
| 999 | private void setDefaultPhoto() { |
| 1000 | if (getConference() != null |
| 1001 | && getConference().getParticipants() != null |
| 1002 | && !getConference().getParticipants().isEmpty()) { |
| 1003 | final SipCall call = getConference().getParticipants().get(0); |
| 1004 | final CallContact contact = call.getContact(); |
| 1005 | if (contact != null) { |
| 1006 | new ContactPictureTask(getActivity(), contactBubbleView, contact).run(); |
| 1007 | } |
| 1008 | } else { |
| 1009 | contactBubbleView.setImageDrawable( |
| 1010 | ResourcesCompat.getDrawable(getResources(), R.drawable.ic_contact_picture, null)); |
| 1011 | } |
| 1012 | } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 1013 | } |