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