Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 1 | /* |
Sébastien Blin | ab53ada | 2019-01-02 17:23:00 -0500 | [diff] [blame] | 2 | * Copyright (C) 2004-2019 Savoir-faire Linux Inc. |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 3 | * |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 4 | * Author: Hadrien De Sousa <hadrien.desousa@savoirfairelinux.com> |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 5 | * 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 | */ |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 21 | package cx.ring.fragments; |
| 22 | |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 23 | import android.app.Activity; |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 24 | import android.app.PendingIntent; |
| 25 | import android.app.PictureInPictureParams; |
| 26 | import android.app.RemoteAction; |
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 | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 29 | import android.graphics.Matrix; |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 30 | import android.graphics.PixelFormat; |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 31 | import android.graphics.Rect; |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 32 | import android.graphics.RectF; |
| 33 | import android.graphics.SurfaceTexture; |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 34 | import android.graphics.drawable.Icon; |
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; |
Adrien Béraud | 3f9f6cd | 2018-12-12 15:05:28 -0500 | [diff] [blame] | 38 | |
Adrien Béraud | 8bc9510 | 2018-08-25 22:34:51 -0400 | [diff] [blame] | 39 | import androidx.annotation.NonNull; |
| 40 | import androidx.annotation.Nullable; |
Adrien Béraud | bcbb4d4 | 2018-12-08 16:06:39 -0500 | [diff] [blame] | 41 | |
| 42 | import android.text.Editable; |
| 43 | import android.text.TextWatcher; |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 44 | import android.util.Rational; |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 45 | import android.view.LayoutInflater; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 46 | import android.view.Menu; |
| 47 | import android.view.MenuInflater; |
| 48 | import android.view.MenuItem; |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 49 | import android.view.OrientationEventListener; |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 50 | import android.view.Surface; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 51 | import android.view.SurfaceHolder; |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 52 | import android.view.TextureView; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 53 | import android.view.View; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 54 | import android.view.ViewGroup; |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 55 | import android.view.WindowManager; |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 56 | import android.view.inputmethod.InputMethodManager; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 57 | import android.widget.RelativeLayout; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 58 | |
Pierre Duchemin | bb83367 | 2018-03-09 16:18:33 -0500 | [diff] [blame] | 59 | import com.rodolfonavalon.shaperipplelibrary.model.Circle; |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 60 | |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 61 | import java.util.ArrayList; |
Romain Bertozzi | 64a6678 | 2016-08-02 12:10:38 -0400 | [diff] [blame] | 62 | import java.util.Locale; |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 63 | import java.util.Random; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 64 | |
Adrien Béraud | 8bc9510 | 2018-08-25 22:34:51 -0400 | [diff] [blame] | 65 | import androidx.appcompat.app.ActionBar; |
| 66 | import androidx.appcompat.app.AppCompatActivity; |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 67 | import androidx.databinding.DataBindingUtil; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 68 | import cx.ring.R; |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 69 | import cx.ring.application.RingApplication; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 70 | import cx.ring.call.CallPresenter; |
| 71 | import cx.ring.call.CallView; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 72 | import cx.ring.client.ConversationActivity; |
Thibault Wittemberg | 4f33d07 | 2016-10-06 17:11:41 -0400 | [diff] [blame] | 73 | import cx.ring.client.HomeActivity; |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 74 | import cx.ring.databinding.FragCallBinding; |
Hadrien De Sousa | 73d6dd7 | 2017-09-07 10:54:51 -0400 | [diff] [blame] | 75 | import cx.ring.dependencyinjection.RingInjectionComponent; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 76 | import cx.ring.model.CallContact; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 77 | import cx.ring.model.SipCall; |
Adrien Béraud | a373e3b | 2018-12-12 11:14:50 -0500 | [diff] [blame] | 78 | import cx.ring.mvp.BaseSupportFragment; |
Alexandre Lision | 5da46fa | 2017-08-09 10:25:50 -0400 | [diff] [blame] | 79 | import cx.ring.service.DRingService; |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 80 | import cx.ring.services.NotificationService; |
Alexandre Lision | 4865f7d | 2016-11-16 18:03:35 -0500 | [diff] [blame] | 81 | import cx.ring.utils.ActionHelper; |
Pierre Duchemin | 42788c3 | 2018-03-08 16:21:15 -0500 | [diff] [blame] | 82 | import cx.ring.utils.DeviceUtils; |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 83 | import cx.ring.utils.KeyboardVisibilityManager; |
Adrien Béraud | 5f8c3f7 | 2018-03-09 14:49:39 -0500 | [diff] [blame] | 84 | import cx.ring.utils.Log; |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 85 | import cx.ring.utils.MediaButtonsHelper; |
Adrien Béraud | 8f9d270 | 2018-09-16 18:24:01 -0400 | [diff] [blame] | 86 | import cx.ring.views.AvatarDrawable; |
Adrien Béraud | 2c378b3 | 2018-07-11 15:24:02 -0400 | [diff] [blame] | 87 | import io.reactivex.disposables.CompositeDisposable; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 88 | |
Adrien Béraud | a373e3b | 2018-12-12 11:14:50 -0500 | [diff] [blame] | 89 | public class CallFragment extends BaseSupportFragment<CallPresenter> implements CallView, MediaButtonsHelper.MediaButtonsHelperCallback { |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 90 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 91 | public static final String TAG = CallFragment.class.getSimpleName(); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 92 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 93 | public static final String ACTION_PLACE_CALL = "PLACE_CALL"; |
| 94 | public static final String ACTION_GET_CALL = "GET_CALL"; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 95 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 96 | public static final String KEY_ACTION = "action"; |
| 97 | public static final String KEY_ACCOUNT_ID = "accountId"; |
| 98 | public static final String KEY_CONF_ID = "confId"; |
Hadrien De Sousa | 203164c | 2017-12-05 17:41:42 -0500 | [diff] [blame] | 99 | public static final String KEY_AUDIO_ONLY = "AUDIO_ONLY"; |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 100 | |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 101 | private FragCallBinding binding; |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 102 | private OrientationEventListener mOrientationListener; |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 103 | |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 104 | private MenuItem dialPadBtn = null; |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 105 | private boolean restartVideo = false; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 106 | private PowerManager.WakeLock mScreenWakeLock; |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 107 | private int mCurrentOrientation = 0; |
| 108 | |
| 109 | private int mVideoWidth = -1; |
| 110 | private int mVideoHeight = -1; |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 111 | private int mPreviewWidth = 720, mPreviewHeight = 1280; |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 112 | private int mPreviewSurfaceWidth = 0, mPreviewSurfaceHeight = 0; |
Adrien Béraud | 8d6a483 | 2016-04-12 18:06:11 -0400 | [diff] [blame] | 113 | |
Adrien Béraud | 2c378b3 | 2018-07-11 15:24:02 -0400 | [diff] [blame] | 114 | private final CompositeDisposable mCompositeDisposable = new CompositeDisposable(); |
| 115 | |
Hadrien De Sousa | 203164c | 2017-12-05 17:41:42 -0500 | [diff] [blame] | 116 | public static CallFragment newInstance(@NonNull String action, @Nullable String accountID, @Nullable String contactRingId, boolean audioOnly) { |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 117 | Bundle bundle = new Bundle(); |
| 118 | bundle.putString(KEY_ACTION, action); |
| 119 | bundle.putString(KEY_ACCOUNT_ID, accountID); |
Hadrien De Sousa | 0dc8316 | 2017-11-10 16:15:18 -0500 | [diff] [blame] | 120 | bundle.putString(ConversationFragment.KEY_CONTACT_RING_ID, contactRingId); |
Hadrien De Sousa | 203164c | 2017-12-05 17:41:42 -0500 | [diff] [blame] | 121 | bundle.putBoolean(KEY_AUDIO_ONLY, audioOnly); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 122 | CallFragment countDownFragment = new CallFragment(); |
| 123 | countDownFragment.setArguments(bundle); |
| 124 | return countDownFragment; |
| 125 | } |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 126 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 127 | public static CallFragment newInstance(@NonNull String action, @Nullable String confId) { |
| 128 | Bundle bundle = new Bundle(); |
| 129 | bundle.putString(KEY_ACTION, action); |
| 130 | bundle.putString(KEY_CONF_ID, confId); |
| 131 | CallFragment countDownFragment = new CallFragment(); |
| 132 | countDownFragment.setArguments(bundle); |
| 133 | return countDownFragment; |
| 134 | } |
| 135 | |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 136 | public static int callStateToHumanState(final SipCall.State state) { |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 137 | switch (state) { |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 138 | case SEARCHING: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 139 | return R.string.call_human_state_searching; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 140 | case CONNECTING: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 141 | return R.string.call_human_state_connecting; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 142 | case RINGING: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 143 | return R.string.call_human_state_ringing; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 144 | case CURRENT: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 145 | return R.string.call_human_state_current; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 146 | case HUNGUP: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 147 | return R.string.call_human_state_hungup; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 148 | case BUSY: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 149 | return R.string.call_human_state_busy; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 150 | case FAILURE: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 151 | return R.string.call_human_state_failure; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 152 | case HOLD: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 153 | return R.string.call_human_state_hold; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 154 | case UNHOLD: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 155 | return R.string.call_human_state_unhold; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 156 | case OVER: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 157 | return R.string.call_human_state_over; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 158 | case NONE: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 159 | default: |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 160 | return 0; |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 161 | } |
| 162 | } |
| 163 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 164 | @Override |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 165 | protected void initPresenter(CallPresenter presenter) { |
| 166 | super.initPresenter(presenter); |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 167 | Bundle args = getArguments(); |
| 168 | if (args != null) { |
| 169 | String action = args.getString(KEY_ACTION); |
| 170 | if (action != null) { |
| 171 | if (action.equals(ACTION_PLACE_CALL)) { |
| 172 | presenter.initOutGoing(getArguments().getString(KEY_ACCOUNT_ID), |
| 173 | getArguments().getString(ConversationFragment.KEY_CONTACT_RING_ID), |
| 174 | getArguments().getBoolean(KEY_AUDIO_ONLY)); |
| 175 | } else if (action.equals(ACTION_GET_CALL)) { |
| 176 | presenter.initIncoming(getArguments().getString(KEY_CONF_ID)); |
| 177 | } |
Pierre Duchemin | 45707ca | 2018-01-15 15:05:23 -0500 | [diff] [blame] | 178 | } |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 179 | } |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 180 | } |
| 181 | |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 182 | public void onUserLeave() { |
| 183 | presenter.requestPipMode(); |
| 184 | } |
| 185 | |
| 186 | @Override |
| 187 | public void enterPipMode(SipCall sipCall) { |
| 188 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { |
| 189 | return; |
| 190 | } |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 191 | Context context = requireContext(); |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 192 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
| 193 | PictureInPictureParams.Builder paramBuilder = new PictureInPictureParams.Builder(); |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 194 | if (binding.videoSurface.getVisibility() == View.VISIBLE) { |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 195 | int[] l = new int[2]; |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 196 | binding.videoSurface.getLocationInWindow(l); |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 197 | int x = l[0]; |
| 198 | int y = l[1]; |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 199 | int w = binding.videoSurface.getWidth(); |
| 200 | int h = binding.videoSurface.getHeight(); |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 201 | Rect videoBounds = new Rect(x, y, x + w, y + h); |
| 202 | paramBuilder.setAspectRatio(new Rational(w, h)); |
| 203 | paramBuilder.setSourceRectHint(videoBounds); |
| 204 | } |
| 205 | ArrayList<RemoteAction> actions = new ArrayList<>(1); |
| 206 | actions.add(new RemoteAction( |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 207 | Icon.createWithResource(context, R.drawable.baseline_call_end_24), |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 208 | getString(R.string.action_call_hangup), |
| 209 | getString(R.string.action_call_hangup), |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 210 | PendingIntent.getService(context, new Random().nextInt(), |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 211 | new Intent(DRingService.ACTION_CALL_END) |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 212 | .setClass(context, DRingService.class) |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 213 | .putExtra(NotificationService.KEY_CALL_ID, sipCall.getCallId()), PendingIntent.FLAG_ONE_SHOT))); |
| 214 | paramBuilder.setActions(actions); |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 215 | requireActivity().enterPictureInPictureMode(paramBuilder.build()); |
| 216 | } else if (DeviceUtils.isTv(context)) { |
| 217 | requireActivity().enterPictureInPictureMode(); |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 218 | } |
| 219 | } |
| 220 | |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 221 | @Override |
Hadrien De Sousa | 73d6dd7 | 2017-09-07 10:54:51 -0400 | [diff] [blame] | 222 | public int getLayout() { |
| 223 | return R.layout.frag_call; |
| 224 | } |
| 225 | |
| 226 | @Override |
| 227 | public void injectFragment(RingInjectionComponent component) { |
| 228 | component.inject(this); |
| 229 | } |
| 230 | |
| 231 | @Override |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 232 | public void onStart() { |
| 233 | super.onStart(); |
| 234 | if (restartVideo) { |
| 235 | displayVideoSurface(true); |
| 236 | restartVideo = false; |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | @Override |
| 241 | public void onStop() { |
| 242 | super.onStop(); |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 243 | if (binding.videoSurface.getVisibility() == View.VISIBLE) { |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 244 | restartVideo = true; |
| 245 | } |
| 246 | } |
| 247 | |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 248 | @Nullable |
| 249 | @Override |
Adrien Béraud | c14d55d | 2019-01-02 16:33:40 -0500 | [diff] [blame] | 250 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 251 | injectFragment(((RingApplication) requireActivity().getApplication()).getRingInjectionComponent()); |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 252 | binding = DataBindingUtil.inflate(inflater, R.layout.frag_call, container, false); |
| 253 | binding.setPresenter(this); |
| 254 | return binding.getRoot(); |
| 255 | } |
| 256 | |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 257 | private TextureView.SurfaceTextureListener listener = new TextureView.SurfaceTextureListener() { |
| 258 | @Override |
| 259 | public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 260 | mPreviewSurfaceWidth = width; |
| 261 | mPreviewSurfaceHeight = height; |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 262 | presenter.previewVideoSurfaceCreated(binding.previewSurface); |
| 263 | } |
| 264 | |
| 265 | @Override |
| 266 | public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 267 | mPreviewSurfaceWidth = width; |
| 268 | mPreviewSurfaceHeight = height; |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | @Override |
| 272 | public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { |
| 273 | presenter.previewVideoSurfaceDestroyed(); |
| 274 | return true; |
| 275 | } |
| 276 | |
| 277 | @Override |
| 278 | public void onSurfaceTextureUpdated(SurfaceTexture surface) {} |
| 279 | }; |
| 280 | |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 281 | @Override |
Adrien Béraud | c14d55d | 2019-01-02 16:33:40 -0500 | [diff] [blame] | 282 | public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 283 | setHasOptionsMenu(true); |
Hadrien De Sousa | 73d6dd7 | 2017-09-07 10:54:51 -0400 | [diff] [blame] | 284 | super.onViewCreated(view, savedInstanceState); |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 285 | mCurrentOrientation = getResources().getConfiguration().orientation; |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 286 | PowerManager powerManager = (PowerManager) requireContext().getSystemService(Context.POWER_SERVICE); |
Adrien Béraud | 87810c7 | 2018-06-11 15:55:03 -0400 | [diff] [blame] | 287 | mScreenWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "ring:callLock"); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 288 | mScreenWakeLock.setReferenceCounted(false); |
| 289 | |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 290 | if (mScreenWakeLock != null && !mScreenWakeLock.isHeld()) { |
| 291 | mScreenWakeLock.acquire(); |
| 292 | } |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 293 | |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 294 | binding.videoSurface.getHolder().setFormat(PixelFormat.RGBA_8888); |
| 295 | binding.videoSurface.getHolder().addCallback(new SurfaceHolder.Callback() { |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 296 | @Override |
| 297 | public void surfaceCreated(SurfaceHolder holder) { |
| 298 | presenter.videoSurfaceCreated(holder); |
| 299 | } |
| 300 | |
| 301 | @Override |
| 302 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
| 303 | |
| 304 | } |
| 305 | |
| 306 | @Override |
| 307 | public void surfaceDestroyed(SurfaceHolder holder) { |
| 308 | presenter.videoSurfaceDestroyed(); |
| 309 | } |
| 310 | }); |
Pierre Duchemin | 45707ca | 2018-01-15 15:05:23 -0500 | [diff] [blame] | 311 | view.setOnSystemUiVisibilityChangeListener(visibility -> { |
| 312 | boolean ui = (visibility & (View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN)) == 0; |
| 313 | presenter.uiVisibilityChanged(ui); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 314 | }); |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 315 | view.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> |
| 316 | resetVideoSize(mVideoWidth, mVideoHeight)); |
| 317 | |
| 318 | WindowManager windowManager = (WindowManager) requireContext().getSystemService(Context.WINDOW_SERVICE); |
| 319 | mOrientationListener = new OrientationEventListener(getContext()) { |
| 320 | @Override |
| 321 | public void onOrientationChanged(int orientation) { |
| 322 | int rot = windowManager.getDefaultDisplay().getRotation(); |
| 323 | if (mCurrentOrientation != rot) { |
| 324 | mCurrentOrientation = rot; |
| 325 | presenter.configurationChanged(rot); |
| 326 | } |
| 327 | } |
| 328 | }; |
| 329 | if (mOrientationListener.canDetectOrientation()) { |
| 330 | mOrientationListener.enable(); |
| 331 | } |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 332 | |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 333 | binding.shapeRipple.setRippleShape(new Circle()); |
| 334 | binding.callSpeakerBtn.setChecked(presenter.isSpeakerphoneOn()); |
Adrien Béraud | ec19fad | 2018-12-30 16:51:05 -0500 | [diff] [blame] | 335 | binding.callMicBtn.setChecked(presenter.isMicrophoneMuted()); |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 336 | binding.previewSurface.setSurfaceTextureListener(listener); |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 337 | binding.previewSurface.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> |
| 338 | configureTransform(mPreviewSurfaceWidth, mPreviewSurfaceHeight)); |
Adrien Béraud | bcbb4d4 | 2018-12-08 16:06:39 -0500 | [diff] [blame] | 339 | |
| 340 | binding.dialpadEditText.addTextChangedListener(new TextWatcher() { |
| 341 | @Override |
| 342 | public void beforeTextChanged(CharSequence s, int start, int count, int after) {} |
| 343 | |
| 344 | @Override |
| 345 | public void onTextChanged(CharSequence s, int start, int before, int count) { |
| 346 | presenter.sendDtmf(s.subSequence(start, start + count)); |
| 347 | } |
| 348 | |
| 349 | @Override |
| 350 | public void afterTextChanged(Editable s) {} |
| 351 | }); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | @Override |
Adrien Béraud | 2c378b3 | 2018-07-11 15:24:02 -0400 | [diff] [blame] | 355 | public void onDestroyView() { |
| 356 | super.onDestroyView(); |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 357 | if (mOrientationListener != null) { |
| 358 | mOrientationListener.disable(); |
| 359 | mOrientationListener = null; |
| 360 | } |
Adrien Béraud | 2c378b3 | 2018-07-11 15:24:02 -0400 | [diff] [blame] | 361 | mCompositeDisposable.clear(); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 362 | if (mScreenWakeLock != null && mScreenWakeLock.isHeld()) { |
| 363 | mScreenWakeLock.release(); |
| 364 | } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 365 | } |
| 366 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 367 | @Override |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 368 | public void onCreateOptionsMenu(Menu m, MenuInflater inf) { |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 369 | super.onCreateOptionsMenu(m, inf); |
Adrien Béraud | da2eb1a | 2016-01-11 13:15:12 -0500 | [diff] [blame] | 370 | inf.inflate(R.menu.ac_call, m); |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 371 | dialPadBtn = m.findItem(R.id.menuitem_dialpad); |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | @Override |
| 375 | public void onPrepareOptionsMenu(Menu menu) { |
| 376 | super.onPrepareOptionsMenu(menu); |
Hadrien De Sousa | f5774ee | 2017-05-17 14:04:17 -0400 | [diff] [blame] | 377 | presenter.prepareOptionMenu(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | @Override |
| 381 | public boolean onOptionsItemSelected(MenuItem item) { |
| 382 | super.onOptionsItemSelected(item); |
| 383 | switch (item.getItemId()) { |
| 384 | case android.R.id.home: |
| 385 | case R.id.menuitem_chat: |
Hadrien De Sousa | f5774ee | 2017-05-17 14:04:17 -0400 | [diff] [blame] | 386 | presenter.chatClick(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 387 | break; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 388 | case R.id.menuitem_dialpad: |
Hadrien De Sousa | f5774ee | 2017-05-17 14:04:17 -0400 | [diff] [blame] | 389 | presenter.dialpadClick(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 390 | break; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 391 | } |
| 392 | return true; |
| 393 | } |
| 394 | |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 395 | @Override |
Adrien Béraud | a373e3b | 2018-12-12 11:14:50 -0500 | [diff] [blame] | 396 | public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) { |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 397 | AppCompatActivity activity = (AppCompatActivity) getActivity(); |
| 398 | ActionBar actionBar = activity == null ? null : activity.getSupportActionBar(); |
| 399 | if (actionBar != null) { |
| 400 | if (isInPictureInPictureMode) |
| 401 | actionBar.hide(); |
| 402 | else |
| 403 | actionBar.show(); |
| 404 | } |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 405 | presenter.pipModeChanged(isInPictureInPictureMode); |
| 406 | } |
| 407 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 408 | @Override |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 409 | public void displayContactBubble(final boolean display) { |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 410 | binding.contactBubbleLayout.getHandler().post(() -> binding.contactBubbleLayout.setVisibility(display ? View.VISIBLE : View.GONE)); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | @Override |
| 414 | public void displayVideoSurface(final boolean display) { |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 415 | binding.videoSurface.setVisibility(display ? View.VISIBLE : View.GONE); |
Adrien Béraud | 76dec1d | 2018-12-14 18:58:19 -0500 | [diff] [blame] | 416 | binding.previewContainer.setVisibility(display ? View.VISIBLE : View.GONE); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 417 | updateMenu(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | @Override |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 421 | public void displayPreviewSurface(final boolean display) { |
| 422 | if (display) { |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 423 | binding.videoSurface.setZOrderOnTop(false); |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 424 | binding.videoSurface.setZOrderMediaOverlay(false); |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 425 | } else { |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 426 | binding.videoSurface.setZOrderMediaOverlay(true); |
| 427 | binding.videoSurface.setZOrderOnTop(true); |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 428 | } |
| 429 | } |
| 430 | |
| 431 | @Override |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 432 | public void displayHangupButton(boolean display) { |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 433 | binding.callControlGroup.setVisibility(display ? View.VISIBLE : View.GONE); |
| 434 | binding.callHangupBtn.setVisibility(display ? View.VISIBLE : View.GONE); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | @Override |
| 438 | public void displayDialPadKeyboard() { |
Adrien Béraud | bcbb4d4 | 2018-12-08 16:06:39 -0500 | [diff] [blame] | 439 | KeyboardVisibilityManager.showKeyboard(getActivity(), binding.dialpadEditText, InputMethodManager.SHOW_FORCED); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | @Override |
| 443 | public void switchCameraIcon(boolean isFront) { |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 444 | binding.callCameraFlipBtn.setImageResource(isFront ? R.drawable.ic_camera_front_white : R.drawable.ic_camera_rear_white); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | @Override |
Adrien Béraud | d3bf4e4 | 2018-02-14 14:44:41 +0100 | [diff] [blame] | 448 | public void updateMenu() { |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 449 | requireActivity().invalidateOptionsMenu(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | @Override |
| 453 | public void updateTime(final long duration) { |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 454 | if (binding.callStatusTxt != null) |
| 455 | binding.callStatusTxt.setText(String.format(Locale.getDefault(), "%d:%02d:%02d", duration / 3600, duration % 3600 / 60, duration % 60)); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | @Override |
Adrien Beraud | 8e6e2ff | 2017-06-14 14:40:27 +0200 | [diff] [blame] | 459 | public void updateContactBubble(@NonNull final CallContact contact) { |
Adrien Béraud | 5f8c3f7 | 2018-03-09 14:49:39 -0500 | [diff] [blame] | 460 | String username = contact.getRingUsername(); |
| 461 | String displayName = contact.getDisplayName(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 462 | |
Adrien Béraud | 5f8c3f7 | 2018-03-09 14:49:39 -0500 | [diff] [blame] | 463 | String ringId = contact.getIds().get(0); |
Adrien Béraud | afcdd96 | 2018-07-06 21:38:41 -0400 | [diff] [blame] | 464 | Log.d(TAG, "updateContactBubble: contact=" + contact + " username=" + username + ", ringId=" + ringId); |
Adrien Béraud | 5f8c3f7 | 2018-03-09 14:49:39 -0500 | [diff] [blame] | 465 | |
Adrien Béraud | afcdd96 | 2018-07-06 21:38:41 -0400 | [diff] [blame] | 466 | boolean hasProfileName = displayName != null && !displayName.contentEquals(username); |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 467 | |
| 468 | AppCompatActivity activity = (AppCompatActivity) getActivity(); |
| 469 | if (activity != null) { |
| 470 | ActionBar ab = activity.getSupportActionBar(); |
| 471 | if (ab != null) { |
| 472 | if (hasProfileName) { |
| 473 | ab.setTitle(displayName); |
| 474 | ab.setSubtitle(username); |
| 475 | } else { |
| 476 | ab.setTitle(username); |
| 477 | ab.setSubtitle(null); |
| 478 | } |
| 479 | ab.setDisplayShowTitleEnabled(true); |
| 480 | } |
| 481 | } |
| 482 | |
Adrien Béraud | afcdd96 | 2018-07-06 21:38:41 -0400 | [diff] [blame] | 483 | if (hasProfileName) { |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 484 | binding.contactBubbleNumTxt.setVisibility(View.VISIBLE); |
| 485 | binding.contactBubbleTxt.setText(displayName); |
| 486 | binding.contactBubbleNumTxt.setText(username); |
Adrien Béraud | afcdd96 | 2018-07-06 21:38:41 -0400 | [diff] [blame] | 487 | } else { |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 488 | binding.contactBubbleNumTxt.setVisibility(View.GONE); |
| 489 | binding.contactBubbleTxt.setText(username); |
Adrien Béraud | afcdd96 | 2018-07-06 21:38:41 -0400 | [diff] [blame] | 490 | } |
Adrien Béraud | 5f8c3f7 | 2018-03-09 14:49:39 -0500 | [diff] [blame] | 491 | |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 492 | binding.contactBubble.setImageDrawable(new AvatarDrawable(getActivity(), contact)); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | @Override |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 496 | public void updateCallStatus(final SipCall.State callState) { |
Adrien Béraud | 3f9f6cd | 2018-12-12 15:05:28 -0500 | [diff] [blame] | 497 | switch (callState) { |
| 498 | case NONE: |
| 499 | binding.callStatusTxt.setText(""); |
| 500 | break; |
| 501 | default: |
| 502 | binding.callStatusTxt.setText(callStateToHumanState(callState)); |
| 503 | break; |
| 504 | } |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | @Override |
| 508 | public void initMenu(boolean isSpeakerOn, boolean hasContact, boolean displayFlip, boolean canDial, boolean onGoingCall) { |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 509 | if (binding.callCameraFlipBtn != null) { |
| 510 | binding.callCameraFlipBtn.setVisibility(displayFlip ? View.VISIBLE : View.GONE); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 511 | } |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 512 | if (dialPadBtn != null) { |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 513 | dialPadBtn.setVisible(canDial); |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 514 | } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | @Override |
Adrien Béraud | ec19fad | 2018-12-30 16:51:05 -0500 | [diff] [blame] | 518 | public void initNormalStateDisplay(final boolean audioOnly, boolean isSpeakerphoneOn, boolean isMuted) { |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 519 | binding.shapeRipple.stopRipple(); |
Pierre Duchemin | bb83367 | 2018-03-09 16:18:33 -0500 | [diff] [blame] | 520 | |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 521 | binding.callAcceptBtn.setVisibility(View.GONE); |
| 522 | binding.callRefuseBtn.setVisibility(View.GONE); |
| 523 | binding.callControlGroup.setVisibility(View.VISIBLE); |
| 524 | binding.callHangupBtn.setVisibility(View.VISIBLE); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 525 | |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 526 | binding.contactBubbleLayout.setVisibility(audioOnly ? View.VISIBLE : View.GONE); |
| 527 | binding.callSpeakerBtn.setChecked(isSpeakerphoneOn); |
Adrien Béraud | ec19fad | 2018-12-30 16:51:05 -0500 | [diff] [blame] | 528 | binding.callMicBtn.setChecked(isMuted); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 529 | |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 530 | requireActivity().invalidateOptionsMenu(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | @Override |
| 534 | public void initIncomingCallDisplay() { |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 535 | binding.callAcceptBtn.setVisibility(View.VISIBLE); |
| 536 | binding.callRefuseBtn.setVisibility(View.VISIBLE); |
| 537 | binding.callControlGroup.setVisibility(View.GONE); |
| 538 | binding.callHangupBtn.setVisibility(View.GONE); |
Hadrien De Sousa | 841d15a | 2017-06-02 11:52:10 -0400 | [diff] [blame] | 539 | |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 540 | binding.contactBubbleLayout.setVisibility(View.VISIBLE); |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 541 | requireActivity().invalidateOptionsMenu(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | @Override |
| 545 | public void initOutGoingCallDisplay() { |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 546 | binding.callAcceptBtn.setVisibility(View.GONE); |
| 547 | binding.callRefuseBtn.setVisibility(View.VISIBLE); |
| 548 | binding.callControlGroup.setVisibility(View.GONE); |
| 549 | binding.callHangupBtn.setVisibility(View.GONE); |
Hadrien De Sousa | 841d15a | 2017-06-02 11:52:10 -0400 | [diff] [blame] | 550 | |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 551 | binding.contactBubbleLayout.setVisibility(View.VISIBLE); |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 552 | requireActivity().invalidateOptionsMenu(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | @Override |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 556 | public void resetPreviewVideoSize(int previewWidth, int previewHeight, int rot) { |
| 557 | if (previewWidth == -1 && previewHeight == -1) |
| 558 | return; |
| 559 | mPreviewWidth = previewWidth; |
| 560 | mPreviewHeight = previewHeight; |
| 561 | boolean flip = (rot % 180) != 0; |
| 562 | binding.previewSurface.setAspectRatio(flip ? mPreviewHeight : mPreviewWidth, flip ? mPreviewWidth : mPreviewHeight); |
| 563 | } |
| 564 | |
| 565 | @Override |
| 566 | public void resetVideoSize(int videoWidth, int videoHeight) { |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 567 | ViewGroup rootView = (ViewGroup) getView(); |
| 568 | if (rootView == null) |
| 569 | return; |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 570 | double videoRatio = videoWidth / (double) videoHeight; |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 571 | double screenRatio = rootView.getWidth() / (double) rootView.getHeight(); |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 572 | RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) binding.videoSurface.getLayoutParams(); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 573 | int oldW = params.width; |
| 574 | int oldH = params.height; |
| 575 | if (videoRatio >= screenRatio) { |
| 576 | params.width = RelativeLayout.LayoutParams.MATCH_PARENT; |
| 577 | params.height = (int) (videoHeight * (double) rootView.getWidth() / (double) videoWidth); |
| 578 | } else { |
| 579 | params.height = RelativeLayout.LayoutParams.MATCH_PARENT; |
| 580 | params.width = (int) (videoWidth * (double) rootView.getHeight() / (double) videoHeight); |
| 581 | } |
Thibault Wittemberg | b328050 | 2016-12-16 17:34:53 -0500 | [diff] [blame] | 582 | |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 583 | if (oldW != params.width || oldH != params.height) { |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 584 | binding.videoSurface.setLayoutParams(params); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 585 | } |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 586 | mVideoWidth = videoWidth; |
| 587 | mVideoHeight = videoHeight; |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 588 | } |
Adrien Béraud | 30532a5 | 2018-09-11 15:10:05 -0400 | [diff] [blame] | 589 | |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 590 | private void configureTransform(int viewWidth, int viewHeight) { |
| 591 | Activity activity = getActivity(); |
Adrien Béraud | 3f9f6cd | 2018-12-12 15:05:28 -0500 | [diff] [blame] | 592 | if (null == binding.previewSurface || null == activity) { |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 593 | return; |
Adrien Béraud | 30532a5 | 2018-09-11 15:10:05 -0400 | [diff] [blame] | 594 | } |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 595 | int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); |
| 596 | boolean rot = Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation; |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 597 | // Log.w(TAG, "configureTransform " + viewWidth + "x" + viewHeight + " rot=" + rot + " mPreviewWidth=" + mPreviewWidth + " mPreviewHeight=" + mPreviewHeight); |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 598 | Matrix matrix = new Matrix(); |
| 599 | RectF viewRect = new RectF(0, 0, viewWidth, viewHeight); |
| 600 | float centerX = viewRect.centerX(); |
| 601 | float centerY = viewRect.centerY(); |
| 602 | if (rot) { |
| 603 | RectF bufferRect = new RectF(0, 0, mPreviewHeight, mPreviewWidth); |
| 604 | bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY()); |
| 605 | matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL); |
| 606 | float scale = Math.max( |
| 607 | (float) viewHeight / mPreviewHeight, |
| 608 | (float) viewWidth / mPreviewWidth); |
| 609 | matrix.postScale(scale, scale, centerX, centerY); |
| 610 | matrix.postRotate(90 * (rotation - 2), centerX, centerY); |
| 611 | } else if (Surface.ROTATION_180 == rotation) { |
| 612 | matrix.postRotate(180, centerX, centerY); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 613 | } |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 614 | binding.previewSurface.setTransform(matrix); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | @Override |
Hadrien De Sousa | 0dc8316 | 2017-11-10 16:15:18 -0500 | [diff] [blame] | 618 | public void goToConversation(String accountId, String conversationId) { |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 619 | Intent intent = new Intent(); |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 620 | if (DeviceUtils.isTablet(requireActivity())) { |
| 621 | intent.setClass(requireActivity(), HomeActivity.class) |
Alexandre Lision | 5da46fa | 2017-08-09 10:25:50 -0400 | [diff] [blame] | 622 | .setAction(DRingService.ACTION_CONV_ACCEPT) |
Hadrien De Sousa | 0dc8316 | 2017-11-10 16:15:18 -0500 | [diff] [blame] | 623 | .putExtra(ConversationFragment.KEY_CONTACT_RING_ID, conversationId); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 624 | startActivity(intent); |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 625 | } else { |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 626 | intent.setClass(requireActivity(), ConversationActivity.class) |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 627 | .setAction(Intent.ACTION_VIEW) |
| 628 | .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP) |
Hadrien De Sousa | 0dc8316 | 2017-11-10 16:15:18 -0500 | [diff] [blame] | 629 | .putExtra(ConversationFragment.KEY_ACCOUNT_ID, accountId) |
| 630 | .putExtra(ConversationFragment.KEY_CONTACT_RING_ID, conversationId); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 631 | startActivityForResult(intent, HomeActivity.REQUEST_CODE_CONVERSATION); |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 632 | } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 633 | } |
| 634 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 635 | @Override |
| 636 | public void goToAddContact(CallContact callContact) { |
| 637 | startActivityForResult(ActionHelper.getAddNumberIntentForContact(callContact), |
| 638 | ConversationFragment.REQ_ADD_CONTACT); |
| 639 | } |
| 640 | |
| 641 | @Override |
| 642 | public void finish() { |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame^] | 643 | Activity activity = getActivity(); |
| 644 | if (activity != null) |
| 645 | activity.finish(); |
Alexandre Lision | 1532d95 | 2016-11-17 09:41:00 -0500 | [diff] [blame] | 646 | } |
| 647 | |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 648 | public void speakerClicked() { |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 649 | presenter.speakerClick(binding.callSpeakerBtn.isChecked()); |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 650 | } |
| 651 | |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 652 | public void micClicked() { |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 653 | presenter.muteMicrophoneToggled(binding.callMicBtn.isChecked()); |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 654 | } |
| 655 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 656 | public void hangUpClicked() { |
Hadrien De Sousa | f5774ee | 2017-05-17 14:04:17 -0400 | [diff] [blame] | 657 | presenter.hangupCall(); |
Alexandre Lision | 1532d95 | 2016-11-17 09:41:00 -0500 | [diff] [blame] | 658 | } |
| 659 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 660 | public void refuseClicked() { |
Hadrien De Sousa | f5774ee | 2017-05-17 14:04:17 -0400 | [diff] [blame] | 661 | presenter.refuseCall(); |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 662 | } |
| 663 | |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 664 | public void acceptClicked() { |
Hadrien De Sousa | f5774ee | 2017-05-17 14:04:17 -0400 | [diff] [blame] | 665 | presenter.acceptCall(); |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 666 | } |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 667 | |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 668 | public void cameraFlip() { |
| 669 | presenter.switchVideoInputClick(); |
| 670 | } |
| 671 | |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 672 | @Override |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 673 | public void positiveMediaButtonClicked() { |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 674 | presenter.positiveButtonClicked(); |
| 675 | } |
| 676 | |
| 677 | @Override |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 678 | public void negativeMediaButtonClicked() { |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 679 | presenter.negativeButtonClicked(); |
| 680 | } |
| 681 | |
| 682 | @Override |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 683 | public void toggleMediaButtonClicked() { |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 684 | presenter.toggleButtonClicked(); |
| 685 | } |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 686 | } |