Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 1 | /* |
Adrien Béraud | e552f69 | 2020-11-03 14:30:52 -0500 | [diff] [blame] | 2 | * Copyright (C) 2004-2020 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 | |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 23 | import android.Manifest; |
Adrien Béraud | 2d50acb | 2020-03-23 22:02:15 -0400 | [diff] [blame] | 24 | import android.animation.ValueAnimator; |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 25 | import android.annotation.SuppressLint; |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 26 | import android.app.Activity; |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 27 | import android.app.PendingIntent; |
| 28 | import android.app.PictureInPictureParams; |
| 29 | import android.app.RemoteAction; |
Rayan Osseiran | f7dfe23 | 2019-06-06 10:26:10 -0400 | [diff] [blame] | 30 | import android.content.ComponentName; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 31 | import android.content.Context; |
| 32 | import android.content.Intent; |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 33 | import android.content.pm.PackageManager; |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 34 | import android.content.res.Configuration; |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 35 | import android.graphics.Matrix; |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 36 | import android.graphics.PixelFormat; |
Adrien Béraud | 2d50acb | 2020-03-23 22:02:15 -0400 | [diff] [blame] | 37 | import android.graphics.PointF; |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 38 | import android.graphics.Rect; |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 39 | import android.graphics.RectF; |
| 40 | import android.graphics.SurfaceTexture; |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 41 | import android.graphics.drawable.Drawable; |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 42 | import android.graphics.drawable.Icon; |
Adrien Béraud | ade9bee | 2019-12-02 17:13:26 -0500 | [diff] [blame] | 43 | import android.media.projection.MediaProjection; |
| 44 | import android.media.projection.MediaProjectionManager; |
Adrien Béraud | 8d6a483 | 2016-04-12 18:06:11 -0400 | [diff] [blame] | 45 | import android.os.Build; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 46 | import android.os.Bundle; |
| 47 | import android.os.PowerManager; |
Adrien Béraud | bcbb4d4 | 2018-12-08 16:06:39 -0500 | [diff] [blame] | 48 | import android.text.Editable; |
Adrien Béraud | 34915fb | 2020-08-24 17:12:03 -0400 | [diff] [blame] | 49 | import android.text.TextUtils; |
Adrien Béraud | bcbb4d4 | 2018-12-08 16:06:39 -0500 | [diff] [blame] | 50 | import android.text.TextWatcher; |
Adrien Béraud | 34915fb | 2020-08-24 17:12:03 -0400 | [diff] [blame] | 51 | import android.util.Log; |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 52 | import android.util.Rational; |
Pierre Duchemin | 37d0b3e | 2020-05-14 18:56:21 -0400 | [diff] [blame] | 53 | import android.view.Gravity; |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 54 | import android.view.LayoutInflater; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 55 | import android.view.Menu; |
| 56 | import android.view.MenuInflater; |
| 57 | import android.view.MenuItem; |
Adrien Béraud | 2d50acb | 2020-03-23 22:02:15 -0400 | [diff] [blame] | 58 | import android.view.MotionEvent; |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 59 | import android.view.OrientationEventListener; |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 60 | import android.view.Surface; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 61 | import android.view.SurfaceHolder; |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 62 | import android.view.TextureView; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 63 | import android.view.View; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 64 | import android.view.ViewGroup; |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 65 | import android.view.WindowManager; |
Adrien Béraud | 2d50acb | 2020-03-23 22:02:15 -0400 | [diff] [blame] | 66 | import android.view.animation.DecelerateInterpolator; |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 67 | import android.view.inputmethod.InputMethodManager; |
Pierre Duchemin | 37d0b3e | 2020-05-14 18:56:21 -0400 | [diff] [blame] | 68 | import android.widget.FrameLayout; |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 69 | import android.widget.LinearLayout; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 70 | import android.widget.RelativeLayout; |
Adrien Béraud | 20bd723 | 2020-03-16 11:33:23 -0400 | [diff] [blame] | 71 | import android.widget.Toast; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 72 | |
Rayan Osseiran | 3dd0466 | 2019-06-28 16:47:48 -0400 | [diff] [blame] | 73 | import androidx.annotation.NonNull; |
| 74 | import androidx.annotation.Nullable; |
| 75 | import androidx.appcompat.app.ActionBar; |
| 76 | import androidx.appcompat.app.AppCompatActivity; |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 77 | import androidx.appcompat.view.menu.MenuBuilder; |
| 78 | import androidx.appcompat.view.menu.MenuPopupHelper; |
| 79 | import androidx.appcompat.widget.PopupMenu; |
Rayan Osseiran | 3dd0466 | 2019-06-28 16:47:48 -0400 | [diff] [blame] | 80 | import androidx.databinding.DataBindingUtil; |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 81 | import androidx.fragment.app.FragmentActivity; |
Adrien Béraud | 34915fb | 2020-08-24 17:12:03 -0400 | [diff] [blame] | 82 | import androidx.percentlayout.widget.PercentFrameLayout; |
Rayan Osseiran | 3dd0466 | 2019-06-28 16:47:48 -0400 | [diff] [blame] | 83 | |
Pierre Duchemin | bb83367 | 2018-03-09 16:18:33 -0500 | [diff] [blame] | 84 | import com.rodolfonavalon.shaperipplelibrary.model.Circle; |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 85 | |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 86 | import java.util.ArrayList; |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 87 | import java.util.List; |
Romain Bertozzi | 64a6678 | 2016-08-02 12:10:38 -0400 | [diff] [blame] | 88 | import java.util.Locale; |
ayounes | 8108747 | 2019-11-08 15:26:05 -0500 | [diff] [blame] | 89 | import java.util.Map; |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 90 | import java.util.Random; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 91 | |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 92 | import javax.inject.Inject; |
| 93 | |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 94 | import cx.ring.R; |
Adrien Béraud | a0226ff | 2019-11-21 15:24:42 -0500 | [diff] [blame] | 95 | import cx.ring.adapters.ConfParticipantAdapter; |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 96 | import cx.ring.application.JamiApplication; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 97 | import cx.ring.call.CallPresenter; |
| 98 | import cx.ring.call.CallView; |
Rayan Osseiran | 3dd0466 | 2019-06-28 16:47:48 -0400 | [diff] [blame] | 99 | import cx.ring.client.CallActivity; |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 100 | import cx.ring.client.ContactDetailsActivity; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 101 | import cx.ring.client.ConversationActivity; |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 102 | import cx.ring.client.ConversationSelectionActivity; |
Thibault Wittemberg | 4f33d07 | 2016-10-06 17:11:41 -0400 | [diff] [blame] | 103 | import cx.ring.client.HomeActivity; |
ayounes | 019267f | 2020-01-13 15:14:08 -0500 | [diff] [blame] | 104 | import cx.ring.daemon.Ringservice; |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 105 | import cx.ring.databinding.FragCallBinding; |
Adrien Béraud | 34915fb | 2020-08-24 17:12:03 -0400 | [diff] [blame] | 106 | import cx.ring.databinding.ItemParticipantLabelBinding; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 107 | import cx.ring.model.CallContact; |
Adrien Béraud | 34915fb | 2020-08-24 17:12:03 -0400 | [diff] [blame] | 108 | import cx.ring.model.Conference; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 109 | import cx.ring.model.SipCall; |
Adrien Béraud | a373e3b | 2018-12-12 11:14:50 -0500 | [diff] [blame] | 110 | import cx.ring.mvp.BaseSupportFragment; |
ayounes | c6c2c01 | 2019-11-11 11:09:51 -0500 | [diff] [blame] | 111 | import cx.ring.plugins.RecyclerPicker.RecyclerPicker; |
| 112 | import cx.ring.plugins.RecyclerPicker.RecyclerPickerLayoutManager; |
Alexandre Lision | 5da46fa | 2017-08-09 10:25:50 -0400 | [diff] [blame] | 113 | import cx.ring.service.DRingService; |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 114 | import cx.ring.services.DeviceRuntimeService; |
Adrien Béraud | 34a6fa2 | 2019-07-28 16:02:59 -0400 | [diff] [blame] | 115 | import cx.ring.services.HardwareService; |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 116 | import cx.ring.services.NotificationService; |
Alexandre Lision | 4865f7d | 2016-11-16 18:03:35 -0500 | [diff] [blame] | 117 | import cx.ring.utils.ActionHelper; |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 118 | import cx.ring.utils.ContentUriHandler; |
| 119 | import cx.ring.utils.ConversationPath; |
Pierre Duchemin | 42788c3 | 2018-03-08 16:21:15 -0500 | [diff] [blame] | 120 | import cx.ring.utils.DeviceUtils; |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 121 | import cx.ring.utils.KeyboardVisibilityManager; |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 122 | import cx.ring.utils.MediaButtonsHelper; |
Aline Gondim Santos | f781c5b | 2020-06-26 12:44:44 -0400 | [diff] [blame] | 123 | import cx.ring.utils.StringUtils; |
Adrien Béraud | 8f9d270 | 2018-09-16 18:24:01 -0400 | [diff] [blame] | 124 | import cx.ring.views.AvatarDrawable; |
Adrien Béraud | 2c378b3 | 2018-07-11 15:24:02 -0400 | [diff] [blame] | 125 | import io.reactivex.disposables.CompositeDisposable; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 126 | |
agsantos | 00e3a9d | 2020-07-06 15:08:43 -0400 | [diff] [blame] | 127 | import static cx.ring.daemon.Ringservice.getPluginsEnabled; |
agsantos | 00e3a9d | 2020-07-06 15:08:43 -0400 | [diff] [blame] | 128 | |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 129 | public class CallFragment extends BaseSupportFragment<CallPresenter> implements CallView, MediaButtonsHelper.MediaButtonsHelperCallback, RecyclerPickerLayoutManager.ItemSelectedListener { |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 130 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 131 | public static final String TAG = CallFragment.class.getSimpleName(); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 132 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 133 | public static final String ACTION_PLACE_CALL = "PLACE_CALL"; |
| 134 | public static final String ACTION_GET_CALL = "GET_CALL"; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 135 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 136 | public static final String KEY_ACTION = "action"; |
| 137 | public static final String KEY_ACCOUNT_ID = "accountId"; |
| 138 | public static final String KEY_CONF_ID = "confId"; |
Hadrien De Sousa | 203164c | 2017-12-05 17:41:42 -0500 | [diff] [blame] | 139 | public static final String KEY_AUDIO_ONLY = "AUDIO_ONLY"; |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 140 | |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 141 | private static final int REQUEST_CODE_ADD_PARTICIPANT = 6; |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 142 | private static final int REQUEST_PERMISSION_INCOMING = 1003; |
| 143 | private static final int REQUEST_PERMISSION_OUTGOING = 1004; |
Adrien Béraud | ade9bee | 2019-12-02 17:13:26 -0500 | [diff] [blame] | 144 | private static final int REQUEST_CODE_SCREEN_SHARE = 7; |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 145 | |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 146 | private FragCallBinding binding; |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 147 | private OrientationEventListener mOrientationListener; |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 148 | |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 149 | private MenuItem dialPadBtn = null; |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 150 | private MenuItem pluginsMenuBtn = null; |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 151 | private boolean restartVideo = false; |
Rayan Osseiran | c1532d4 | 2019-06-05 13:17:53 -0400 | [diff] [blame] | 152 | private boolean restartPreview = false; |
Rayan Osseiran | de9ac14 | 2019-07-02 13:01:32 -0400 | [diff] [blame] | 153 | private PowerManager.WakeLock mScreenWakeLock = null; |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 154 | private int mCurrentOrientation = 0; |
| 155 | |
| 156 | private int mVideoWidth = -1; |
| 157 | private int mVideoHeight = -1; |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 158 | private int mPreviewWidth = 720, mPreviewHeight = 1280; |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 159 | private int mPreviewSurfaceWidth = 0, mPreviewSurfaceHeight = 0; |
Adrien Béraud | 8d6a483 | 2016-04-12 18:06:11 -0400 | [diff] [blame] | 160 | |
Adrien Béraud | ade9bee | 2019-12-02 17:13:26 -0500 | [diff] [blame] | 161 | private MediaProjectionManager mProjectionManager; |
| 162 | |
Rayan Osseiran | f7dfe23 | 2019-06-06 10:26:10 -0400 | [diff] [blame] | 163 | private boolean mBackstackLost = false; |
| 164 | |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 165 | private ConfParticipantAdapter confAdapter = null; |
| 166 | private boolean mConferenceMode = false; |
agsantos | a6d68a8 | 2020-07-09 11:33:30 -0400 | [diff] [blame] | 167 | private boolean choosePluginMode = false; |
| 168 | public boolean isChoosePluginMode() { |
| 169 | return choosePluginMode; |
| 170 | } |
ayounes | 8108747 | 2019-11-08 15:26:05 -0500 | [diff] [blame] | 171 | private boolean pluginsModeFirst = true; |
ayounes | 019267f | 2020-01-13 15:14:08 -0500 | [diff] [blame] | 172 | private List<String> callMediaHandlers; |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 173 | private int previousPluginPosition = -1; |
| 174 | private RecyclerPicker rp; |
ayounes | c6c2c01 | 2019-11-11 11:09:51 -0500 | [diff] [blame] | 175 | private final ValueAnimator animation = new ValueAnimator(); |
| 176 | |
Adrien Béraud | 2d50acb | 2020-03-23 22:02:15 -0400 | [diff] [blame] | 177 | private PointF previewDrag = null; |
| 178 | private final ValueAnimator previewSnapAnimation = new ValueAnimator(); |
| 179 | private final int[] previewMargins = new int[4]; |
Pierre Duchemin | 37d0b3e | 2020-05-14 18:56:21 -0400 | [diff] [blame] | 180 | private float previewHiddenState = 0; |
| 181 | private enum PreviewPosition {LEFT, RIGHT} |
| 182 | private PreviewPosition previewPosition = PreviewPosition.RIGHT; |
Adrien Béraud | 2d50acb | 2020-03-23 22:02:15 -0400 | [diff] [blame] | 183 | |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 184 | @Inject |
| 185 | DeviceRuntimeService mDeviceRuntimeService; |
| 186 | |
Adrien Béraud | 2c378b3 | 2018-07-11 15:24:02 -0400 | [diff] [blame] | 187 | private final CompositeDisposable mCompositeDisposable = new CompositeDisposable(); |
| 188 | |
Hadrien De Sousa | 203164c | 2017-12-05 17:41:42 -0500 | [diff] [blame] | 189 | 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] | 190 | Bundle bundle = new Bundle(); |
| 191 | bundle.putString(KEY_ACTION, action); |
| 192 | bundle.putString(KEY_ACCOUNT_ID, accountID); |
Hadrien De Sousa | 0dc8316 | 2017-11-10 16:15:18 -0500 | [diff] [blame] | 193 | bundle.putString(ConversationFragment.KEY_CONTACT_RING_ID, contactRingId); |
Hadrien De Sousa | 203164c | 2017-12-05 17:41:42 -0500 | [diff] [blame] | 194 | bundle.putBoolean(KEY_AUDIO_ONLY, audioOnly); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 195 | CallFragment countDownFragment = new CallFragment(); |
| 196 | countDownFragment.setArguments(bundle); |
| 197 | return countDownFragment; |
| 198 | } |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 199 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 200 | public static CallFragment newInstance(@NonNull String action, @Nullable String confId) { |
| 201 | Bundle bundle = new Bundle(); |
| 202 | bundle.putString(KEY_ACTION, action); |
| 203 | bundle.putString(KEY_CONF_ID, confId); |
| 204 | CallFragment countDownFragment = new CallFragment(); |
| 205 | countDownFragment.setArguments(bundle); |
| 206 | return countDownFragment; |
| 207 | } |
| 208 | |
Rayan Osseiran | 6f41566 | 2019-10-25 14:23:25 -0400 | [diff] [blame] | 209 | public static int callStateToHumanState(final SipCall.CallStatus state) { |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 210 | switch (state) { |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 211 | case SEARCHING: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 212 | return R.string.call_human_state_searching; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 213 | case CONNECTING: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 214 | return R.string.call_human_state_connecting; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 215 | case RINGING: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 216 | return R.string.call_human_state_ringing; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 217 | case CURRENT: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 218 | return R.string.call_human_state_current; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 219 | case HUNGUP: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 220 | return R.string.call_human_state_hungup; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 221 | case BUSY: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 222 | return R.string.call_human_state_busy; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 223 | case FAILURE: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 224 | return R.string.call_human_state_failure; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 225 | case HOLD: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 226 | return R.string.call_human_state_hold; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 227 | case UNHOLD: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 228 | return R.string.call_human_state_unhold; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 229 | case OVER: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 230 | return R.string.call_human_state_over; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 231 | case NONE: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 232 | default: |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 233 | return R.string.call_human_state_none; |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 234 | } |
| 235 | } |
| 236 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 237 | @Override |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 238 | protected void initPresenter(CallPresenter presenter) { |
| 239 | super.initPresenter(presenter); |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 240 | Bundle args = getArguments(); |
| 241 | if (args != null) { |
| 242 | String action = args.getString(KEY_ACTION); |
| 243 | if (action != null) { |
| 244 | if (action.equals(ACTION_PLACE_CALL)) { |
Rayan Osseiran | 3dd0466 | 2019-06-28 16:47:48 -0400 | [diff] [blame] | 245 | prepareCall(false); |
Pierre Duchemin | 37d0b3e | 2020-05-14 18:56:21 -0400 | [diff] [blame] | 246 | } else if (action.equals(ACTION_GET_CALL) || action.equals(CallActivity.ACTION_CALL_ACCEPT)) { |
Rayan Osseiran | ed9feeb | 2019-07-05 16:04:30 -0400 | [diff] [blame] | 247 | presenter.initIncomingCall(getArguments().getString(KEY_CONF_ID), action.equals(ACTION_GET_CALL)); |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 248 | } |
Pierre Duchemin | 45707ca | 2018-01-15 15:05:23 -0500 | [diff] [blame] | 249 | } |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 250 | } |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 251 | } |
| 252 | |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 253 | public void onUserLeave() { |
| 254 | presenter.requestPipMode(); |
| 255 | } |
| 256 | |
| 257 | @Override |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 258 | public void enterPipMode(String callId) { |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 259 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { |
| 260 | return; |
| 261 | } |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 262 | Context context = requireContext(); |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 263 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
| 264 | PictureInPictureParams.Builder paramBuilder = new PictureInPictureParams.Builder(); |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 265 | if (binding.videoSurface.getVisibility() == View.VISIBLE) { |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 266 | int[] l = new int[2]; |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 267 | binding.videoSurface.getLocationInWindow(l); |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 268 | int x = l[0]; |
| 269 | int y = l[1]; |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 270 | int w = binding.videoSurface.getWidth(); |
| 271 | int h = binding.videoSurface.getHeight(); |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 272 | Rect videoBounds = new Rect(x, y, x + w, y + h); |
| 273 | paramBuilder.setAspectRatio(new Rational(w, h)); |
| 274 | paramBuilder.setSourceRectHint(videoBounds); |
| 275 | } |
| 276 | ArrayList<RemoteAction> actions = new ArrayList<>(1); |
| 277 | actions.add(new RemoteAction( |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 278 | Icon.createWithResource(context, R.drawable.baseline_call_end_24), |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 279 | getString(R.string.action_call_hangup), |
| 280 | getString(R.string.action_call_hangup), |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 281 | PendingIntent.getService(context, new Random().nextInt(), |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 282 | new Intent(DRingService.ACTION_CALL_END) |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 283 | .setClass(context, DRingService.class) |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 284 | .putExtra(NotificationService.KEY_CALL_ID, callId), PendingIntent.FLAG_ONE_SHOT))); |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 285 | paramBuilder.setActions(actions); |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 286 | requireActivity().enterPictureInPictureMode(paramBuilder.build()); |
| 287 | } else if (DeviceUtils.isTv(context)) { |
| 288 | requireActivity().enterPictureInPictureMode(); |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 289 | } |
| 290 | } |
| 291 | |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 292 | @Override |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 293 | public void onStart() { |
| 294 | super.onStart(); |
Rayan Osseiran | c1532d4 | 2019-06-05 13:17:53 -0400 | [diff] [blame] | 295 | if (restartVideo && restartPreview) { |
| 296 | displayVideoSurface(true, !presenter.isPipMode()); |
| 297 | restartVideo = false; |
| 298 | restartPreview = false; |
Rayan Osseiran | f7dfe23 | 2019-06-06 10:26:10 -0400 | [diff] [blame] | 299 | } else if (restartVideo) { |
Rayan Osseiran | c1532d4 | 2019-06-05 13:17:53 -0400 | [diff] [blame] | 300 | displayVideoSurface(true, false); |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 301 | restartVideo = false; |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | @Override |
| 306 | public void onStop() { |
| 307 | super.onStop(); |
Adrien Béraud | 7b7e2ca | 2020-12-10 11:18:19 -0500 | [diff] [blame] | 308 | previewSnapAnimation.cancel(); |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 309 | if (binding.videoSurface.getVisibility() == View.VISIBLE) { |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 310 | restartVideo = true; |
| 311 | } |
agsantos | a6d68a8 | 2020-07-09 11:33:30 -0400 | [diff] [blame] | 312 | if (!choosePluginMode) { |
AGS5 | ef482ce | 2020-06-12 13:28:51 -0400 | [diff] [blame] | 313 | if (binding.previewContainer.getVisibility() == View.VISIBLE) { |
| 314 | restartPreview = true; |
| 315 | } |
| 316 | }else { |
| 317 | if (binding.pluginPreviewContainer.getVisibility() == View.VISIBLE) { |
| 318 | restartPreview = true; |
agsantos | 4f7b5a1 | 2020-07-08 16:18:07 -0400 | [diff] [blame] | 319 | presenter.stopPlugin(); |
AGS5 | ef482ce | 2020-06-12 13:28:51 -0400 | [diff] [blame] | 320 | } |
Rayan Osseiran | c1532d4 | 2019-06-05 13:17:53 -0400 | [diff] [blame] | 321 | } |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 322 | } |
| 323 | |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 324 | @Nullable |
| 325 | @Override |
Adrien Béraud | c14d55d | 2019-01-02 16:33:40 -0500 | [diff] [blame] | 326 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { |
Adrien Béraud | 7307cd5 | 2020-04-13 23:29:11 -0400 | [diff] [blame] | 327 | ((JamiApplication) requireActivity().getApplication()).getInjectionComponent().inject(this); |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 328 | binding = DataBindingUtil.inflate(inflater, R.layout.frag_call, container, false); |
| 329 | binding.setPresenter(this); |
Adrien Béraud | 496e49a | 2020-08-13 22:31:05 -0400 | [diff] [blame] | 330 | rp = new RecyclerPicker(binding.recyclerPicker, |
ayounes | c6c2c01 | 2019-11-11 11:09:51 -0500 | [diff] [blame] | 331 | R.layout.item_picker, |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 332 | LinearLayout.HORIZONTAL, this); |
ayounes | c6c2c01 | 2019-11-11 11:09:51 -0500 | [diff] [blame] | 333 | rp.setFirstLastElementsWidths(112, 112); |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 334 | return binding.getRoot(); |
| 335 | } |
| 336 | |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 337 | private TextureView.SurfaceTextureListener listener = new TextureView.SurfaceTextureListener() { |
| 338 | @Override |
| 339 | public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 340 | mPreviewSurfaceWidth = width; |
| 341 | mPreviewSurfaceHeight = height; |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 342 | presenter.previewVideoSurfaceCreated(binding.previewSurface); |
| 343 | } |
| 344 | |
| 345 | @Override |
| 346 | public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 347 | mPreviewSurfaceWidth = width; |
| 348 | mPreviewSurfaceHeight = height; |
Pierre Duchemin | 7c125f7 | 2020-05-29 15:23:53 -0400 | [diff] [blame] | 349 | configurePreview(width, 1); |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | @Override |
| 353 | public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { |
| 354 | presenter.previewVideoSurfaceDestroyed(); |
| 355 | return true; |
| 356 | } |
| 357 | |
| 358 | @Override |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 359 | public void onSurfaceTextureUpdated(SurfaceTexture surface) { |
| 360 | } |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 361 | }; |
| 362 | |
Pierre Duchemin | 37d0b3e | 2020-05-14 18:56:21 -0400 | [diff] [blame] | 363 | /** |
| 364 | * @param hiddenState 0.f if fully shown, 1.f if fully hidden. |
| 365 | */ |
| 366 | private void setPreviewDragHiddenState(float hiddenState) { |
| 367 | binding.previewSurface.setAlpha(1.f - (3 * hiddenState / 4)); |
AGS5 | ef482ce | 2020-06-12 13:28:51 -0400 | [diff] [blame] | 368 | binding.pluginPreviewSurface.setAlpha(1.f - (3 * hiddenState / 4)); |
Pierre Duchemin | 37d0b3e | 2020-05-14 18:56:21 -0400 | [diff] [blame] | 369 | binding.previewHandle.setAlpha(hiddenState); |
AGS5 | ef482ce | 2020-06-12 13:28:51 -0400 | [diff] [blame] | 370 | binding.pluginPreviewHandle.setAlpha(hiddenState); |
Pierre Duchemin | 37d0b3e | 2020-05-14 18:56:21 -0400 | [diff] [blame] | 371 | } |
| 372 | |
Adrien Béraud | 2d50acb | 2020-03-23 22:02:15 -0400 | [diff] [blame] | 373 | @SuppressLint("ClickableViewAccessibility") |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 374 | @Override |
Adrien Béraud | c14d55d | 2019-01-02 16:33:40 -0500 | [diff] [blame] | 375 | public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 376 | setHasOptionsMenu(true); |
Hadrien De Sousa | 73d6dd7 | 2017-09-07 10:54:51 -0400 | [diff] [blame] | 377 | super.onViewCreated(view, savedInstanceState); |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 378 | mCurrentOrientation = getResources().getConfiguration().orientation; |
ayounes | c6c2c01 | 2019-11-11 11:09:51 -0500 | [diff] [blame] | 379 | float dpRatio = requireActivity().getResources().getDisplayMetrics().density; |
| 380 | |
| 381 | animation.setDuration(150); |
| 382 | animation.addUpdateListener(valueAnimator -> { |
Adrien Béraud | b46fd32 | 2020-09-02 17:18:28 -0400 | [diff] [blame] | 383 | if (binding == null) |
| 384 | return; |
ayounes | c6c2c01 | 2019-11-11 11:09:51 -0500 | [diff] [blame] | 385 | int upBy = (int) valueAnimator.getAnimatedValue(); |
| 386 | RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) binding.previewContainer.getLayoutParams(); |
| 387 | layoutParams.setMargins(0, 0, 0, (int) (upBy * dpRatio)); |
| 388 | binding.previewContainer.setLayoutParams(layoutParams); |
| 389 | }); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 390 | |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 391 | FragmentActivity activity = getActivity(); |
| 392 | if (activity != null) { |
| 393 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); |
| 394 | if (activity instanceof AppCompatActivity) { |
| 395 | AppCompatActivity ac_activity = (AppCompatActivity) activity; |
| 396 | ActionBar ab = ac_activity.getSupportActionBar(); |
| 397 | if (ab != null) { |
| 398 | ab.setHomeAsUpIndicator(R.drawable.baseline_chat_24); |
| 399 | ab.setDisplayHomeAsUpEnabled(true); |
| 400 | } |
| 401 | } |
| 402 | } |
| 403 | |
Adrien Béraud | ade9bee | 2019-12-02 17:13:26 -0500 | [diff] [blame] | 404 | mProjectionManager = (MediaProjectionManager) requireContext().getSystemService(Context.MEDIA_PROJECTION_SERVICE); |
| 405 | |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 406 | PowerManager powerManager = (PowerManager) requireContext().getSystemService(Context.POWER_SERVICE); |
| 407 | if (powerManager != null) { |
| 408 | mScreenWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "ring:callLock"); |
| 409 | mScreenWakeLock.setReferenceCounted(false); |
| 410 | if (mScreenWakeLock != null && !mScreenWakeLock.isHeld()) { |
| 411 | mScreenWakeLock.acquire(); |
| 412 | } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 413 | } |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 414 | |
Amirhossein | 7bb77aa | 2020-12-18 16:30:44 -0500 | [diff] [blame^] | 415 | if (presenter.setBlockRecordStatus()) { |
| 416 | binding.videoSurface.setSecure(true); |
| 417 | getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); |
| 418 | } |
| 419 | |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 420 | binding.videoSurface.getHolder().setFormat(PixelFormat.RGBA_8888); |
| 421 | binding.videoSurface.getHolder().addCallback(new SurfaceHolder.Callback() { |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 422 | @Override |
| 423 | public void surfaceCreated(SurfaceHolder holder) { |
| 424 | presenter.videoSurfaceCreated(holder); |
| 425 | } |
| 426 | |
| 427 | @Override |
| 428 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
| 429 | |
| 430 | } |
| 431 | |
| 432 | @Override |
| 433 | public void surfaceDestroyed(SurfaceHolder holder) { |
| 434 | presenter.videoSurfaceDestroyed(); |
| 435 | } |
| 436 | }); |
AGS5 | ef482ce | 2020-06-12 13:28:51 -0400 | [diff] [blame] | 437 | |
| 438 | binding.pluginPreviewSurface.getHolder().setFormat(PixelFormat.RGBA_8888); |
| 439 | binding.pluginPreviewSurface.getHolder().addCallback(new SurfaceHolder.Callback() { |
| 440 | @Override |
| 441 | public void surfaceCreated(SurfaceHolder holder) { |
| 442 | presenter.pluginSurfaceCreated(holder); |
| 443 | } |
| 444 | |
| 445 | @Override |
| 446 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
| 447 | |
| 448 | } |
| 449 | |
| 450 | @Override |
| 451 | public void surfaceDestroyed(SurfaceHolder holder) { |
| 452 | presenter.pluginSurfaceDestroyed(); |
| 453 | } |
| 454 | }); |
| 455 | |
Pierre Duchemin | 45707ca | 2018-01-15 15:05:23 -0500 | [diff] [blame] | 456 | view.setOnSystemUiVisibilityChangeListener(visibility -> { |
| 457 | boolean ui = (visibility & (View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN)) == 0; |
| 458 | presenter.uiVisibilityChanged(ui); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 459 | }); |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 460 | view.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> |
| 461 | resetVideoSize(mVideoWidth, mVideoHeight)); |
| 462 | |
| 463 | WindowManager windowManager = (WindowManager) requireContext().getSystemService(Context.WINDOW_SERVICE); |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 464 | if (windowManager != null) { |
| 465 | mOrientationListener = new OrientationEventListener(getContext()) { |
| 466 | @Override |
| 467 | public void onOrientationChanged(int orientation) { |
| 468 | int rot = windowManager.getDefaultDisplay().getRotation(); |
| 469 | if (mCurrentOrientation != rot) { |
| 470 | mCurrentOrientation = rot; |
| 471 | presenter.configurationChanged(rot); |
| 472 | } |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 473 | } |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 474 | }; |
| 475 | if (mOrientationListener.canDetectOrientation()) { |
| 476 | mOrientationListener.enable(); |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 477 | } |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 478 | } |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 479 | |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 480 | binding.shapeRipple.setRippleShape(new Circle()); |
| 481 | binding.callSpeakerBtn.setChecked(presenter.isSpeakerphoneOn()); |
Adrien Béraud | ec19fad | 2018-12-30 16:51:05 -0500 | [diff] [blame] | 482 | binding.callMicBtn.setChecked(presenter.isMicrophoneMuted()); |
AGS5 | ef482ce | 2020-06-12 13:28:51 -0400 | [diff] [blame] | 483 | binding.pluginPreviewSurface.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> |
| 484 | configureTransform(mPreviewSurfaceWidth, mPreviewSurfaceHeight)); |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 485 | binding.previewSurface.setSurfaceTextureListener(listener); |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 486 | binding.previewSurface.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> |
| 487 | configureTransform(mPreviewSurfaceWidth, mPreviewSurfaceHeight)); |
Adrien Béraud | bcbb4d4 | 2018-12-08 16:06:39 -0500 | [diff] [blame] | 488 | |
Adrien Béraud | 2d50acb | 2020-03-23 22:02:15 -0400 | [diff] [blame] | 489 | previewSnapAnimation.setDuration(250); |
| 490 | previewSnapAnimation.setFloatValues(0.f, 1.f); |
| 491 | previewSnapAnimation.setInterpolator(new DecelerateInterpolator()); |
| 492 | previewSnapAnimation.addUpdateListener(animation -> { |
Pierre Duchemin | 7c125f7 | 2020-05-29 15:23:53 -0400 | [diff] [blame] | 493 | float animatedFraction = animation == null ? 1 : animation.getAnimatedFraction(); |
| 494 | configurePreview(mPreviewSurfaceWidth, animatedFraction); |
Adrien Béraud | 2d50acb | 2020-03-23 22:02:15 -0400 | [diff] [blame] | 495 | }); |
| 496 | |
| 497 | binding.previewContainer.setOnTouchListener((v, event) -> { |
| 498 | int action = event.getActionMasked(); |
Pierre Duchemin | 37d0b3e | 2020-05-14 18:56:21 -0400 | [diff] [blame] | 499 | RelativeLayout parent = (RelativeLayout) v.getParent(); |
| 500 | RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) v.getLayoutParams(); |
| 501 | |
Adrien Béraud | 2d50acb | 2020-03-23 22:02:15 -0400 | [diff] [blame] | 502 | if (action == MotionEvent.ACTION_DOWN) { |
| 503 | previewSnapAnimation.cancel(); |
| 504 | previewDrag = new PointF(event.getX(), event.getY()); |
| 505 | v.setElevation(v.getContext().getResources().getDimension(R.dimen.call_preview_elevation_dragged)); |
Adrien Béraud | 2d50acb | 2020-03-23 22:02:15 -0400 | [diff] [blame] | 506 | params.removeRule(RelativeLayout.ALIGN_PARENT_RIGHT); |
| 507 | params.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM); |
| 508 | params.addRule(RelativeLayout.ALIGN_PARENT_TOP); |
| 509 | params.addRule(RelativeLayout.ALIGN_PARENT_LEFT); |
Pierre Duchemin | 37d0b3e | 2020-05-14 18:56:21 -0400 | [diff] [blame] | 510 | params.setMargins((int) v.getX(), (int) v.getY(), parent.getWidth() - ((int) v.getX() + v.getWidth()), parent.getHeight() - ((int) v.getY() + v.getHeight())); |
Adrien Béraud | 2d50acb | 2020-03-23 22:02:15 -0400 | [diff] [blame] | 511 | v.setLayoutParams(params); |
| 512 | return true; |
| 513 | } else if (action == MotionEvent.ACTION_MOVE) { |
| 514 | if (previewDrag != null) { |
Pierre Duchemin | 37d0b3e | 2020-05-14 18:56:21 -0400 | [diff] [blame] | 515 | int currentXPosition = params.leftMargin + (int) (event.getX() - previewDrag.x); |
| 516 | int currentYPosition = params.topMargin + (int) (event.getY() - previewDrag.y); |
Adrien Béraud | 2d50acb | 2020-03-23 22:02:15 -0400 | [diff] [blame] | 517 | params.setMargins( |
Pierre Duchemin | 37d0b3e | 2020-05-14 18:56:21 -0400 | [diff] [blame] | 518 | currentXPosition, |
| 519 | currentYPosition, |
| 520 | -((currentXPosition + v.getWidth()) - (int) event.getX()), |
| 521 | -((currentYPosition + v.getHeight()) - (int) event.getY())); |
Adrien Béraud | 2d50acb | 2020-03-23 22:02:15 -0400 | [diff] [blame] | 522 | v.setLayoutParams(params); |
Pierre Duchemin | 37d0b3e | 2020-05-14 18:56:21 -0400 | [diff] [blame] | 523 | |
| 524 | float outPosition = binding.previewContainer.getWidth() * 0.85f; |
| 525 | float drapOut = 0.f; |
| 526 | if (currentXPosition < 0) { |
| 527 | drapOut = Math.min(1.f, -currentXPosition / outPosition); |
| 528 | } else if (currentXPosition + v.getWidth() > parent.getWidth()) { |
| 529 | drapOut = Math.min(1.f, (currentXPosition + v.getWidth() - parent.getWidth()) / outPosition); |
| 530 | } |
| 531 | setPreviewDragHiddenState(drapOut); |
Adrien Béraud | 2d50acb | 2020-03-23 22:02:15 -0400 | [diff] [blame] | 532 | return true; |
| 533 | } |
| 534 | return false; |
| 535 | } else if (action == MotionEvent.ACTION_UP) { |
| 536 | if (previewDrag != null) { |
Pierre Duchemin | 37d0b3e | 2020-05-14 18:56:21 -0400 | [diff] [blame] | 537 | int currentXPosition = params.leftMargin + (int) (event.getX() - previewDrag.x); |
| 538 | |
Adrien Béraud | 2d50acb | 2020-03-23 22:02:15 -0400 | [diff] [blame] | 539 | previewSnapAnimation.cancel(); |
| 540 | previewDrag = null; |
| 541 | v.setElevation(v.getContext().getResources().getDimension(R.dimen.call_preview_elevation)); |
Adrien Béraud | 2d50acb | 2020-03-23 22:02:15 -0400 | [diff] [blame] | 542 | int ml = 0, mr = 0, mt = 0, mb = 0; |
Pierre Duchemin | 37d0b3e | 2020-05-14 18:56:21 -0400 | [diff] [blame] | 543 | |
| 544 | FrameLayout.LayoutParams hp = (FrameLayout.LayoutParams) binding.previewHandle.getLayoutParams(); |
Adrien Béraud | 2d50acb | 2020-03-23 22:02:15 -0400 | [diff] [blame] | 545 | if (params.leftMargin + (v.getWidth() / 2) > parent.getWidth() / 2) { |
| 546 | params.removeRule(RelativeLayout.ALIGN_PARENT_LEFT); |
| 547 | params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); |
| 548 | mr = (int) (parent.getWidth() - v.getWidth() - v.getX()); |
Pierre Duchemin | 37d0b3e | 2020-05-14 18:56:21 -0400 | [diff] [blame] | 549 | previewPosition = PreviewPosition.RIGHT; |
| 550 | hp.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT; |
Adrien Béraud | 2d50acb | 2020-03-23 22:02:15 -0400 | [diff] [blame] | 551 | } else { |
| 552 | params.removeRule(RelativeLayout.ALIGN_PARENT_RIGHT); |
| 553 | params.addRule(RelativeLayout.ALIGN_PARENT_LEFT); |
| 554 | ml = (int) v.getX(); |
Pierre Duchemin | 37d0b3e | 2020-05-14 18:56:21 -0400 | [diff] [blame] | 555 | previewPosition = PreviewPosition.LEFT; |
| 556 | hp.gravity = Gravity.CENTER_VERTICAL | Gravity.RIGHT; |
Adrien Béraud | 2d50acb | 2020-03-23 22:02:15 -0400 | [diff] [blame] | 557 | } |
Pierre Duchemin | 37d0b3e | 2020-05-14 18:56:21 -0400 | [diff] [blame] | 558 | binding.previewHandle.setLayoutParams(hp); |
| 559 | |
Adrien Béraud | 2d50acb | 2020-03-23 22:02:15 -0400 | [diff] [blame] | 560 | if (params.topMargin + (v.getHeight() / 2) > parent.getHeight() / 2) { |
| 561 | params.removeRule(RelativeLayout.ALIGN_PARENT_TOP); |
| 562 | params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); |
| 563 | mb = (int) (parent.getHeight() - v.getHeight() - v.getY()); |
| 564 | } else { |
| 565 | params.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM); |
| 566 | params.addRule(RelativeLayout.ALIGN_PARENT_TOP); |
| 567 | mt = (int) v.getY(); |
| 568 | } |
| 569 | previewMargins[0] = ml; |
| 570 | previewMargins[1] = mt; |
| 571 | previewMargins[2] = mr; |
| 572 | previewMargins[3] = mb; |
| 573 | params.setMargins(ml, mt, mr, mb); |
| 574 | v.setLayoutParams(params); |
Pierre Duchemin | 37d0b3e | 2020-05-14 18:56:21 -0400 | [diff] [blame] | 575 | |
| 576 | float outPosition = binding.previewContainer.getWidth() * 0.85f; |
| 577 | previewHiddenState = currentXPosition < 0 |
| 578 | ? Math.min(1.f, -currentXPosition / outPosition) |
| 579 | : ((currentXPosition + v.getWidth() > parent.getWidth()) |
| 580 | ? Math.min(1.f, (currentXPosition + v.getWidth() - parent.getWidth()) / outPosition) |
| 581 | : 0.f); |
| 582 | setPreviewDragHiddenState(previewHiddenState); |
| 583 | |
Adrien Béraud | 2d50acb | 2020-03-23 22:02:15 -0400 | [diff] [blame] | 584 | previewSnapAnimation.start(); |
| 585 | return true; |
| 586 | } |
| 587 | return false; |
| 588 | } else { |
| 589 | return false; |
| 590 | } |
| 591 | }); |
| 592 | |
AGS5 | ef482ce | 2020-06-12 13:28:51 -0400 | [diff] [blame] | 593 | binding.pluginPreviewContainer.setOnTouchListener((v, event) -> { |
| 594 | int action = event.getActionMasked(); |
| 595 | RelativeLayout parent = (RelativeLayout) v.getParent(); |
| 596 | RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) v.getLayoutParams(); |
| 597 | |
| 598 | if (action == MotionEvent.ACTION_DOWN) { |
| 599 | previewSnapAnimation.cancel(); |
| 600 | previewDrag = new PointF(event.getX(), event.getY()); |
| 601 | v.setElevation(v.getContext().getResources().getDimension(R.dimen.call_preview_elevation_dragged)); |
| 602 | params.removeRule(RelativeLayout.ALIGN_PARENT_RIGHT); |
| 603 | params.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM); |
| 604 | params.addRule(RelativeLayout.ALIGN_PARENT_TOP); |
| 605 | params.addRule(RelativeLayout.ALIGN_PARENT_LEFT); |
| 606 | params.setMargins((int) v.getX(), (int) v.getY(), parent.getWidth() - ((int) v.getX() + v.getWidth()), parent.getHeight() - ((int) v.getY() + v.getHeight())); |
| 607 | v.setLayoutParams(params); |
| 608 | return true; |
| 609 | } else if (action == MotionEvent.ACTION_MOVE) { |
| 610 | if (previewDrag != null) { |
| 611 | int currentXPosition = params.leftMargin + (int) (event.getX() - previewDrag.x); |
| 612 | int currentYPosition = params.topMargin + (int) (event.getY() - previewDrag.y); |
| 613 | params.setMargins( |
| 614 | currentXPosition, |
| 615 | currentYPosition, |
| 616 | -((currentXPosition + v.getWidth()) - (int) event.getX()), |
| 617 | -((currentYPosition + v.getHeight()) - (int) event.getY())); |
| 618 | v.setLayoutParams(params); |
| 619 | |
| 620 | float outPosition = binding.pluginPreviewContainer.getWidth() * 0.85f; |
| 621 | float drapOut = 0.f; |
| 622 | if (currentXPosition < 0) { |
| 623 | drapOut = Math.min(1.f, -currentXPosition / outPosition); |
| 624 | } else if (currentXPosition + v.getWidth() > parent.getWidth()) { |
| 625 | drapOut = Math.min(1.f, (currentXPosition + v.getWidth() - parent.getWidth()) / outPosition); |
| 626 | } |
| 627 | setPreviewDragHiddenState(drapOut); |
| 628 | return true; |
| 629 | } |
| 630 | return false; |
| 631 | } else if (action == MotionEvent.ACTION_UP) { |
| 632 | if (previewDrag != null) { |
| 633 | int currentXPosition = params.leftMargin + (int) (event.getX() - previewDrag.x); |
| 634 | |
| 635 | previewSnapAnimation.cancel(); |
| 636 | previewDrag = null; |
| 637 | v.setElevation(v.getContext().getResources().getDimension(R.dimen.call_preview_elevation)); |
| 638 | int ml = 0, mr = 0, mt = 0, mb = 0; |
| 639 | |
| 640 | FrameLayout.LayoutParams hp = (FrameLayout.LayoutParams) binding.pluginPreviewHandle.getLayoutParams(); |
| 641 | if (params.leftMargin + (v.getWidth() / 2) > parent.getWidth() / 2) { |
| 642 | params.removeRule(RelativeLayout.ALIGN_PARENT_LEFT); |
| 643 | params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); |
| 644 | mr = (int) (parent.getWidth() - v.getWidth() - v.getX()); |
| 645 | previewPosition = PreviewPosition.RIGHT; |
| 646 | hp.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT; |
| 647 | } else { |
| 648 | params.removeRule(RelativeLayout.ALIGN_PARENT_RIGHT); |
| 649 | params.addRule(RelativeLayout.ALIGN_PARENT_LEFT); |
| 650 | ml = (int) v.getX(); |
| 651 | previewPosition = PreviewPosition.LEFT; |
| 652 | hp.gravity = Gravity.CENTER_VERTICAL | Gravity.RIGHT; |
| 653 | } |
| 654 | binding.pluginPreviewHandle.setLayoutParams(hp); |
| 655 | |
| 656 | if (params.topMargin + (v.getHeight() / 2) > parent.getHeight() / 2) { |
| 657 | params.removeRule(RelativeLayout.ALIGN_PARENT_TOP); |
| 658 | params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); |
| 659 | mb = (int) (parent.getHeight() - v.getHeight() - v.getY()); |
| 660 | } else { |
| 661 | params.removeRule(RelativeLayout.ALIGN_PARENT_BOTTOM); |
| 662 | params.addRule(RelativeLayout.ALIGN_PARENT_TOP); |
| 663 | mt = (int) v.getY(); |
| 664 | } |
| 665 | previewMargins[0] = ml; |
| 666 | previewMargins[1] = mt; |
| 667 | previewMargins[2] = mr; |
| 668 | previewMargins[3] = mb; |
| 669 | params.setMargins(ml, mt, mr, mb); |
| 670 | v.setLayoutParams(params); |
| 671 | |
| 672 | float outPosition = binding.pluginPreviewContainer.getWidth() * 0.85f; |
| 673 | previewHiddenState = currentXPosition < 0 |
| 674 | ? Math.min(1.f, -currentXPosition / outPosition) |
| 675 | : ((currentXPosition + v.getWidth() > parent.getWidth()) |
| 676 | ? Math.min(1.f, (currentXPosition + v.getWidth() - parent.getWidth()) / outPosition) |
| 677 | : 0.f); |
| 678 | setPreviewDragHiddenState(previewHiddenState); |
| 679 | |
| 680 | previewSnapAnimation.start(); |
| 681 | return true; |
| 682 | } |
| 683 | return false; |
| 684 | } else { |
| 685 | return false; |
| 686 | } |
| 687 | }); |
| 688 | |
Adrien Béraud | bcbb4d4 | 2018-12-08 16:06:39 -0500 | [diff] [blame] | 689 | binding.dialpadEditText.addTextChangedListener(new TextWatcher() { |
| 690 | @Override |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 691 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { |
| 692 | } |
Adrien Béraud | bcbb4d4 | 2018-12-08 16:06:39 -0500 | [diff] [blame] | 693 | |
| 694 | @Override |
| 695 | public void onTextChanged(CharSequence s, int start, int before, int count) { |
| 696 | presenter.sendDtmf(s.subSequence(start, start + count)); |
| 697 | } |
| 698 | |
| 699 | @Override |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 700 | public void afterTextChanged(Editable s) { |
| 701 | } |
Adrien Béraud | bcbb4d4 | 2018-12-08 16:06:39 -0500 | [diff] [blame] | 702 | }); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 703 | } |
| 704 | |
Pierre Duchemin | 7c125f7 | 2020-05-29 15:23:53 -0400 | [diff] [blame] | 705 | private void configurePreview(int width, float animatedFraction) { |
Adrien Béraud | 7b7e2ca | 2020-12-10 11:18:19 -0500 | [diff] [blame] | 706 | Context context = getContext(); |
| 707 | if (context == null || binding == null) |
| 708 | return; |
| 709 | float margin = context.getResources().getDimension(R.dimen.call_preview_margin); |
Pierre Duchemin | 7c125f7 | 2020-05-29 15:23:53 -0400 | [diff] [blame] | 710 | RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) binding.previewContainer.getLayoutParams(); |
| 711 | float r = 1.f - animatedFraction; |
| 712 | float hideMargin = 0.f; |
| 713 | float targetHiddenState = 0.f; |
| 714 | if (previewHiddenState > 0.f) { |
| 715 | targetHiddenState = 1.f; |
| 716 | float v = width * 0.85f * animatedFraction; |
| 717 | hideMargin = previewPosition == PreviewPosition.RIGHT ? v : -v; |
| 718 | } |
| 719 | setPreviewDragHiddenState(previewHiddenState * r + targetHiddenState * animatedFraction); |
| 720 | |
| 721 | float f = margin * animatedFraction; |
| 722 | params.setMargins( |
| 723 | (int) (previewMargins[0] * r + f + hideMargin), |
| 724 | (int) (previewMargins[1] * r + f), |
| 725 | (int) (previewMargins[2] * r + f - hideMargin), |
| 726 | (int) (previewMargins[3] * r + f)); |
| 727 | binding.previewContainer.setLayoutParams(params); |
AGS5 | ef482ce | 2020-06-12 13:28:51 -0400 | [diff] [blame] | 728 | binding.pluginPreviewContainer.setLayoutParams(params); |
Pierre Duchemin | 7c125f7 | 2020-05-29 15:23:53 -0400 | [diff] [blame] | 729 | } |
| 730 | |
Rayan Osseiran | de9ac14 | 2019-07-02 13:01:32 -0400 | [diff] [blame] | 731 | /** |
| 732 | * Releases current wakelock and acquires a new proximity wakelock if current call is audio only. |
ayounes | c6c2c01 | 2019-11-11 11:09:51 -0500 | [diff] [blame] | 733 | * |
Rayan Osseiran | de9ac14 | 2019-07-02 13:01:32 -0400 | [diff] [blame] | 734 | * @param isAudioOnly true if it is an audio call |
| 735 | */ |
| 736 | @Override |
| 737 | public void handleCallWakelock(boolean isAudioOnly) { |
| 738 | if (isAudioOnly) { |
| 739 | if (mScreenWakeLock != null && mScreenWakeLock.isHeld()) { |
| 740 | mScreenWakeLock.release(); |
| 741 | } |
| 742 | PowerManager powerManager = (PowerManager) requireContext().getSystemService(Context.POWER_SERVICE); |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 743 | if (powerManager != null) { |
| 744 | mScreenWakeLock = powerManager.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "ring:callLock"); |
| 745 | mScreenWakeLock.setReferenceCounted(false); |
Rayan Osseiran | de9ac14 | 2019-07-02 13:01:32 -0400 | [diff] [blame] | 746 | |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 747 | if (mScreenWakeLock != null && !mScreenWakeLock.isHeld()) { |
| 748 | mScreenWakeLock.acquire(); |
| 749 | } |
Rayan Osseiran | de9ac14 | 2019-07-02 13:01:32 -0400 | [diff] [blame] | 750 | } |
| 751 | } |
| 752 | } |
| 753 | |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 754 | @Override |
Adrien Béraud | 2c378b3 | 2018-07-11 15:24:02 -0400 | [diff] [blame] | 755 | public void onDestroyView() { |
| 756 | super.onDestroyView(); |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 757 | if (mOrientationListener != null) { |
| 758 | mOrientationListener.disable(); |
| 759 | mOrientationListener = null; |
| 760 | } |
Adrien Béraud | 2c378b3 | 2018-07-11 15:24:02 -0400 | [diff] [blame] | 761 | mCompositeDisposable.clear(); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 762 | if (mScreenWakeLock != null && mScreenWakeLock.isHeld()) { |
| 763 | mScreenWakeLock.release(); |
| 764 | } |
Adrien Béraud | 7307cd5 | 2020-04-13 23:29:11 -0400 | [diff] [blame] | 765 | binding = null; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 766 | } |
| 767 | |
Adrien Béraud | 7307cd5 | 2020-04-13 23:29:11 -0400 | [diff] [blame] | 768 | @Override |
| 769 | public void onDestroy() { |
| 770 | super.onDestroy(); |
| 771 | mCompositeDisposable.dispose(); |
| 772 | } |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 773 | |
| 774 | @Override |
| 775 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { |
| 776 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
Adrien Béraud | 63de604 | 2019-05-31 09:38:31 -0400 | [diff] [blame] | 777 | if (requestCode != REQUEST_PERMISSION_INCOMING && requestCode != REQUEST_PERMISSION_OUTGOING) |
| 778 | return; |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 779 | for (int i = 0, n = permissions.length; i < n; i++) { |
| 780 | boolean audioGranted = mDeviceRuntimeService.hasAudioPermission(); |
Adrien Béraud | 63de604 | 2019-05-31 09:38:31 -0400 | [diff] [blame] | 781 | boolean granted = grantResults[i] == PackageManager.PERMISSION_GRANTED; |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 782 | switch (permissions[i]) { |
| 783 | case Manifest.permission.CAMERA: |
Adrien Béraud | 63de604 | 2019-05-31 09:38:31 -0400 | [diff] [blame] | 784 | presenter.cameraPermissionChanged(granted); |
| 785 | if (audioGranted) { |
| 786 | initializeCall(requestCode == REQUEST_PERMISSION_INCOMING); |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 787 | } |
| 788 | break; |
| 789 | case Manifest.permission.RECORD_AUDIO: |
Adrien Béraud | 63de604 | 2019-05-31 09:38:31 -0400 | [diff] [blame] | 790 | presenter.audioPermissionChanged(granted); |
| 791 | initializeCall(requestCode == REQUEST_PERMISSION_INCOMING); |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 792 | break; |
| 793 | } |
| 794 | } |
| 795 | } |
| 796 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 797 | @Override |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 798 | public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { |
| 799 | if (requestCode == REQUEST_CODE_ADD_PARTICIPANT) { |
| 800 | if (resultCode == Activity.RESULT_OK && data != null) { |
| 801 | ConversationPath path = ConversationPath.fromUri(data.getData()); |
| 802 | if (path != null) { |
Adrien Béraud | 2d8a8a8 | 2020-10-15 11:05:38 -0400 | [diff] [blame] | 803 | presenter.addConferenceParticipant(path.getAccountId(), path.getConversationId()); |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 804 | } |
| 805 | } |
Adrien Béraud | ade9bee | 2019-12-02 17:13:26 -0500 | [diff] [blame] | 806 | } else if (requestCode == REQUEST_CODE_SCREEN_SHARE) { |
| 807 | if (resultCode == Activity.RESULT_OK && data != null) { |
Adrien Béraud | d0bd4ce | 2020-11-09 12:07:18 -0500 | [diff] [blame] | 808 | try { |
| 809 | startScreenShare(mProjectionManager.getMediaProjection(resultCode, data)); |
| 810 | } catch (Exception e) { |
| 811 | Log.w(TAG, "Error starting screen sharing", e); |
| 812 | } |
Adrien Béraud | ade9bee | 2019-12-02 17:13:26 -0500 | [diff] [blame] | 813 | } else { |
| 814 | binding.callScreenshareBtn.setChecked(false); |
| 815 | } |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 816 | } |
| 817 | } |
| 818 | |
| 819 | @Override |
| 820 | public void onCreateOptionsMenu(@NonNull Menu m, @NonNull MenuInflater inf) { |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 821 | super.onCreateOptionsMenu(m, inf); |
Adrien Béraud | da2eb1a | 2016-01-11 13:15:12 -0500 | [diff] [blame] | 822 | inf.inflate(R.menu.ac_call, m); |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 823 | dialPadBtn = m.findItem(R.id.menuitem_dialpad); |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 824 | pluginsMenuBtn = m.findItem(R.id.menuitem_video_plugins); |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | @Override |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 828 | public void onPrepareOptionsMenu(@NonNull Menu menu) { |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 829 | super.onPrepareOptionsMenu(menu); |
Hadrien De Sousa | f5774ee | 2017-05-17 14:04:17 -0400 | [diff] [blame] | 830 | presenter.prepareOptionMenu(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | @Override |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 834 | public boolean onOptionsItemSelected(@NonNull MenuItem item) { |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 835 | super.onOptionsItemSelected(item); |
| 836 | switch (item.getItemId()) { |
| 837 | case android.R.id.home: |
Hadrien De Sousa | f5774ee | 2017-05-17 14:04:17 -0400 | [diff] [blame] | 838 | presenter.chatClick(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 839 | break; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 840 | case R.id.menuitem_dialpad: |
Hadrien De Sousa | f5774ee | 2017-05-17 14:04:17 -0400 | [diff] [blame] | 841 | presenter.dialpadClick(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 842 | break; |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 843 | case R.id.menuitem_video_plugins: |
| 844 | displayVideoPluginsCarousel(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 845 | } |
| 846 | return true; |
| 847 | } |
| 848 | |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 849 | @Override |
Adrien Béraud | a373e3b | 2018-12-12 11:14:50 -0500 | [diff] [blame] | 850 | public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode) { |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 851 | AppCompatActivity activity = (AppCompatActivity) getActivity(); |
| 852 | ActionBar actionBar = activity == null ? null : activity.getSupportActionBar(); |
| 853 | if (actionBar != null) { |
Rayan Osseiran | f7dfe23 | 2019-06-06 10:26:10 -0400 | [diff] [blame] | 854 | if (isInPictureInPictureMode) { |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 855 | actionBar.hide(); |
Rayan Osseiran | f7dfe23 | 2019-06-06 10:26:10 -0400 | [diff] [blame] | 856 | } else { |
| 857 | mBackstackLost = true; |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 858 | actionBar.show(); |
Rayan Osseiran | f7dfe23 | 2019-06-06 10:26:10 -0400 | [diff] [blame] | 859 | } |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 860 | } |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 861 | presenter.pipModeChanged(isInPictureInPictureMode); |
| 862 | } |
| 863 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 864 | @Override |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 865 | public void displayContactBubble(final boolean display) { |
Adrien Béraud | d0bd4ce | 2020-11-09 12:07:18 -0500 | [diff] [blame] | 866 | if (binding != null) |
| 867 | binding.contactBubbleLayout.getHandler().post(() -> { |
| 868 | if (binding != null) binding.contactBubbleLayout.setVisibility(display ? View.VISIBLE : View.GONE); |
| 869 | }); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | @Override |
Rayan Osseiran | c1532d4 | 2019-06-05 13:17:53 -0400 | [diff] [blame] | 873 | public void displayVideoSurface(final boolean displayVideoSurface, final boolean displayPreviewContainer) { |
| 874 | binding.videoSurface.setVisibility(displayVideoSurface ? View.VISIBLE : View.GONE); |
agsantos | a6d68a8 | 2020-07-09 11:33:30 -0400 | [diff] [blame] | 875 | if (choosePluginMode) { |
AGS5 | ef482ce | 2020-06-12 13:28:51 -0400 | [diff] [blame] | 876 | binding.pluginPreviewSurface.setVisibility(displayPreviewContainer ? View.VISIBLE : View.GONE); |
| 877 | binding.pluginPreviewContainer.setVisibility(displayPreviewContainer ? View.VISIBLE : View.GONE); |
| 878 | binding.previewContainer.setVisibility(View.GONE); |
| 879 | } else { |
| 880 | binding.pluginPreviewSurface.setVisibility(View.GONE); |
| 881 | binding.pluginPreviewContainer.setVisibility(View.GONE); |
| 882 | binding.previewContainer.setVisibility(displayPreviewContainer ? View.VISIBLE : View.GONE); |
| 883 | } |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 884 | updateMenu(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | @Override |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 888 | public void displayPreviewSurface(final boolean display) { |
| 889 | if (display) { |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 890 | binding.videoSurface.setZOrderOnTop(false); |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 891 | binding.videoSurface.setZOrderMediaOverlay(false); |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 892 | } else { |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 893 | binding.videoSurface.setZOrderMediaOverlay(true); |
| 894 | binding.videoSurface.setZOrderOnTop(true); |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 895 | } |
| 896 | } |
| 897 | |
| 898 | @Override |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 899 | public void displayHangupButton(boolean display) { |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 900 | Log.w(TAG, "displayHangupButton " + display); |
agsantos | a6d68a8 | 2020-07-09 11:33:30 -0400 | [diff] [blame] | 901 | display &= !choosePluginMode; |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 902 | binding.callControlGroup.setVisibility(display ? View.VISIBLE : View.GONE); |
| 903 | binding.callHangupBtn.setVisibility(display ? View.VISIBLE : View.GONE); |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 904 | binding.confControlGroup.setVisibility((mConferenceMode && display) ? View.VISIBLE : View.GONE); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | @Override |
| 908 | public void displayDialPadKeyboard() { |
Adrien Béraud | bcbb4d4 | 2018-12-08 16:06:39 -0500 | [diff] [blame] | 909 | KeyboardVisibilityManager.showKeyboard(getActivity(), binding.dialpadEditText, InputMethodManager.SHOW_FORCED); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | @Override |
| 913 | public void switchCameraIcon(boolean isFront) { |
Adrien Béraud | 91f8874 | 2019-09-09 00:46:46 -0400 | [diff] [blame] | 914 | binding.callCameraFlipBtn.setImageResource(isFront ? R.drawable.baseline_camera_front_24 : R.drawable.baseline_camera_rear_24); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | @Override |
Adrien Béraud | 34a6fa2 | 2019-07-28 16:02:59 -0400 | [diff] [blame] | 918 | public void updateAudioState(HardwareService.AudioState state) { |
| 919 | binding.callSpeakerBtn.setChecked(state.getOutputType() == HardwareService.AudioOutput.SPEAKERS); |
| 920 | } |
| 921 | |
| 922 | @Override |
Adrien Béraud | d3bf4e4 | 2018-02-14 14:44:41 +0100 | [diff] [blame] | 923 | public void updateMenu() { |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 924 | requireActivity().invalidateOptionsMenu(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | @Override |
| 928 | public void updateTime(final long duration) { |
Pierre Duchemin | 37d0b3e | 2020-05-14 18:56:21 -0400 | [diff] [blame] | 929 | if (binding != null) { |
Adrien Béraud | 78c547f | 2020-09-08 16:01:17 -0400 | [diff] [blame] | 930 | if (duration <= 0) |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 931 | binding.callStatusTxt.setText(null); |
| 932 | else |
| 933 | binding.callStatusTxt.setText(String.format(Locale.getDefault(), "%d:%02d:%02d", duration / 3600, duration % 3600 / 60, duration % 60)); |
| 934 | } |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | @Override |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 938 | @SuppressLint("RestrictedApi") |
| 939 | public void updateContactBubble(@NonNull final List<SipCall> contacts) { |
| 940 | Log.w(TAG, "updateContactBubble " + contacts.size()); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 941 | |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 942 | mConferenceMode = contacts.size() > 1; |
| 943 | String username = mConferenceMode ? "Conference with " + contacts.size() + " people" : contacts.get(0).getContact().getRingUsername(); |
| 944 | String displayName = mConferenceMode ? null : contacts.get(0).getContact().getDisplayName(); |
Adrien Béraud | 5f8c3f7 | 2018-03-09 14:49:39 -0500 | [diff] [blame] | 945 | |
Adrien Béraud | afcdd96 | 2018-07-06 21:38:41 -0400 | [diff] [blame] | 946 | boolean hasProfileName = displayName != null && !displayName.contentEquals(username); |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 947 | |
| 948 | AppCompatActivity activity = (AppCompatActivity) getActivity(); |
| 949 | if (activity != null) { |
| 950 | ActionBar ab = activity.getSupportActionBar(); |
| 951 | if (ab != null) { |
| 952 | if (hasProfileName) { |
| 953 | ab.setTitle(displayName); |
| 954 | ab.setSubtitle(username); |
| 955 | } else { |
| 956 | ab.setTitle(username); |
| 957 | ab.setSubtitle(null); |
| 958 | } |
| 959 | ab.setDisplayShowTitleEnabled(true); |
| 960 | } |
| 961 | } |
| 962 | |
Adrien Béraud | afcdd96 | 2018-07-06 21:38:41 -0400 | [diff] [blame] | 963 | if (hasProfileName) { |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 964 | binding.contactBubbleNumTxt.setVisibility(View.VISIBLE); |
| 965 | binding.contactBubbleTxt.setText(displayName); |
| 966 | binding.contactBubbleNumTxt.setText(username); |
Adrien Béraud | afcdd96 | 2018-07-06 21:38:41 -0400 | [diff] [blame] | 967 | } else { |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 968 | binding.contactBubbleNumTxt.setVisibility(View.GONE); |
| 969 | binding.contactBubbleTxt.setText(username); |
Adrien Béraud | afcdd96 | 2018-07-06 21:38:41 -0400 | [diff] [blame] | 970 | } |
Adrien Béraud | 5f8c3f7 | 2018-03-09 14:49:39 -0500 | [diff] [blame] | 971 | |
Andreas Traczyk | cee415a | 2019-12-03 15:45:04 -0500 | [diff] [blame] | 972 | binding.contactBubble.setImageDrawable( |
| 973 | new AvatarDrawable.Builder() |
| 974 | .withContact(contacts.get(0).getContact()) |
| 975 | .withCircleCrop(true) |
| 976 | .withPresence(false) |
| 977 | .build(getActivity()) |
| 978 | ); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 979 | |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 980 | if (!mConferenceMode) { |
| 981 | binding.confControlGroup.setVisibility(View.GONE); |
| 982 | } else { |
| 983 | binding.confControlGroup.setVisibility(View.VISIBLE); |
ayounes | c6c2c01 | 2019-11-11 11:09:51 -0500 | [diff] [blame] | 984 | if (confAdapter == null) { |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 985 | confAdapter = new ConfParticipantAdapter((view, call) -> { |
Adrien Béraud | 78c547f | 2020-09-08 16:01:17 -0400 | [diff] [blame] | 986 | if (presenter == null) |
| 987 | return; |
| 988 | boolean maximized = presenter.isMaximized(call); |
Adrien Béraud | a165bee | 2020-06-08 10:30:26 -0400 | [diff] [blame] | 989 | PopupMenu popup = new PopupMenu(view.getContext(), view); |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 990 | popup.inflate(R.menu.conference_participant_actions); |
Adrien Béraud | 78c547f | 2020-09-08 16:01:17 -0400 | [diff] [blame] | 991 | MenuBuilder menu = (MenuBuilder) popup.getMenu(); |
| 992 | MenuItem maxItem = menu.findItem(R.id.conv_contact_maximize); |
| 993 | if (maximized) { |
| 994 | maxItem.setTitle(R.string.action_call_minimize); |
| 995 | maxItem.setIcon(R.drawable.baseline_close_fullscreen_24); |
| 996 | } else { |
| 997 | maxItem.setTitle(R.string.action_call_maximize); |
| 998 | maxItem.setIcon(R.drawable.baseline_open_in_full_24); |
| 999 | } |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 1000 | popup.setOnMenuItemClickListener(item -> { |
Adrien Béraud | 78c547f | 2020-09-08 16:01:17 -0400 | [diff] [blame] | 1001 | if (presenter == null) |
| 1002 | return false; |
| 1003 | switch (item.getItemId()) { |
| 1004 | case R.id.conv_contact_details: |
| 1005 | presenter.openParticipantContact(call); |
| 1006 | break; |
| 1007 | case R.id.conv_contact_hangup: |
| 1008 | presenter.hangupParticipant(call); |
| 1009 | break; |
| 1010 | case R.id.conv_contact_maximize: |
| 1011 | presenter.maximizeParticipant(call); |
| 1012 | break; |
| 1013 | default: |
| 1014 | return false; |
| 1015 | } |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 1016 | return true; |
| 1017 | }); |
Adrien Béraud | 78c547f | 2020-09-08 16:01:17 -0400 | [diff] [blame] | 1018 | MenuPopupHelper menuHelper = new MenuPopupHelper(view.getContext(), menu, view); |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 1019 | menuHelper.setForceShowIcon(true); |
| 1020 | menuHelper.show(); |
| 1021 | }); |
| 1022 | } |
| 1023 | confAdapter.updateFromCalls(contacts); |
| 1024 | if (binding.confControlGroup.getAdapter() == null) |
| 1025 | binding.confControlGroup.setAdapter(confAdapter); |
Adrien Béraud | 3f9f6cd | 2018-12-12 15:05:28 -0500 | [diff] [blame] | 1026 | } |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | @Override |
Adrien Béraud | 34915fb | 2020-08-24 17:12:03 -0400 | [diff] [blame] | 1030 | public void updateConfInfo(List<Conference.ParticipantInfo> info) { |
| 1031 | binding.participantLabelContainer.removeAllViews(); |
| 1032 | if (!info.isEmpty()) { |
| 1033 | LayoutInflater inflater = LayoutInflater.from(binding.participantLabelContainer.getContext()); |
| 1034 | for (Conference.ParticipantInfo i : info) { |
| 1035 | String displayName = i.contact.getDisplayName(); |
| 1036 | if (!TextUtils.isEmpty(displayName)) { |
| 1037 | ItemParticipantLabelBinding label = ItemParticipantLabelBinding.inflate(inflater); |
| 1038 | PercentFrameLayout.LayoutParams params = new PercentFrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); |
| 1039 | params.getPercentLayoutInfo().leftMarginPercent = i.x / (float) mVideoWidth; |
| 1040 | params.getPercentLayoutInfo().topMarginPercent = i.y / (float) mVideoHeight; |
| 1041 | label.participantName.setText(displayName); |
| 1042 | binding.participantLabelContainer.addView(label.getRoot(), params); |
| 1043 | } |
| 1044 | } |
| 1045 | } |
| 1046 | binding.participantLabelContainer.setVisibility(info.isEmpty() ? View.GONE : View.VISIBLE); |
| 1047 | } |
| 1048 | |
| 1049 | @Override |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 1050 | public void updateCallStatus(final SipCall.CallStatus callStatus) { |
| 1051 | binding.callStatusTxt.setText(callStateToHumanState(callStatus)); |
| 1052 | } |
| 1053 | |
| 1054 | @Override |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 1055 | public void initMenu(boolean isSpeakerOn, boolean displayFlip, boolean canDial, |
| 1056 | boolean showPluginBtn, boolean onGoingCall) { |
Adrien Béraud | 93e887f | 2020-08-13 15:50:32 -0400 | [diff] [blame] | 1057 | if (binding != null) { |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 1058 | binding.callCameraFlipBtn.setVisibility(displayFlip ? View.VISIBLE : View.GONE); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 1059 | } |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 1060 | if (dialPadBtn != null) { |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 1061 | dialPadBtn.setVisible(canDial); |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 1062 | } |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 1063 | |
ayounes | c6c2c01 | 2019-11-11 11:09:51 -0500 | [diff] [blame] | 1064 | if (pluginsMenuBtn != null) { |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 1065 | pluginsMenuBtn.setVisible(showPluginBtn); |
| 1066 | } |
| 1067 | updateMenu(); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | @Override |
Adrien Béraud | 34a6fa2 | 2019-07-28 16:02:59 -0400 | [diff] [blame] | 1071 | public void initNormalStateDisplay(final boolean audioOnly, boolean isMuted) { |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 1072 | Log.w(TAG, "initNormalStateDisplay"); |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 1073 | binding.shapeRipple.stopRipple(); |
Pierre Duchemin | bb83367 | 2018-03-09 16:18:33 -0500 | [diff] [blame] | 1074 | |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 1075 | binding.callAcceptBtn.setVisibility(View.GONE); |
| 1076 | binding.callRefuseBtn.setVisibility(View.GONE); |
| 1077 | binding.callControlGroup.setVisibility(View.VISIBLE); |
| 1078 | binding.callHangupBtn.setVisibility(View.VISIBLE); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 1079 | |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 1080 | binding.contactBubbleLayout.setVisibility(audioOnly ? View.VISIBLE : View.GONE); |
Adrien Béraud | ec19fad | 2018-12-30 16:51:05 -0500 | [diff] [blame] | 1081 | binding.callMicBtn.setChecked(isMuted); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 1082 | |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 1083 | requireActivity().invalidateOptionsMenu(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | @Override |
| 1087 | public void initIncomingCallDisplay() { |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 1088 | Log.w(TAG, "initIncomingCallDisplay"); |
| 1089 | |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 1090 | binding.callAcceptBtn.setVisibility(View.VISIBLE); |
| 1091 | binding.callRefuseBtn.setVisibility(View.VISIBLE); |
| 1092 | binding.callControlGroup.setVisibility(View.GONE); |
| 1093 | binding.callHangupBtn.setVisibility(View.GONE); |
Hadrien De Sousa | 841d15a | 2017-06-02 11:52:10 -0400 | [diff] [blame] | 1094 | |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 1095 | binding.contactBubbleLayout.setVisibility(View.VISIBLE); |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 1096 | requireActivity().invalidateOptionsMenu(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | @Override |
| 1100 | public void initOutGoingCallDisplay() { |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 1101 | Log.w(TAG, "initOutGoingCallDisplay"); |
| 1102 | |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 1103 | binding.callAcceptBtn.setVisibility(View.GONE); |
| 1104 | binding.callRefuseBtn.setVisibility(View.VISIBLE); |
| 1105 | binding.callControlGroup.setVisibility(View.GONE); |
| 1106 | binding.callHangupBtn.setVisibility(View.GONE); |
Hadrien De Sousa | 841d15a | 2017-06-02 11:52:10 -0400 | [diff] [blame] | 1107 | |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 1108 | binding.contactBubbleLayout.setVisibility(View.VISIBLE); |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 1109 | requireActivity().invalidateOptionsMenu(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | @Override |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 1113 | public void resetPreviewVideoSize(int previewWidth, int previewHeight, int rot) { |
| 1114 | if (previewWidth == -1 && previewHeight == -1) |
| 1115 | return; |
| 1116 | mPreviewWidth = previewWidth; |
| 1117 | mPreviewHeight = previewHeight; |
| 1118 | boolean flip = (rot % 180) != 0; |
| 1119 | binding.previewSurface.setAspectRatio(flip ? mPreviewHeight : mPreviewWidth, flip ? mPreviewWidth : mPreviewHeight); |
| 1120 | } |
| 1121 | |
| 1122 | @Override |
AGS5 | ef482ce | 2020-06-12 13:28:51 -0400 | [diff] [blame] | 1123 | public void resetPluginPreviewVideoSize(int previewWidth, int previewHeight, int rot) { |
| 1124 | if (previewWidth == -1 && previewHeight == -1) |
| 1125 | return; |
| 1126 | mPreviewWidth = previewWidth; |
| 1127 | mPreviewHeight = previewHeight; |
| 1128 | boolean flip = (rot % 180) != 0; |
| 1129 | binding.pluginPreviewSurface.setAspectRatio(flip ? mPreviewHeight : mPreviewWidth, flip ? mPreviewWidth : mPreviewHeight); |
| 1130 | } |
| 1131 | |
| 1132 | @Override |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 1133 | public void resetVideoSize(int videoWidth, int videoHeight) { |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 1134 | ViewGroup rootView = (ViewGroup) getView(); |
| 1135 | if (rootView == null) |
| 1136 | return; |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 1137 | double videoRatio = videoWidth / (double) videoHeight; |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 1138 | double screenRatio = rootView.getWidth() / (double) rootView.getHeight(); |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 1139 | RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) binding.videoSurface.getLayoutParams(); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 1140 | int oldW = params.width; |
| 1141 | int oldH = params.height; |
| 1142 | if (videoRatio >= screenRatio) { |
| 1143 | params.width = RelativeLayout.LayoutParams.MATCH_PARENT; |
| 1144 | params.height = (int) (videoHeight * (double) rootView.getWidth() / (double) videoWidth); |
| 1145 | } else { |
| 1146 | params.height = RelativeLayout.LayoutParams.MATCH_PARENT; |
| 1147 | params.width = (int) (videoWidth * (double) rootView.getHeight() / (double) videoHeight); |
| 1148 | } |
Thibault Wittemberg | b328050 | 2016-12-16 17:34:53 -0500 | [diff] [blame] | 1149 | |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 1150 | if (oldW != params.width || oldH != params.height) { |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 1151 | binding.videoSurface.setLayoutParams(params); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 1152 | } |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 1153 | mVideoWidth = videoWidth; |
| 1154 | mVideoHeight = videoHeight; |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 1155 | } |
Adrien Béraud | 30532a5 | 2018-09-11 15:10:05 -0400 | [diff] [blame] | 1156 | |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 1157 | private void configureTransform(int viewWidth, int viewHeight) { |
| 1158 | Activity activity = getActivity(); |
Adrien Béraud | 93e887f | 2020-08-13 15:50:32 -0400 | [diff] [blame] | 1159 | if (null == binding || null == activity) { |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 1160 | return; |
Adrien Béraud | 30532a5 | 2018-09-11 15:10:05 -0400 | [diff] [blame] | 1161 | } |
Adrien Béraud | de0d452 | 2018-12-12 12:11:02 -0500 | [diff] [blame] | 1162 | int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); |
| 1163 | boolean rot = Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation; |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 1164 | // 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] | 1165 | Matrix matrix = new Matrix(); |
| 1166 | RectF viewRect = new RectF(0, 0, viewWidth, viewHeight); |
| 1167 | float centerX = viewRect.centerX(); |
| 1168 | float centerY = viewRect.centerY(); |
| 1169 | if (rot) { |
| 1170 | RectF bufferRect = new RectF(0, 0, mPreviewHeight, mPreviewWidth); |
| 1171 | bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY()); |
| 1172 | matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL); |
| 1173 | float scale = Math.max( |
| 1174 | (float) viewHeight / mPreviewHeight, |
| 1175 | (float) viewWidth / mPreviewWidth); |
| 1176 | matrix.postScale(scale, scale, centerX, centerY); |
| 1177 | matrix.postRotate(90 * (rotation - 2), centerX, centerY); |
| 1178 | } else if (Surface.ROTATION_180 == rotation) { |
| 1179 | matrix.postRotate(180, centerX, centerY); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 1180 | } |
agsantos | a6d68a8 | 2020-07-09 11:33:30 -0400 | [diff] [blame] | 1181 | if(!choosePluginMode) { |
AGS5 | ef482ce | 2020-06-12 13:28:51 -0400 | [diff] [blame] | 1182 | // binding.pluginPreviewSurface.setTransform(matrix); |
| 1183 | // } |
| 1184 | // else { |
| 1185 | binding.previewSurface.setTransform(matrix); |
| 1186 | } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | @Override |
Hadrien De Sousa | 0dc8316 | 2017-11-10 16:15:18 -0500 | [diff] [blame] | 1190 | public void goToConversation(String accountId, String conversationId) { |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 1191 | Context context = requireContext(); |
| 1192 | if (DeviceUtils.isTablet(context)) { |
Adrien Béraud | 52d46a4 | 2020-05-15 14:41:08 -0400 | [diff] [blame] | 1193 | startActivity(new Intent(DRingService.ACTION_CONV_ACCEPT, ConversationPath.toUri(accountId, conversationId), context, HomeActivity.class)); |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 1194 | } else { |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 1195 | startActivityForResult(new Intent(Intent.ACTION_VIEW, ConversationPath.toUri(accountId, conversationId), context, ConversationActivity.class) |
| 1196 | .setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT), HomeActivity.REQUEST_CODE_CONVERSATION); |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 1197 | } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 1198 | } |
| 1199 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 1200 | @Override |
| 1201 | public void goToAddContact(CallContact callContact) { |
| 1202 | startActivityForResult(ActionHelper.getAddNumberIntentForContact(callContact), |
| 1203 | ConversationFragment.REQ_ADD_CONTACT); |
| 1204 | } |
| 1205 | |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 1206 | @Override |
| 1207 | public void goToContact(String accountId, CallContact contact) { |
| 1208 | startActivity(new Intent(Intent.ACTION_VIEW, android.net.Uri.withAppendedPath(android.net.Uri.withAppendedPath(ContentUriHandler.CONTACT_CONTENT_URI, accountId), contact.getPrimaryNumber())) |
| 1209 | .setClass(requireContext(), ContactDetailsActivity.class)); |
| 1210 | } |
| 1211 | |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 1212 | /** |
| 1213 | * Checks if permissions are accepted for camera and microphone. Takes into account whether call is incoming and outgoing, and requests permissions if not available. |
Rayan Osseiran | 3dd0466 | 2019-06-28 16:47:48 -0400 | [diff] [blame] | 1214 | * Initializes the call if permissions are accepted. |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 1215 | * |
| 1216 | * @param isIncoming true if call is incoming, false for outgoing |
Rayan Osseiran | 3dd0466 | 2019-06-28 16:47:48 -0400 | [diff] [blame] | 1217 | * @see #initializeCall(boolean) initializeCall |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 1218 | */ |
Rayan Osseiran | 3dd0466 | 2019-06-28 16:47:48 -0400 | [diff] [blame] | 1219 | @Override |
| 1220 | public void prepareCall(boolean isIncoming) { |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 1221 | boolean audioGranted = mDeviceRuntimeService.hasAudioPermission(); |
| 1222 | boolean audioOnly; |
| 1223 | int permissionType; |
| 1224 | |
| 1225 | if (isIncoming) { |
| 1226 | audioOnly = presenter.isAudioOnly(); |
| 1227 | permissionType = REQUEST_PERMISSION_INCOMING; |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 1228 | } else { |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 1229 | Bundle args = getArguments(); |
| 1230 | audioOnly = args != null && args.getBoolean(KEY_AUDIO_ONLY); |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 1231 | permissionType = REQUEST_PERMISSION_OUTGOING; |
| 1232 | } |
| 1233 | if (!audioOnly) { |
| 1234 | boolean videoGranted = mDeviceRuntimeService.hasVideoPermission(); |
| 1235 | |
Adrien Béraud | a0226ff | 2019-11-21 15:24:42 -0500 | [diff] [blame] | 1236 | if ((!audioGranted || !videoGranted) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 1237 | ArrayList<String> perms = new ArrayList<>(); |
| 1238 | if (!videoGranted) { |
| 1239 | perms.add(Manifest.permission.CAMERA); |
| 1240 | } |
| 1241 | if (!audioGranted) { |
| 1242 | perms.add(Manifest.permission.RECORD_AUDIO); |
| 1243 | } |
| 1244 | requestPermissions(perms.toArray(new String[perms.size()]), permissionType); |
| 1245 | } else if (audioGranted && videoGranted) { |
Rayan Osseiran | 3dd0466 | 2019-06-28 16:47:48 -0400 | [diff] [blame] | 1246 | initializeCall(isIncoming); |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 1247 | } |
| 1248 | } else { |
Adrien Béraud | a0226ff | 2019-11-21 15:24:42 -0500 | [diff] [blame] | 1249 | if (!audioGranted && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 1250 | requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, permissionType); |
| 1251 | } else if (audioGranted) { |
Rayan Osseiran | 3dd0466 | 2019-06-28 16:47:48 -0400 | [diff] [blame] | 1252 | initializeCall(isIncoming); |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 1253 | } |
| 1254 | } |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | /** |
| 1258 | * Starts a call. Takes into account whether call is incoming or outgoing. |
| 1259 | * |
| 1260 | * @param isIncoming true if call is incoming, false for outgoing |
| 1261 | */ |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 1262 | private void initializeCall(boolean isIncoming) { |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 1263 | if (isIncoming) { |
| 1264 | presenter.acceptCall(); |
| 1265 | } else { |
| 1266 | Bundle args; |
| 1267 | args = getArguments(); |
| 1268 | if (args != null) { |
| 1269 | presenter.initOutGoing(getArguments().getString(KEY_ACCOUNT_ID), |
| 1270 | getArguments().getString(ConversationFragment.KEY_CONTACT_RING_ID), |
| 1271 | getArguments().getBoolean(KEY_AUDIO_ONLY)); |
| 1272 | } |
| 1273 | } |
| 1274 | } |
| 1275 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 1276 | @Override |
| 1277 | public void finish() { |
Adrien Béraud | eb4bb00 | 2019-03-14 15:52:48 -0400 | [diff] [blame] | 1278 | Activity activity = getActivity(); |
Rayan Osseiran | f7dfe23 | 2019-06-06 10:26:10 -0400 | [diff] [blame] | 1279 | if (activity != null) { |
Adrien Béraud | b46fd32 | 2020-09-02 17:18:28 -0400 | [diff] [blame] | 1280 | activity.finishAndRemoveTask(); |
Rayan Osseiran | f7dfe23 | 2019-06-06 10:26:10 -0400 | [diff] [blame] | 1281 | if (mBackstackLost) { |
Adrien Béraud | b46fd32 | 2020-09-02 17:18:28 -0400 | [diff] [blame] | 1282 | startActivity(Intent.makeMainActivity(new ComponentName(activity, HomeActivity.class)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); |
Rayan Osseiran | f7dfe23 | 2019-06-06 10:26:10 -0400 | [diff] [blame] | 1283 | } |
| 1284 | } |
Alexandre Lision | 1532d95 | 2016-11-17 09:41:00 -0500 | [diff] [blame] | 1285 | } |
| 1286 | |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 1287 | public void speakerClicked() { |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 1288 | presenter.speakerClick(binding.callSpeakerBtn.isChecked()); |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 1289 | } |
| 1290 | |
Adrien Béraud | ade9bee | 2019-12-02 17:13:26 -0500 | [diff] [blame] | 1291 | private void startScreenShare(MediaProjection mediaProjection) { |
Adrien Béraud | 20bd723 | 2020-03-16 11:33:23 -0400 | [diff] [blame] | 1292 | if (presenter.startScreenShare(mediaProjection)) { |
agsantos | a6d68a8 | 2020-07-09 11:33:30 -0400 | [diff] [blame] | 1293 | if(choosePluginMode) { |
AGS5 | ef482ce | 2020-06-12 13:28:51 -0400 | [diff] [blame] | 1294 | binding.pluginPreviewSurface.setVisibility(View.GONE); |
| 1295 | } else { |
| 1296 | binding.previewSurface.setVisibility(View.GONE); |
| 1297 | } |
Adrien Béraud | 20bd723 | 2020-03-16 11:33:23 -0400 | [diff] [blame] | 1298 | } else { |
| 1299 | Toast.makeText(requireContext(), "Can't start screen sharing", Toast.LENGTH_SHORT).show(); |
| 1300 | } |
Adrien Béraud | ade9bee | 2019-12-02 17:13:26 -0500 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | private void stopShareScreen() { |
Adrien Béraud | 496e49a | 2020-08-13 22:31:05 -0400 | [diff] [blame] | 1304 | binding.previewSurface.setVisibility(View.VISIBLE); |
Adrien Béraud | ade9bee | 2019-12-02 17:13:26 -0500 | [diff] [blame] | 1305 | presenter.stopScreenShare(); |
| 1306 | } |
| 1307 | |
| 1308 | public void shareScreenClicked(boolean checked) { |
| 1309 | if (!checked) { |
| 1310 | stopShareScreen(); |
| 1311 | } else { |
| 1312 | startActivityForResult(mProjectionManager.createScreenCaptureIntent(), REQUEST_CODE_SCREEN_SHARE); |
| 1313 | } |
| 1314 | } |
| 1315 | |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 1316 | public void micClicked() { |
Adrien Béraud | 86a1e37 | 2018-11-23 23:24:30 -0500 | [diff] [blame] | 1317 | presenter.muteMicrophoneToggled(binding.callMicBtn.isChecked()); |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 1318 | } |
| 1319 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 1320 | public void hangUpClicked() { |
Hadrien De Sousa | f5774ee | 2017-05-17 14:04:17 -0400 | [diff] [blame] | 1321 | presenter.hangupCall(); |
Alexandre Lision | 1532d95 | 2016-11-17 09:41:00 -0500 | [diff] [blame] | 1322 | } |
| 1323 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 1324 | public void refuseClicked() { |
Hadrien De Sousa | f5774ee | 2017-05-17 14:04:17 -0400 | [diff] [blame] | 1325 | presenter.refuseCall(); |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 1326 | } |
| 1327 | |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 1328 | public void acceptClicked() { |
Rayan Osseiran | 3dd0466 | 2019-06-28 16:47:48 -0400 | [diff] [blame] | 1329 | prepareCall(true); |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 1330 | } |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 1331 | |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 1332 | public void cameraFlip() { |
| 1333 | presenter.switchVideoInputClick(); |
| 1334 | } |
| 1335 | |
Adrien Béraud | e4f901a | 2019-10-25 17:26:30 -0400 | [diff] [blame] | 1336 | public void addParticipant() { |
| 1337 | presenter.startAddParticipant(); |
| 1338 | } |
| 1339 | |
| 1340 | @Override |
| 1341 | public void startAddParticipant(String conferenceId) { |
| 1342 | startActivityForResult( |
| 1343 | new Intent(Intent.ACTION_PICK) |
| 1344 | .setClass(requireActivity(), ConversationSelectionActivity.class) |
| 1345 | .putExtra(KEY_CONF_ID, conferenceId), |
| 1346 | CallFragment.REQUEST_CODE_ADD_PARTICIPANT); |
| 1347 | } |
agsantos | 4f7b5a1 | 2020-07-08 16:18:07 -0400 | [diff] [blame] | 1348 | |
| 1349 | @Override |
agsantos | 5f68e51 | 2020-10-26 11:48:52 -0400 | [diff] [blame] | 1350 | public void toggleCallMediaHandler(String id, String callId, boolean toggle) { |
| 1351 | Ringservice.toggleCallMediaHandler(id, callId, toggle); |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 1352 | } |
| 1353 | |
ayounes | 019267f | 2020-01-13 15:14:08 -0500 | [diff] [blame] | 1354 | public Map<String, String> getCallMediaHandlerDetails(String id) { |
| 1355 | return Ringservice.getCallMediaHandlerDetails(id).toNative(); |
ayounes | c6c2c01 | 2019-11-11 11:09:51 -0500 | [diff] [blame] | 1356 | } |
ayounes | 8108747 | 2019-11-08 15:26:05 -0500 | [diff] [blame] | 1357 | |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 1358 | @Override |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 1359 | public void positiveMediaButtonClicked() { |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 1360 | presenter.positiveButtonClicked(); |
| 1361 | } |
| 1362 | |
| 1363 | @Override |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 1364 | public void negativeMediaButtonClicked() { |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 1365 | presenter.negativeButtonClicked(); |
| 1366 | } |
| 1367 | |
| 1368 | @Override |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 1369 | public void toggleMediaButtonClicked() { |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 1370 | presenter.toggleButtonClicked(); |
| 1371 | } |
Rayan Osseiran | 38206c6 | 2019-05-15 14:49:03 -0400 | [diff] [blame] | 1372 | |
ayounes | c6c2c01 | 2019-11-11 11:09:51 -0500 | [diff] [blame] | 1373 | public boolean displayPluginsButton() { |
agsantos | a6d68a8 | 2020-07-09 11:33:30 -0400 | [diff] [blame] | 1374 | return getPluginsEnabled(); |
ayounes | c6c2c01 | 2019-11-11 11:09:51 -0500 | [diff] [blame] | 1375 | } |
| 1376 | |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 1377 | @Override |
| 1378 | public void onConfigurationChanged(@NonNull Configuration newConfig) { |
| 1379 | super.onConfigurationChanged(newConfig); |
agsantos | 00e3a9d | 2020-07-06 15:08:43 -0400 | [diff] [blame] | 1380 | // Reset the padding of the RecyclerPicker on each |
ayounes | c6c2c01 | 2019-11-11 11:09:51 -0500 | [diff] [blame] | 1381 | rp.setFirstLastElementsWidths(112, 112); |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 1382 | binding.recyclerPicker.setVisibility(View.GONE); |
agsantos | a6d68a8 | 2020-07-09 11:33:30 -0400 | [diff] [blame] | 1383 | if (choosePluginMode) { |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 1384 | displayHangupButton(false); |
| 1385 | binding.recyclerPicker.setVisibility(View.VISIBLE); |
ayounes | c6c2c01 | 2019-11-11 11:09:51 -0500 | [diff] [blame] | 1386 | movePreview(true); |
| 1387 | if (previousPluginPosition != -1) { |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 1388 | rp.scrollToPosition(previousPluginPosition); |
| 1389 | } |
| 1390 | } else { |
ayounes | c6c2c01 | 2019-11-11 11:09:51 -0500 | [diff] [blame] | 1391 | movePreview(false); |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 1392 | displayHangupButton(true); |
| 1393 | } |
| 1394 | } |
| 1395 | |
ayounes | c6c2c01 | 2019-11-11 11:09:51 -0500 | [diff] [blame] | 1396 | public void toggleVideoPluginsCarousel(boolean toggle) { |
agsantos | a6d68a8 | 2020-07-09 11:33:30 -0400 | [diff] [blame] | 1397 | if (choosePluginMode) { |
Adrien Béraud | 93e887f | 2020-08-13 15:50:32 -0400 | [diff] [blame] | 1398 | if (toggle) { |
ayounes | c6c2c01 | 2019-11-11 11:09:51 -0500 | [diff] [blame] | 1399 | binding.recyclerPicker.setVisibility(View.VISIBLE); |
| 1400 | movePreview(true); |
| 1401 | } else { |
| 1402 | binding.recyclerPicker.setVisibility(View.INVISIBLE); |
| 1403 | movePreview(false); |
| 1404 | } |
| 1405 | } |
ayounes | c6c2c01 | 2019-11-11 11:09:51 -0500 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | public void movePreview(boolean up) { |
| 1409 | // Move the preview container (cardview) by a certain margin |
| 1410 | if(up) { |
| 1411 | animation.setIntValues(12, 128); |
| 1412 | } else { |
| 1413 | animation.setIntValues(128, 12); |
| 1414 | } |
| 1415 | animation.start(); |
| 1416 | } |
| 1417 | |
| 1418 | /** |
| 1419 | * Function that is called to show/hide the plugins recycler viewer and update UI |
| 1420 | */ |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 1421 | public void displayVideoPluginsCarousel() { |
agsantos | a6d68a8 | 2020-07-09 11:33:30 -0400 | [diff] [blame] | 1422 | choosePluginMode = !choosePluginMode; |
AGS5 | ef482ce | 2020-06-12 13:28:51 -0400 | [diff] [blame] | 1423 | |
ayounes | 8108747 | 2019-11-08 15:26:05 -0500 | [diff] [blame] | 1424 | Context context = requireActivity(); |
| 1425 | |
ayounes | 019267f | 2020-01-13 15:14:08 -0500 | [diff] [blame] | 1426 | // Create callMediaHandlers and videoPluginsItems in a lazy manner |
ayounes | c6c2c01 | 2019-11-11 11:09:51 -0500 | [diff] [blame] | 1427 | if (pluginsModeFirst) { |
| 1428 | // Init |
ayounes | 019267f | 2020-01-13 15:14:08 -0500 | [diff] [blame] | 1429 | callMediaHandlers = Ringservice.listCallMediaHandlers(); |
Aline Gondim Santos | f781c5b | 2020-06-26 12:44:44 -0400 | [diff] [blame] | 1430 | List<Drawable> videoPluginsItems = new ArrayList<>(callMediaHandlers.size() + 1); |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 1431 | |
Aline Gondim Santos | f781c5b | 2020-06-26 12:44:44 -0400 | [diff] [blame] | 1432 | videoPluginsItems.add(context.getDrawable(R.drawable.baseline_cancel_24)); |
ayounes | 019267f | 2020-01-13 15:14:08 -0500 | [diff] [blame] | 1433 | // Search for plugin call media handlers icons |
| 1434 | // If a call media handler doesn't have an icon use a standard android icon |
| 1435 | for (String callMediaHandler : callMediaHandlers) { |
| 1436 | Map<String, String> details = getCallMediaHandlerDetails(callMediaHandler); |
agsantos | 4d495c9 | 2020-07-10 12:01:36 -0400 | [diff] [blame] | 1437 | String drawablePath = details.get("iconPath"); |
| 1438 | Drawable handlerIcon = StringUtils.isEmpty(drawablePath) ? null : Drawable.createFromPath(details.get("iconPath")); |
Aline Gondim Santos | f781c5b | 2020-06-26 12:44:44 -0400 | [diff] [blame] | 1439 | if (handlerIcon == null) { |
| 1440 | handlerIcon = context.getDrawable(R.drawable.ic_jami); |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 1441 | } |
Aline Gondim Santos | f781c5b | 2020-06-26 12:44:44 -0400 | [diff] [blame] | 1442 | videoPluginsItems.add(handlerIcon); |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 1443 | } |
| 1444 | |
| 1445 | rp.updateData(videoPluginsItems); |
| 1446 | |
ayounes | c6c2c01 | 2019-11-11 11:09:51 -0500 | [diff] [blame] | 1447 | pluginsModeFirst = false; |
| 1448 | } |
| 1449 | |
agsantos | a6d68a8 | 2020-07-09 11:33:30 -0400 | [diff] [blame] | 1450 | if (choosePluginMode) { |
ayounes | c6c2c01 | 2019-11-11 11:09:51 -0500 | [diff] [blame] | 1451 | // hide hang up button and other call buttons |
| 1452 | displayHangupButton(false); |
| 1453 | // Display the plugins recyclerpicker |
| 1454 | binding.recyclerPicker.setVisibility(View.VISIBLE); |
| 1455 | movePreview(true); |
| 1456 | |
| 1457 | // Start loading the first or previous plugin if one was active |
ayounes | 019267f | 2020-01-13 15:14:08 -0500 | [diff] [blame] | 1458 | if(callMediaHandlers.size() > 0) { |
ayounes | c6c2c01 | 2019-11-11 11:09:51 -0500 | [diff] [blame] | 1459 | // If no previous plugin was active, take the first, else previous |
Aline Gondim Santos | f781c5b | 2020-06-26 12:44:44 -0400 | [diff] [blame] | 1460 | int position; |
| 1461 | if(previousPluginPosition < 1) { |
| 1462 | rp.scrollToPosition(1); |
| 1463 | position = 1; |
| 1464 | previousPluginPosition = 1; |
| 1465 | } else { |
| 1466 | position = previousPluginPosition; |
| 1467 | } |
| 1468 | if (position > 0) { |
| 1469 | String callMediaId = callMediaHandlers.get(position-1); |
agsantos | 4d495c9 | 2020-07-10 12:01:36 -0400 | [diff] [blame] | 1470 | presenter.startPlugin(callMediaId); |
Aline Gondim Santos | f781c5b | 2020-06-26 12:44:44 -0400 | [diff] [blame] | 1471 | } |
ayounes | c6c2c01 | 2019-11-11 11:09:51 -0500 | [diff] [blame] | 1472 | } |
| 1473 | |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 1474 | } else { |
Aline Gondim Santos | f781c5b | 2020-06-26 12:44:44 -0400 | [diff] [blame] | 1475 | if (previousPluginPosition > 0) { |
ayounes | 019267f | 2020-01-13 15:14:08 -0500 | [diff] [blame] | 1476 | String callMediaId = callMediaHandlers. |
Aline Gondim Santos | f781c5b | 2020-06-26 12:44:44 -0400 | [diff] [blame] | 1477 | get(previousPluginPosition-1); |
ayounes | 8108747 | 2019-11-08 15:26:05 -0500 | [diff] [blame] | 1478 | |
agsantos | 4f7b5a1 | 2020-07-08 16:18:07 -0400 | [diff] [blame] | 1479 | presenter.toggleCallMediaHandler(callMediaId, false); |
Aline Gondim Santos | f781c5b | 2020-06-26 12:44:44 -0400 | [diff] [blame] | 1480 | rp.scrollToPosition(previousPluginPosition); |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 1481 | } |
agsantos | 4d495c9 | 2020-07-10 12:01:36 -0400 | [diff] [blame] | 1482 | presenter.stopPlugin(); |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 1483 | binding.recyclerPicker.setVisibility(View.GONE); |
ayounes | c6c2c01 | 2019-11-11 11:09:51 -0500 | [diff] [blame] | 1484 | movePreview(false); |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 1485 | displayHangupButton(true); |
| 1486 | } |
agsantos | 4d495c9 | 2020-07-10 12:01:36 -0400 | [diff] [blame] | 1487 | |
| 1488 | //change preview image |
| 1489 | displayVideoSurface(true,true); |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 1490 | } |
| 1491 | |
ayounes | c6c2c01 | 2019-11-11 11:09:51 -0500 | [diff] [blame] | 1492 | /** |
| 1493 | * Called whenever a plugin drawable in the recycler picker is clicked or scrolled to |
| 1494 | * @param position |
| 1495 | */ |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 1496 | @Override |
| 1497 | public void onItemSelected(int position) { |
| 1498 | Log.i(TAG, "selected position: " + position); |
Aline Gondim Santos | f781c5b | 2020-06-26 12:44:44 -0400 | [diff] [blame] | 1499 | /** If there was a different plugin before, unload it |
| 1500 | * If previousPluginPosition = -1 or 0, there was no plugin |
| 1501 | */ |
| 1502 | if (previousPluginPosition > 0) { |
| 1503 | String callMediaId = callMediaHandlers.get(previousPluginPosition-1); |
agsantos | 4f7b5a1 | 2020-07-08 16:18:07 -0400 | [diff] [blame] | 1504 | presenter.toggleCallMediaHandler(callMediaId, false); |
Aline Gondim Santos | f781c5b | 2020-06-26 12:44:44 -0400 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | if (position > 0) { |
| 1508 | previousPluginPosition = position; |
| 1509 | String callMediaId = callMediaHandlers.get(position-1); |
agsantos | 4f7b5a1 | 2020-07-08 16:18:07 -0400 | [diff] [blame] | 1510 | presenter.toggleCallMediaHandler(callMediaId, true); |
Aline Gondim Santos | f781c5b | 2020-06-26 12:44:44 -0400 | [diff] [blame] | 1511 | } |
| 1512 | } |
| 1513 | |
| 1514 | |
| 1515 | /** |
| 1516 | * Called whenever a plugin drawable in the recycler picker is clicked |
| 1517 | * @param position |
| 1518 | */ |
| 1519 | @Override |
| 1520 | public void onItemClicked(int position) { |
| 1521 | Log.i(TAG, "selected position: " + position); |
| 1522 | if (position == 0) { |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 1523 | /** If there was a different plugin before, unload it |
Aline Gondim Santos | f781c5b | 2020-06-26 12:44:44 -0400 | [diff] [blame] | 1524 | * If previousPluginPosition = -1 or 0, there was no plugin |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 1525 | */ |
Aline Gondim Santos | f781c5b | 2020-06-26 12:44:44 -0400 | [diff] [blame] | 1526 | if (previousPluginPosition > 0) { |
| 1527 | String callMediaId = callMediaHandlers.get(previousPluginPosition-1); |
agsantos | 4f7b5a1 | 2020-07-08 16:18:07 -0400 | [diff] [blame] | 1528 | presenter.toggleCallMediaHandler(callMediaId, false); |
Aline Gondim Santos | f781c5b | 2020-06-26 12:44:44 -0400 | [diff] [blame] | 1529 | rp.scrollToPosition(previousPluginPosition); |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 1530 | } |
| 1531 | |
Aline Gondim Santos | f781c5b | 2020-06-26 12:44:44 -0400 | [diff] [blame] | 1532 | CallActivity callActivity = (CallActivity) getActivity(); |
| 1533 | callActivity.showSystemUI(); |
| 1534 | |
| 1535 | toggleVideoPluginsCarousel(false); |
| 1536 | displayVideoPluginsCarousel(); |
ayounes | 47e9399 | 2019-10-28 12:09:53 -0400 | [diff] [blame] | 1537 | } |
| 1538 | } |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 1539 | } |