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