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