Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 1 | /* |
Pierre Duchemin | 2802bfd | 2018-02-21 16:41:32 -0500 | [diff] [blame] | 2 | * Copyright (C) 2004-2018 Savoir-faire Linux Inc. |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 3 | * |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 4 | * Author: Hadrien De Sousa <hadrien.desousa@savoirfairelinux.com> |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 5 | * Adrien Béraud <adrien.beraud@savoirfairelinux.com> |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 20 | */ |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 21 | package cx.ring.fragments; |
| 22 | |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 23 | import android.app.PendingIntent; |
| 24 | import android.app.PictureInPictureParams; |
| 25 | import android.app.RemoteAction; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 26 | import android.content.Context; |
| 27 | import android.content.Intent; |
Kateryna Kostiuk | cea7119 | 2017-02-17 15:54:47 -0500 | [diff] [blame] | 28 | import android.content.pm.ActivityInfo; |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 29 | import android.content.res.Configuration; |
| 30 | import android.graphics.PixelFormat; |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 31 | import android.graphics.Rect; |
| 32 | import android.graphics.drawable.Icon; |
Adrien Béraud | 8d6a483 | 2016-04-12 18:06:11 -0400 | [diff] [blame] | 33 | import android.os.Build; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 34 | import android.os.Bundle; |
| 35 | import android.os.PowerManager; |
Adrien Béraud | 8bc9510 | 2018-08-25 22:34:51 -0400 | [diff] [blame] | 36 | import androidx.annotation.NonNull; |
| 37 | import androidx.annotation.Nullable; |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 38 | import android.util.DisplayMetrics; |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 39 | import android.util.Rational; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 40 | import android.view.Menu; |
| 41 | import android.view.MenuInflater; |
| 42 | import android.view.MenuItem; |
| 43 | import android.view.SurfaceHolder; |
| 44 | import android.view.SurfaceView; |
| 45 | import android.view.View; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 46 | import android.view.ViewGroup; |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 47 | import android.view.inputmethod.InputMethodManager; |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 48 | import android.widget.EditText; |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 49 | import android.widget.ImageButton; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 50 | import android.widget.ImageView; |
| 51 | import android.widget.RelativeLayout; |
| 52 | import android.widget.TextView; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 53 | |
Pierre Duchemin | bb83367 | 2018-03-09 16:18:33 -0500 | [diff] [blame] | 54 | import com.rodolfonavalon.shaperipplelibrary.ShapeRipple; |
| 55 | import com.rodolfonavalon.shaperipplelibrary.model.Circle; |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 56 | |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 57 | import java.util.ArrayList; |
Romain Bertozzi | 64a6678 | 2016-08-02 12:10:38 -0400 | [diff] [blame] | 58 | import java.util.Locale; |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 59 | import java.util.Random; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 60 | |
Adrien Béraud | 8bc9510 | 2018-08-25 22:34:51 -0400 | [diff] [blame] | 61 | import androidx.appcompat.app.ActionBar; |
| 62 | import androidx.appcompat.app.AppCompatActivity; |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 63 | import butterknife.BindView; |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 64 | import butterknife.OnClick; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 65 | import cx.ring.R; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 66 | import cx.ring.call.CallPresenter; |
| 67 | import cx.ring.call.CallView; |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 68 | import cx.ring.client.CallActivity; |
Adrien Béraud | 162427f | 2016-04-12 18:04:08 -0400 | [diff] [blame] | 69 | import cx.ring.client.ConversationActivity; |
Thibault Wittemberg | 4f33d07 | 2016-10-06 17:11:41 -0400 | [diff] [blame] | 70 | import cx.ring.client.HomeActivity; |
Adrien Béraud | 5f8c3f7 | 2018-03-09 14:49:39 -0500 | [diff] [blame] | 71 | import cx.ring.contacts.AvatarFactory; |
Hadrien De Sousa | 73d6dd7 | 2017-09-07 10:54:51 -0400 | [diff] [blame] | 72 | import cx.ring.dependencyinjection.RingInjectionComponent; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 73 | import cx.ring.model.CallContact; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 74 | import cx.ring.model.SipCall; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 75 | import cx.ring.mvp.BaseFragment; |
Alexandre Lision | 5da46fa | 2017-08-09 10:25:50 -0400 | [diff] [blame] | 76 | import cx.ring.service.DRingService; |
Hadrien De Sousa | 9c968fc | 2017-08-30 17:46:03 -0400 | [diff] [blame] | 77 | import cx.ring.services.HardwareServiceImpl; |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 78 | import cx.ring.services.NotificationService; |
Alexandre Lision | 4865f7d | 2016-11-16 18:03:35 -0500 | [diff] [blame] | 79 | import cx.ring.utils.ActionHelper; |
Pierre Duchemin | 42788c3 | 2018-03-08 16:21:15 -0500 | [diff] [blame] | 80 | import cx.ring.utils.DeviceUtils; |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 81 | import cx.ring.utils.KeyboardVisibilityManager; |
Adrien Béraud | 5f8c3f7 | 2018-03-09 14:49:39 -0500 | [diff] [blame] | 82 | import cx.ring.utils.Log; |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 83 | import cx.ring.utils.MediaButtonsHelper; |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 84 | import cx.ring.views.CheckableImageButton; |
Adrien Béraud | 2c378b3 | 2018-07-11 15:24:02 -0400 | [diff] [blame] | 85 | import io.reactivex.disposables.CompositeDisposable; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 86 | |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 87 | public class CallFragment extends BaseFragment<CallPresenter> implements CallView, MediaButtonsHelper.MediaButtonsHelperCallback { |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 88 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 89 | public static final String TAG = CallFragment.class.getSimpleName(); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 90 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 91 | public static final String ACTION_PLACE_CALL = "PLACE_CALL"; |
| 92 | public static final String ACTION_GET_CALL = "GET_CALL"; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 93 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 94 | public static final String KEY_ACTION = "action"; |
| 95 | public static final String KEY_ACCOUNT_ID = "accountId"; |
| 96 | public static final String KEY_CONF_ID = "confId"; |
Hadrien De Sousa | 203164c | 2017-12-05 17:41:42 -0500 | [diff] [blame] | 97 | public static final String KEY_AUDIO_ONLY = "AUDIO_ONLY"; |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 98 | |
| 99 | @BindView(R.id.contact_bubble_layout) |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 100 | protected ViewGroup contactBubbleLayout; |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 101 | |
| 102 | @BindView(R.id.contact_bubble) |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 103 | protected ImageView contactBubbleView; |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 104 | |
| 105 | @BindView(R.id.contact_bubble_txt) |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 106 | protected TextView contactBubbleTxt; |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 107 | |
| 108 | @BindView(R.id.contact_bubble_num_txt) |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 109 | protected TextView contactBubbleNumTxt; |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 110 | |
| 111 | @BindView(R.id.call_accept_btn) |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 112 | protected View acceptButton; |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 113 | |
| 114 | @BindView(R.id.call_refuse_btn) |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 115 | protected View refuseButton; |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 116 | |
| 117 | @BindView(R.id.call_hangup_btn) |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 118 | protected View hangupButton; |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 119 | |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 120 | @BindView(R.id.call_speaker_btn) |
| 121 | protected CheckableImageButton speakerButton; |
| 122 | |
| 123 | @BindView(R.id.call_mic_btn) |
| 124 | protected CheckableImageButton micButton; |
| 125 | |
| 126 | @BindView(R.id.call_camera_flip_btn) |
| 127 | protected ImageButton flipCameraBtn = null; |
| 128 | |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 129 | @BindView(R.id.call_status_txt) |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 130 | protected TextView mCallStatusTxt; |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 131 | |
| 132 | @BindView(R.id.dialpad_edit_text) |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 133 | protected EditText mNumeralDialEditText; |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 134 | |
Pierre Duchemin | bb83367 | 2018-03-09 16:18:33 -0500 | [diff] [blame] | 135 | @BindView(R.id.shape_ripple) |
| 136 | protected ShapeRipple shapeRipple = null; |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 137 | |
| 138 | @BindView(R.id.video_preview_surface) |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 139 | protected SurfaceView mVideoSurface = null; |
| 140 | |
| 141 | @BindView(R.id.camera_preview_surface) |
| 142 | protected SurfaceView mVideoPreview = null; |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 143 | |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 144 | @BindView(R.id.call_control_group) |
| 145 | protected ViewGroup controlLayout; |
| 146 | |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 147 | private MenuItem dialPadBtn = null; |
Kateryna Kostiuk | cea7119 | 2017-02-17 15:54:47 -0500 | [diff] [blame] | 148 | private MenuItem changeScreenOrientationBtn = null; |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 149 | private boolean restartVideo = false; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 150 | private PowerManager.WakeLock mScreenWakeLock; |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 151 | private int mCurrentOrientation = Configuration.ORIENTATION_UNDEFINED; |
Adrien Béraud | 8d6a483 | 2016-04-12 18:06:11 -0400 | [diff] [blame] | 152 | |
Adrien Béraud | 2c378b3 | 2018-07-11 15:24:02 -0400 | [diff] [blame] | 153 | private final CompositeDisposable mCompositeDisposable = new CompositeDisposable(); |
| 154 | |
Hadrien De Sousa | 203164c | 2017-12-05 17:41:42 -0500 | [diff] [blame] | 155 | 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] | 156 | Bundle bundle = new Bundle(); |
| 157 | bundle.putString(KEY_ACTION, action); |
| 158 | bundle.putString(KEY_ACCOUNT_ID, accountID); |
Hadrien De Sousa | 0dc8316 | 2017-11-10 16:15:18 -0500 | [diff] [blame] | 159 | bundle.putString(ConversationFragment.KEY_CONTACT_RING_ID, contactRingId); |
Hadrien De Sousa | 203164c | 2017-12-05 17:41:42 -0500 | [diff] [blame] | 160 | bundle.putBoolean(KEY_AUDIO_ONLY, audioOnly); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 161 | CallFragment countDownFragment = new CallFragment(); |
| 162 | countDownFragment.setArguments(bundle); |
| 163 | return countDownFragment; |
| 164 | } |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 165 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 166 | public static CallFragment newInstance(@NonNull String action, @Nullable String confId) { |
| 167 | Bundle bundle = new Bundle(); |
| 168 | bundle.putString(KEY_ACTION, action); |
| 169 | bundle.putString(KEY_CONF_ID, confId); |
| 170 | CallFragment countDownFragment = new CallFragment(); |
| 171 | countDownFragment.setArguments(bundle); |
| 172 | return countDownFragment; |
| 173 | } |
| 174 | |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 175 | public static int callStateToHumanState(final SipCall.State state) { |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 176 | switch (state) { |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 177 | case SEARCHING: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 178 | return R.string.call_human_state_searching; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 179 | case CONNECTING: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 180 | return R.string.call_human_state_connecting; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 181 | case RINGING: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 182 | return R.string.call_human_state_ringing; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 183 | case CURRENT: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 184 | return R.string.call_human_state_current; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 185 | case HUNGUP: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 186 | return R.string.call_human_state_hungup; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 187 | case BUSY: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 188 | return R.string.call_human_state_busy; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 189 | case FAILURE: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 190 | return R.string.call_human_state_failure; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 191 | case HOLD: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 192 | return R.string.call_human_state_hold; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 193 | case UNHOLD: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 194 | return R.string.call_human_state_unhold; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 195 | case OVER: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 196 | return R.string.call_human_state_over; |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 197 | case NONE: |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 198 | default: |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 199 | return 0; |
Loïc Siret | 0202fbf | 2017-09-28 16:34:28 -0400 | [diff] [blame] | 200 | } |
| 201 | } |
| 202 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 203 | @Override |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 204 | protected void initPresenter(CallPresenter presenter) { |
| 205 | super.initPresenter(presenter); |
| 206 | |
| 207 | String action = getArguments().getString(KEY_ACTION); |
Pierre Duchemin | 45707ca | 2018-01-15 15:05:23 -0500 | [diff] [blame] | 208 | if (action != null) { |
| 209 | if (action.equals(ACTION_PLACE_CALL)) { |
| 210 | presenter.initOutGoing(getArguments().getString(KEY_ACCOUNT_ID), |
| 211 | getArguments().getString(ConversationFragment.KEY_CONTACT_RING_ID), |
| 212 | getArguments().getBoolean(KEY_AUDIO_ONLY)); |
| 213 | } else if (action.equals(ACTION_GET_CALL)) { |
| 214 | presenter.initIncoming(getArguments().getString(KEY_CONF_ID)); |
| 215 | } |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 216 | } |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 217 | } |
| 218 | |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 219 | public void onUserLeave() { |
| 220 | presenter.requestPipMode(); |
| 221 | } |
| 222 | |
| 223 | @Override |
| 224 | public void enterPipMode(SipCall sipCall) { |
| 225 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { |
| 226 | return; |
| 227 | } |
| 228 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
| 229 | PictureInPictureParams.Builder paramBuilder = new PictureInPictureParams.Builder(); |
| 230 | if (mVideoSurface.getVisibility() == View.VISIBLE) { |
| 231 | int[] l = new int[2]; |
| 232 | mVideoSurface.getLocationInWindow(l); |
| 233 | int x = l[0]; |
| 234 | int y = l[1]; |
| 235 | int w = mVideoSurface.getWidth(); |
| 236 | int h = mVideoSurface.getHeight(); |
| 237 | Rect videoBounds = new Rect(x, y, x + w, y + h); |
| 238 | paramBuilder.setAspectRatio(new Rational(w, h)); |
| 239 | paramBuilder.setSourceRectHint(videoBounds); |
| 240 | } |
| 241 | ArrayList<RemoteAction> actions = new ArrayList<>(1); |
| 242 | actions.add(new RemoteAction( |
| 243 | Icon.createWithResource(getContext(), R.drawable.ic_call_end_white), |
| 244 | getString(R.string.action_call_hangup), |
| 245 | getString(R.string.action_call_hangup), |
| 246 | PendingIntent.getService(getContext(), new Random().nextInt(), |
| 247 | new Intent(DRingService.ACTION_CALL_END) |
| 248 | .setClass(getContext(), DRingService.class) |
| 249 | .putExtra(NotificationService.KEY_CALL_ID, sipCall.getCallId()), PendingIntent.FLAG_ONE_SHOT))); |
| 250 | paramBuilder.setActions(actions); |
| 251 | getActivity().enterPictureInPictureMode(paramBuilder.build()); |
Adrien Béraud | 8e05cf3 | 2018-03-15 11:58:38 -0400 | [diff] [blame] | 252 | } else if (DeviceUtils.isTv(getContext())) { |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 253 | getActivity().enterPictureInPictureMode(); |
| 254 | } |
| 255 | } |
| 256 | |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 257 | @Override |
Hadrien De Sousa | 73d6dd7 | 2017-09-07 10:54:51 -0400 | [diff] [blame] | 258 | public int getLayout() { |
| 259 | return R.layout.frag_call; |
| 260 | } |
| 261 | |
| 262 | @Override |
| 263 | public void injectFragment(RingInjectionComponent component) { |
| 264 | component.inject(this); |
| 265 | } |
| 266 | |
| 267 | @Override |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 268 | public void onStart() { |
| 269 | super.onStart(); |
| 270 | if (restartVideo) { |
| 271 | displayVideoSurface(true); |
| 272 | restartVideo = false; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | @Override |
| 277 | public void onStop() { |
| 278 | super.onStop(); |
| 279 | if (mVideoSurface.getVisibility() == View.VISIBLE) { |
| 280 | restartVideo = true; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | @Override |
Hadrien De Sousa | 73d6dd7 | 2017-09-07 10:54:51 -0400 | [diff] [blame] | 285 | public void onViewCreated(View view, Bundle savedInstanceState) { |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 286 | setHasOptionsMenu(true); |
Hadrien De Sousa | 73d6dd7 | 2017-09-07 10:54:51 -0400 | [diff] [blame] | 287 | super.onViewCreated(view, savedInstanceState); |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 288 | mCurrentOrientation = getResources().getConfiguration().orientation; |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 289 | PowerManager powerManager = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE); |
Adrien Béraud | 87810c7 | 2018-06-11 15:55:03 -0400 | [diff] [blame] | 290 | mScreenWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "ring:callLock"); |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 291 | mScreenWakeLock.setReferenceCounted(false); |
| 292 | |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 293 | if (mScreenWakeLock != null && !mScreenWakeLock.isHeld()) { |
| 294 | mScreenWakeLock.acquire(); |
| 295 | } |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 296 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 297 | mVideoSurface.getHolder().setFormat(PixelFormat.RGBA_8888); |
| 298 | mVideoSurface.getHolder().addCallback(new SurfaceHolder.Callback() { |
| 299 | @Override |
| 300 | public void surfaceCreated(SurfaceHolder holder) { |
| 301 | presenter.videoSurfaceCreated(holder); |
| 302 | } |
| 303 | |
| 304 | @Override |
| 305 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
| 306 | |
| 307 | } |
| 308 | |
| 309 | @Override |
| 310 | public void surfaceDestroyed(SurfaceHolder holder) { |
| 311 | presenter.videoSurfaceDestroyed(); |
| 312 | } |
| 313 | }); |
Pierre Duchemin | 45707ca | 2018-01-15 15:05:23 -0500 | [diff] [blame] | 314 | view.addOnLayoutChangeListener((parent, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> presenter.layoutChanged()); |
| 315 | view.setOnSystemUiVisibilityChangeListener(visibility -> { |
| 316 | boolean ui = (visibility & (View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN)) == 0; |
| 317 | presenter.uiVisibilityChanged(ui); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 318 | }); |
| 319 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 320 | mVideoPreview.getHolder().addCallback(new SurfaceHolder.Callback() { |
| 321 | @Override |
| 322 | public void surfaceCreated(SurfaceHolder holder) { |
| 323 | presenter.previewVideoSurfaceCreated(holder); |
| 324 | } |
| 325 | |
| 326 | @Override |
| 327 | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { |
| 328 | |
| 329 | } |
| 330 | |
| 331 | @Override |
| 332 | public void surfaceDestroyed(SurfaceHolder holder) { |
| 333 | presenter.previewVideoSurfaceDestroyed(); |
| 334 | } |
| 335 | }); |
| 336 | mVideoPreview.setZOrderMediaOverlay(true); |
Pierre Duchemin | bb83367 | 2018-03-09 16:18:33 -0500 | [diff] [blame] | 337 | shapeRipple.setRippleShape(new Circle()); |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 338 | speakerButton.setChecked(presenter.isSpeakerphoneOn()); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | @Override |
Adrien Béraud | 2c378b3 | 2018-07-11 15:24:02 -0400 | [diff] [blame] | 342 | public void onDestroyView() { |
| 343 | super.onDestroyView(); |
| 344 | mCompositeDisposable.clear(); |
Adrien Béraud | fb6341f | 2016-03-07 16:18:54 -0500 | [diff] [blame] | 345 | if (mScreenWakeLock != null && mScreenWakeLock.isHeld()) { |
| 346 | mScreenWakeLock.release(); |
| 347 | } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 348 | } |
| 349 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 350 | @Override |
| 351 | public void onConfigurationChanged(Configuration newConfig) { |
| 352 | super.onConfigurationChanged(newConfig); |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 353 | int newOrientation = newConfig.orientation; |
| 354 | if (newOrientation == mCurrentOrientation) { |
| 355 | return; |
| 356 | } |
| 357 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && getActivity().isInPictureInPictureMode()) { |
| 358 | // avoid restarting the camera when entering PIP mode |
| 359 | return; |
| 360 | } |
| 361 | mCurrentOrientation = newOrientation; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 362 | presenter.configurationChanged(); |
Adrien Béraud | b179bab | 2015-10-08 12:04:22 -0400 | [diff] [blame] | 363 | } |
| 364 | |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 365 | @Override |
| 366 | public void onCreateOptionsMenu(Menu m, MenuInflater inf) { |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 367 | super.onCreateOptionsMenu(m, inf); |
Adrien Béraud | da2eb1a | 2016-01-11 13:15:12 -0500 | [diff] [blame] | 368 | inf.inflate(R.menu.ac_call, m); |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 369 | dialPadBtn = m.findItem(R.id.menuitem_dialpad); |
Kateryna Kostiuk | cea7119 | 2017-02-17 15:54:47 -0500 | [diff] [blame] | 370 | changeScreenOrientationBtn = m.findItem(R.id.menuitem_change_screen_orientation); |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | @Override |
| 374 | public void onPrepareOptionsMenu(Menu menu) { |
| 375 | super.onPrepareOptionsMenu(menu); |
Hadrien De Sousa | f5774ee | 2017-05-17 14:04:17 -0400 | [diff] [blame] | 376 | presenter.prepareOptionMenu(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | @Override |
| 380 | public boolean onOptionsItemSelected(MenuItem item) { |
| 381 | super.onOptionsItemSelected(item); |
| 382 | switch (item.getItemId()) { |
| 383 | case android.R.id.home: |
| 384 | case R.id.menuitem_chat: |
Hadrien De Sousa | f5774ee | 2017-05-17 14:04:17 -0400 | [diff] [blame] | 385 | presenter.chatClick(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 386 | break; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 387 | case R.id.menuitem_dialpad: |
Hadrien De Sousa | f5774ee | 2017-05-17 14:04:17 -0400 | [diff] [blame] | 388 | presenter.dialpadClick(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 389 | break; |
| 390 | case R.id.menuitem_change_screen_orientation: |
Hadrien De Sousa | f5774ee | 2017-05-17 14:04:17 -0400 | [diff] [blame] | 391 | presenter.screenRotationClick(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 392 | break; |
| 393 | } |
| 394 | return true; |
| 395 | } |
| 396 | |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 397 | |
| 398 | @Override |
| 399 | public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) { |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 400 | if (isInPictureInPictureMode) |
| 401 | ((CallActivity) getActivity()).getSupportActionBar().hide(); |
| 402 | else |
| 403 | ((CallActivity) getActivity()).getSupportActionBar().show(); |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 404 | presenter.pipModeChanged(isInPictureInPictureMode); |
| 405 | } |
| 406 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 407 | @Override |
| 408 | public void blockScreenRotation() { |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 409 | getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | @Override |
| 413 | public void displayContactBubble(final boolean display) { |
Pierre Duchemin | 45707ca | 2018-01-15 15:05:23 -0500 | [diff] [blame] | 414 | getActivity().runOnUiThread(() -> contactBubbleLayout.setVisibility(display ? View.VISIBLE : View.GONE)); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | @Override |
| 418 | public void displayVideoSurface(final boolean display) { |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 419 | mVideoSurface.setVisibility(display ? View.VISIBLE : View.GONE); |
| 420 | mVideoPreview.setVisibility(display ? View.VISIBLE : View.GONE); |
| 421 | updateMenu(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | @Override |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 425 | public void displayPreviewSurface(final boolean display) { |
| 426 | if (display) { |
| 427 | mVideoPreview.setZOrderMediaOverlay(true); |
| 428 | mVideoSurface.setZOrderMediaOverlay(false); |
| 429 | } else { |
| 430 | mVideoPreview.setZOrderMediaOverlay(false); |
| 431 | mVideoSurface.setZOrderMediaOverlay(true); |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | @Override |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 436 | public void displayHangupButton(boolean display) { |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 437 | controlLayout.setVisibility(display ? View.VISIBLE : View.GONE); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 438 | hangupButton.setVisibility(display ? View.VISIBLE : View.GONE); |
| 439 | } |
| 440 | |
| 441 | @Override |
| 442 | public void displayDialPadKeyboard() { |
| 443 | KeyboardVisibilityManager.showKeyboard(getActivity(), |
| 444 | mNumeralDialEditText, |
| 445 | InputMethodManager.SHOW_IMPLICIT); |
| 446 | } |
| 447 | |
| 448 | @Override |
| 449 | public void switchCameraIcon(boolean isFront) { |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 450 | flipCameraBtn.setImageResource(isFront ? R.drawable.ic_camera_front_white : R.drawable.ic_camera_rear_white); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | @Override |
Adrien Béraud | d3bf4e4 | 2018-02-14 14:44:41 +0100 | [diff] [blame] | 454 | public void updateMenu() { |
| 455 | getActivity().invalidateOptionsMenu(); |
| 456 | } |
| 457 | |
| 458 | @Override |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 459 | public void changeScreenRotation() { |
Adrien Béraud | 79808d0 | 2018-02-20 00:16:28 +0100 | [diff] [blame] | 460 | if (mCurrentOrientation == Configuration.ORIENTATION_LANDSCAPE) { |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 461 | getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
| 462 | } else { |
| 463 | getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | @Override |
| 468 | public void updateTime(final long duration) { |
Adrien Béraud | 3aeed5d | 2018-07-26 11:26:13 -0400 | [diff] [blame] | 469 | if (mCallStatusTxt != null) |
| 470 | mCallStatusTxt.setText(String.format(Locale.getDefault(), "%d:%02d:%02d", duration / 3600, duration % 3600 / 60, duration % 60)); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | @Override |
Adrien Beraud | 8e6e2ff | 2017-06-14 14:40:27 +0200 | [diff] [blame] | 474 | public void updateContactBubble(@NonNull final CallContact contact) { |
Adrien Béraud | 5f8c3f7 | 2018-03-09 14:49:39 -0500 | [diff] [blame] | 475 | String username = contact.getRingUsername(); |
| 476 | String displayName = contact.getDisplayName(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 477 | |
Adrien Béraud | 5f8c3f7 | 2018-03-09 14:49:39 -0500 | [diff] [blame] | 478 | String ringId = contact.getIds().get(0); |
Adrien Béraud | afcdd96 | 2018-07-06 21:38:41 -0400 | [diff] [blame] | 479 | Log.d(TAG, "updateContactBubble: contact=" + contact + " username=" + username + ", ringId=" + ringId); |
Adrien Béraud | 5f8c3f7 | 2018-03-09 14:49:39 -0500 | [diff] [blame] | 480 | |
Adrien Béraud | afcdd96 | 2018-07-06 21:38:41 -0400 | [diff] [blame] | 481 | boolean hasProfileName = displayName != null && !displayName.contentEquals(username); |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 482 | |
| 483 | AppCompatActivity activity = (AppCompatActivity) getActivity(); |
| 484 | if (activity != null) { |
| 485 | ActionBar ab = activity.getSupportActionBar(); |
| 486 | if (ab != null) { |
| 487 | if (hasProfileName) { |
| 488 | ab.setTitle(displayName); |
| 489 | ab.setSubtitle(username); |
| 490 | } else { |
| 491 | ab.setTitle(username); |
| 492 | ab.setSubtitle(null); |
| 493 | } |
| 494 | ab.setDisplayShowTitleEnabled(true); |
| 495 | } |
| 496 | } |
| 497 | |
Adrien Béraud | afcdd96 | 2018-07-06 21:38:41 -0400 | [diff] [blame] | 498 | if (hasProfileName) { |
| 499 | contactBubbleNumTxt.setVisibility(View.VISIBLE); |
| 500 | contactBubbleTxt.setText(displayName); |
| 501 | contactBubbleNumTxt.setText(username); |
| 502 | } else { |
| 503 | contactBubbleNumTxt.setVisibility(View.GONE); |
| 504 | contactBubbleTxt.setText(username); |
| 505 | } |
Adrien Béraud | 5f8c3f7 | 2018-03-09 14:49:39 -0500 | [diff] [blame] | 506 | |
Adrien Béraud | 78ae7b9 | 2018-08-25 19:04:17 -0400 | [diff] [blame] | 507 | AvatarFactory.loadGlideAvatar(contactBubbleView, contact); |
| 508 | |
| 509 | /*mCompositeDisposable.add(Single.fromCallable(() -> Glide.with(getActivity()) |
Adrien Béraud | 2c378b3 | 2018-07-11 15:24:02 -0400 | [diff] [blame] | 510 | .load(AvatarFactory.getAvatar( |
| 511 | getActivity(), |
| 512 | contact.getPhoto(), |
| 513 | username, |
| 514 | ringId, true)) |
Adrien Béraud | afcdd96 | 2018-07-06 21:38:41 -0400 | [diff] [blame] | 515 | .apply(AvatarFactory.getGlideOptions(true, false)) |
Adrien Béraud | 2c378b3 | 2018-07-11 15:24:02 -0400 | [diff] [blame] | 516 | .submit() |
| 517 | .get()) |
| 518 | .subscribeOn(Schedulers.computation()) |
| 519 | .observeOn(AndroidSchedulers.mainThread()) |
Adrien Béraud | 78ae7b9 | 2018-08-25 19:04:17 -0400 | [diff] [blame] | 520 | .subscribe(d -> contactBubbleView.setImageDrawable(d)));*/ |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | @Override |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 524 | public void updateCallStatus(final SipCall.State callState) { |
Pierre Duchemin | 45707ca | 2018-01-15 15:05:23 -0500 | [diff] [blame] | 525 | getActivity().runOnUiThread(() -> { |
| 526 | switch (callState) { |
Adrien Béraud | a3f0b4b | 2018-08-09 11:41:53 -0400 | [diff] [blame] | 527 | case NONE: |
Pierre Duchemin | 45707ca | 2018-01-15 15:05:23 -0500 | [diff] [blame] | 528 | mCallStatusTxt.setText(""); |
| 529 | break; |
| 530 | default: |
| 531 | mCallStatusTxt.setText(callStateToHumanState(callState)); |
| 532 | break; |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 533 | } |
| 534 | }); |
| 535 | } |
| 536 | |
| 537 | @Override |
| 538 | public void initMenu(boolean isSpeakerOn, boolean hasContact, boolean displayFlip, boolean canDial, boolean onGoingCall) { |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 539 | if (flipCameraBtn != null) { |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 540 | flipCameraBtn.setVisibility(displayFlip ? View.VISIBLE : View.GONE); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 541 | } |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 542 | if (dialPadBtn != null) { |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 543 | dialPadBtn.setVisible(canDial); |
Romain Bertozzi | ad8fd84 | 2016-05-11 14:30:35 -0400 | [diff] [blame] | 544 | } |
Kateryna Kostiuk | cea7119 | 2017-02-17 15:54:47 -0500 | [diff] [blame] | 545 | if (changeScreenOrientationBtn != null) { |
| 546 | changeScreenOrientationBtn.setVisible(mVideoSurface.getVisibility() == View.VISIBLE); |
| 547 | } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | @Override |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 551 | public void initNormalStateDisplay(final boolean audioOnly, boolean isSpeakerphoneOn) { |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 552 | shapeRipple.stopRipple(); |
Pierre Duchemin | bb83367 | 2018-03-09 16:18:33 -0500 | [diff] [blame] | 553 | |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 554 | acceptButton.setVisibility(View.GONE); |
| 555 | refuseButton.setVisibility(View.GONE); |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 556 | controlLayout.setVisibility(View.VISIBLE); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 557 | hangupButton.setVisibility(View.VISIBLE); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 558 | |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 559 | contactBubbleLayout.setVisibility(audioOnly ? View.VISIBLE : View.GONE); |
| 560 | speakerButton.setChecked(isSpeakerphoneOn); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 561 | |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 562 | getActivity().invalidateOptionsMenu(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | @Override |
| 566 | public void initIncomingCallDisplay() { |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 567 | acceptButton.setVisibility(View.VISIBLE); |
| 568 | refuseButton.setVisibility(View.VISIBLE); |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 569 | controlLayout.setVisibility(View.GONE); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 570 | hangupButton.setVisibility(View.GONE); |
Hadrien De Sousa | 841d15a | 2017-06-02 11:52:10 -0400 | [diff] [blame] | 571 | |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 572 | contactBubbleLayout.setVisibility(View.VISIBLE); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 573 | getActivity().invalidateOptionsMenu(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | @Override |
| 577 | public void initOutGoingCallDisplay() { |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 578 | acceptButton.setVisibility(View.GONE); |
| 579 | refuseButton.setVisibility(View.VISIBLE); |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 580 | controlLayout.setVisibility(View.GONE); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 581 | hangupButton.setVisibility(View.GONE); |
Hadrien De Sousa | 841d15a | 2017-06-02 11:52:10 -0400 | [diff] [blame] | 582 | |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 583 | contactBubbleLayout.setVisibility(View.VISIBLE); |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 584 | getActivity().invalidateOptionsMenu(); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | @Override |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 588 | public void resetVideoSize(final int videoWidth, final int videoHeight, final int previewWidth, final int previewHeight) { |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 589 | ViewGroup rootView = (ViewGroup) getView(); |
| 590 | if (rootView == null) |
| 591 | return; |
Adrien Béraud | 8d6a483 | 2016-04-12 18:06:11 -0400 | [diff] [blame] | 592 | |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 593 | double videoRatio = videoWidth / (double) videoHeight; |
| 594 | double screenRatio = getView().getWidth() / (double) getView().getHeight(); |
Adrien Béraud | 8d6a483 | 2016-04-12 18:06:11 -0400 | [diff] [blame] | 595 | |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 596 | RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) mVideoSurface.getLayoutParams(); |
| 597 | int oldW = params.width; |
| 598 | int oldH = params.height; |
| 599 | if (videoRatio >= screenRatio) { |
| 600 | params.width = RelativeLayout.LayoutParams.MATCH_PARENT; |
| 601 | params.height = (int) (videoHeight * (double) rootView.getWidth() / (double) videoWidth); |
| 602 | } else { |
| 603 | params.height = RelativeLayout.LayoutParams.MATCH_PARENT; |
| 604 | params.width = (int) (videoWidth * (double) rootView.getHeight() / (double) videoHeight); |
| 605 | } |
Thibault Wittemberg | b328050 | 2016-12-16 17:34:53 -0500 | [diff] [blame] | 606 | |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 607 | if (oldW != params.width || oldH != params.height) { |
| 608 | mVideoSurface.setLayoutParams(params); |
| 609 | } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 610 | |
Adrien Béraud | 30532a5 | 2018-09-11 15:10:05 -0400 | [diff] [blame^] | 611 | if (previewWidth == -1 && previewHeight == -1) |
| 612 | return; |
| 613 | Log.w(TAG, "resetVideoSize preview: " + previewWidth + "x" + previewHeight); |
| 614 | ViewGroup.LayoutParams paramsPreview = mVideoPreview.getLayoutParams(); |
| 615 | DisplayMetrics metrics = getResources().getDisplayMetrics(); |
| 616 | |
| 617 | oldW = paramsPreview.width; |
| 618 | oldH = paramsPreview.height; |
| 619 | double previewMaxDim = Math.max(previewWidth, previewHeight); |
| 620 | double previewRatio = metrics.density * 160. / previewMaxDim; |
| 621 | paramsPreview.width = (int) (previewWidth * previewRatio); |
| 622 | paramsPreview.height = (int) (previewHeight * previewRatio); |
| 623 | |
| 624 | if (oldW != paramsPreview.width || oldH != paramsPreview.height) { |
| 625 | Log.w(TAG, "mVideoPreview.setLayoutParams: " + paramsPreview.width + "x" + paramsPreview.height + " was: " + oldW + "x"+oldH); |
| 626 | mVideoPreview.setLayoutParams(paramsPreview); |
| 627 | } |
| 628 | |
| 629 | /*final int mPreviewWidth; |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 630 | final int mPreviewHeight; |
Hadrien De Sousa | 9c968fc | 2017-08-30 17:46:03 -0400 | [diff] [blame] | 631 | |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 632 | if (mCurrentOrientation == Configuration.ORIENTATION_PORTRAIT) { |
| 633 | mPreviewWidth = HardwareServiceImpl.VIDEO_HEIGHT; |
| 634 | mPreviewHeight = HardwareServiceImpl.VIDEO_WIDTH; |
| 635 | } else { |
| 636 | mPreviewWidth = HardwareServiceImpl.VIDEO_WIDTH; |
| 637 | mPreviewHeight = HardwareServiceImpl.VIDEO_HEIGHT; |
| 638 | } |
Hadrien De Sousa | 9c968fc | 2017-08-30 17:46:03 -0400 | [diff] [blame] | 639 | |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 640 | DisplayMetrics metrics = getResources().getDisplayMetrics(); |
| 641 | RelativeLayout.LayoutParams paramsPreview = (RelativeLayout.LayoutParams) mVideoPreview.getLayoutParams(); |
| 642 | oldW = paramsPreview.width; |
| 643 | oldH = paramsPreview.height; |
| 644 | double previewMaxDim = Math.max(mPreviewWidth, mPreviewHeight); |
| 645 | double previewRatio = metrics.density * 160. / previewMaxDim; |
| 646 | paramsPreview.width = (int) (mPreviewWidth * previewRatio); |
| 647 | paramsPreview.height = (int) (mPreviewHeight * previewRatio); |
Hadrien De Sousa | 9c968fc | 2017-08-30 17:46:03 -0400 | [diff] [blame] | 648 | |
Adrien Béraud | ace37a2 | 2018-06-22 14:58:36 -0400 | [diff] [blame] | 649 | if (oldW != paramsPreview.width || oldH != paramsPreview.height) { |
| 650 | mVideoPreview.setLayoutParams(paramsPreview); |
Adrien Béraud | 30532a5 | 2018-09-11 15:10:05 -0400 | [diff] [blame^] | 651 | }*/ |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | @Override |
Hadrien De Sousa | 0dc8316 | 2017-11-10 16:15:18 -0500 | [diff] [blame] | 655 | public void goToConversation(String accountId, String conversationId) { |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 656 | Intent intent = new Intent(); |
Pierre Duchemin | 42788c3 | 2018-03-08 16:21:15 -0500 | [diff] [blame] | 657 | if (DeviceUtils.isTablet(getActivity())) { |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 658 | intent.setClass(getActivity(), HomeActivity.class) |
Alexandre Lision | 5da46fa | 2017-08-09 10:25:50 -0400 | [diff] [blame] | 659 | .setAction(DRingService.ACTION_CONV_ACCEPT) |
Hadrien De Sousa | 0dc8316 | 2017-11-10 16:15:18 -0500 | [diff] [blame] | 660 | .putExtra(ConversationFragment.KEY_CONTACT_RING_ID, conversationId); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 661 | startActivity(intent); |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 662 | } else { |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 663 | intent.setClass(getActivity(), ConversationActivity.class) |
| 664 | .setAction(Intent.ACTION_VIEW) |
| 665 | .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP) |
Hadrien De Sousa | 0dc8316 | 2017-11-10 16:15:18 -0500 | [diff] [blame] | 666 | .putExtra(ConversationFragment.KEY_ACCOUNT_ID, accountId) |
| 667 | .putExtra(ConversationFragment.KEY_CONTACT_RING_ID, conversationId); |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 668 | startActivityForResult(intent, HomeActivity.REQUEST_CODE_CONVERSATION); |
Adrien Béraud | da712a4 | 2015-11-22 23:45:26 -0500 | [diff] [blame] | 669 | } |
Adrien Béraud | 04d822c | 2015-04-02 17:44:36 -0400 | [diff] [blame] | 670 | } |
| 671 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 672 | @Override |
| 673 | public void goToAddContact(CallContact callContact) { |
| 674 | startActivityForResult(ActionHelper.getAddNumberIntentForContact(callContact), |
| 675 | ConversationFragment.REQ_ADD_CONTACT); |
| 676 | } |
| 677 | |
| 678 | @Override |
| 679 | public void finish() { |
| 680 | getActivity().finish(); |
Alexandre Lision | 1532d95 | 2016-11-17 09:41:00 -0500 | [diff] [blame] | 681 | } |
| 682 | |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 683 | @OnClick({R.id.call_speaker_btn}) |
| 684 | public void speakerClicked() { |
| 685 | presenter.speakerClick(speakerButton.isChecked()); |
| 686 | } |
| 687 | |
| 688 | @OnClick({R.id.call_mic_btn}) |
| 689 | public void micClicked() { |
| 690 | presenter.muteMicrophoneToggled(micButton.isChecked()); |
| 691 | } |
| 692 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 693 | @OnClick({R.id.call_hangup_btn}) |
| 694 | public void hangUpClicked() { |
Hadrien De Sousa | f5774ee | 2017-05-17 14:04:17 -0400 | [diff] [blame] | 695 | presenter.hangupCall(); |
Alexandre Lision | 1532d95 | 2016-11-17 09:41:00 -0500 | [diff] [blame] | 696 | } |
| 697 | |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 698 | @OnClick(R.id.call_refuse_btn) |
| 699 | public void refuseClicked() { |
Hadrien De Sousa | f5774ee | 2017-05-17 14:04:17 -0400 | [diff] [blame] | 700 | presenter.refuseCall(); |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | @OnClick(R.id.call_accept_btn) |
| 704 | public void acceptClicked() { |
Hadrien De Sousa | f5774ee | 2017-05-17 14:04:17 -0400 | [diff] [blame] | 705 | presenter.acceptCall(); |
Thibault Wittemberg | b70d5b0 | 2016-07-08 16:50:14 -0400 | [diff] [blame] | 706 | } |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 707 | |
Adrien Béraud | bc0898e | 2018-08-23 14:31:11 -0400 | [diff] [blame] | 708 | @OnClick(R.id.call_camera_flip_btn) |
| 709 | public void cameraFlip() { |
| 710 | presenter.switchVideoInputClick(); |
| 711 | } |
| 712 | |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 713 | @Override |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 714 | public void positiveMediaButtonClicked() { |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 715 | presenter.positiveButtonClicked(); |
| 716 | } |
| 717 | |
| 718 | @Override |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 719 | public void negativeMediaButtonClicked() { |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 720 | presenter.negativeButtonClicked(); |
| 721 | } |
| 722 | |
| 723 | @Override |
Pierre Duchemin | 1fa6192 | 2018-01-18 10:09:02 -0500 | [diff] [blame] | 724 | public void toggleMediaButtonClicked() { |
Pierre Duchemin | 8b2c1b5 | 2017-12-29 17:17:13 -0500 | [diff] [blame] | 725 | presenter.toggleButtonClicked(); |
| 726 | } |
Hadrien De Sousa | ccc947d | 2017-04-12 14:26:52 -0400 | [diff] [blame] | 727 | } |