Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.incallui; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.content.Intent; |
| 21 | import android.graphics.drawable.GradientDrawable; |
| 22 | import android.graphics.drawable.GradientDrawable.Orientation; |
| 23 | import android.os.Bundle; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 24 | import android.os.Trace; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 25 | import android.support.annotation.ColorInt; |
| 26 | import android.support.annotation.FloatRange; |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 27 | import android.support.annotation.NonNull; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 28 | import android.support.annotation.Nullable; |
| 29 | import android.support.v4.app.FragmentManager; |
| 30 | import android.support.v4.app.FragmentTransaction; |
| 31 | import android.support.v4.graphics.ColorUtils; |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 32 | import android.telephony.TelephonyManager; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 33 | import android.view.KeyEvent; |
| 34 | import android.view.MenuItem; |
| 35 | import android.view.MotionEvent; |
| 36 | import android.view.View; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 37 | import com.android.dialer.common.Assert; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 38 | import com.android.dialer.common.LogUtil; |
| 39 | import com.android.dialer.compat.ActivityCompat; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 40 | import com.android.dialer.configprovider.ConfigProviderBindings; |
| 41 | import com.android.dialer.logging.DialerImpression; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 42 | import com.android.dialer.logging.Logger; |
Eric Erfanian | 8369df0 | 2017-05-03 10:27:13 -0700 | [diff] [blame] | 43 | import com.android.dialer.logging.ScreenEvent; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 44 | import com.android.incallui.answer.bindings.AnswerBindings; |
| 45 | import com.android.incallui.answer.protocol.AnswerScreen; |
| 46 | import com.android.incallui.answer.protocol.AnswerScreenDelegate; |
| 47 | import com.android.incallui.answer.protocol.AnswerScreenDelegateFactory; |
| 48 | import com.android.incallui.answerproximitysensor.PseudoScreenState; |
| 49 | import com.android.incallui.call.CallList; |
| 50 | import com.android.incallui.call.DialerCall; |
| 51 | import com.android.incallui.call.DialerCall.State; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 52 | import com.android.incallui.callpending.CallPendingActivity; |
| 53 | import com.android.incallui.disconnectdialog.DisconnectMessage; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 54 | import com.android.incallui.incall.bindings.InCallBindings; |
| 55 | import com.android.incallui.incall.protocol.InCallButtonUiDelegate; |
| 56 | import com.android.incallui.incall.protocol.InCallButtonUiDelegateFactory; |
| 57 | import com.android.incallui.incall.protocol.InCallScreen; |
| 58 | import com.android.incallui.incall.protocol.InCallScreenDelegate; |
| 59 | import com.android.incallui.incall.protocol.InCallScreenDelegateFactory; |
| 60 | import com.android.incallui.video.bindings.VideoBindings; |
| 61 | import com.android.incallui.video.protocol.VideoCallScreen; |
| 62 | import com.android.incallui.video.protocol.VideoCallScreenDelegate; |
| 63 | import com.android.incallui.video.protocol.VideoCallScreenDelegateFactory; |
| 64 | |
| 65 | /** Version of {@link InCallActivity} that shows the new UI */ |
| 66 | public class InCallActivity extends TransactionSafeFragmentActivity |
| 67 | implements AnswerScreenDelegateFactory, |
| 68 | InCallScreenDelegateFactory, |
| 69 | InCallButtonUiDelegateFactory, |
| 70 | VideoCallScreenDelegateFactory, |
| 71 | PseudoScreenState.StateChangedListener { |
| 72 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 73 | public static final int PENDING_INTENT_REQUEST_CODE_NON_FULL_SCREEN = 0; |
| 74 | public static final int PENDING_INTENT_REQUEST_CODE_FULL_SCREEN = 1; |
| 75 | public static final int PENDING_INTENT_REQUEST_CODE_BUBBLE = 2; |
| 76 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 77 | private static final String TAG_IN_CALL_SCREEN = "tag_in_call_screen"; |
| 78 | private static final String TAG_ANSWER_SCREEN = "tag_answer_screen"; |
| 79 | private static final String TAG_VIDEO_CALL_SCREEN = "tag_video_call_screen"; |
| 80 | |
| 81 | private static final String DID_SHOW_ANSWER_SCREEN_KEY = "did_show_answer_screen"; |
| 82 | private static final String DID_SHOW_IN_CALL_SCREEN_KEY = "did_show_in_call_screen"; |
| 83 | private static final String DID_SHOW_VIDEO_CALL_SCREEN_KEY = "did_show_video_call_screen"; |
| 84 | |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 85 | private static final String CONFIG_ANSWER_AND_RELEASE_ENABLED = "answer_and_release_enabled"; |
| 86 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 87 | private final InCallActivityCommon common; |
| 88 | private boolean didShowAnswerScreen; |
| 89 | private boolean didShowInCallScreen; |
| 90 | private boolean didShowVideoCallScreen; |
| 91 | private int[] backgroundDrawableColors; |
| 92 | private GradientDrawable backgroundDrawable; |
| 93 | private boolean isVisible; |
| 94 | private View pseudoBlackScreenOverlay; |
| 95 | private boolean touchDownWhenPseudoScreenOff; |
| 96 | private boolean isInShowMainInCallFragment; |
| 97 | private boolean needDismissPendingDialogs; |
| 98 | |
| 99 | public InCallActivity() { |
| 100 | common = new InCallActivityCommon(this); |
| 101 | } |
| 102 | |
| 103 | public static Intent getIntent( |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 104 | Context context, boolean showDialpad, boolean newOutgoingCall, boolean isForFullScreen) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 105 | Intent intent = new Intent(Intent.ACTION_MAIN, null); |
| 106 | intent.setFlags(Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NEW_TASK); |
| 107 | intent.setClass(context, InCallActivity.class); |
| 108 | InCallActivityCommon.setIntentExtras(intent, showDialpad, newOutgoingCall, isForFullScreen); |
| 109 | return intent; |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | protected void onResumeFragments() { |
| 114 | super.onResumeFragments(); |
| 115 | if (needDismissPendingDialogs) { |
| 116 | dismissPendingDialogs(); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | @Override |
| 121 | protected void onCreate(Bundle icicle) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 122 | Trace.beginSection("InCallActivity.onCreate"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 123 | LogUtil.i("InCallActivity.onCreate", ""); |
| 124 | super.onCreate(icicle); |
| 125 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 126 | if (getIntent().getBooleanExtra(ReturnToCallController.RETURN_TO_CALL_EXTRA_KEY, false)) { |
| 127 | Logger.get(this).logImpression(DialerImpression.Type.BUBBLE_PRIMARY_BUTTON_RETURN_TO_CALL); |
| 128 | getIntent().removeExtra(ReturnToCallController.RETURN_TO_CALL_EXTRA_KEY); |
| 129 | } |
| 130 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 131 | if (icicle != null) { |
| 132 | didShowAnswerScreen = icicle.getBoolean(DID_SHOW_ANSWER_SCREEN_KEY); |
| 133 | didShowInCallScreen = icicle.getBoolean(DID_SHOW_IN_CALL_SCREEN_KEY); |
| 134 | didShowVideoCallScreen = icicle.getBoolean(DID_SHOW_VIDEO_CALL_SCREEN_KEY); |
| 135 | } |
| 136 | |
| 137 | common.onCreate(icicle); |
| 138 | |
| 139 | getWindow() |
| 140 | .getDecorView() |
| 141 | .setSystemUiVisibility( |
| 142 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); |
| 143 | |
| 144 | pseudoBlackScreenOverlay = findViewById(R.id.psuedo_black_screen_overlay); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 145 | sendBroadcast(CallPendingActivity.getFinishBroadcast()); |
| 146 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | @Override |
| 150 | protected void onSaveInstanceState(Bundle out) { |
| 151 | LogUtil.i("InCallActivity.onSaveInstanceState", ""); |
| 152 | common.onSaveInstanceState(out); |
| 153 | out.putBoolean(DID_SHOW_ANSWER_SCREEN_KEY, didShowAnswerScreen); |
| 154 | out.putBoolean(DID_SHOW_IN_CALL_SCREEN_KEY, didShowInCallScreen); |
| 155 | out.putBoolean(DID_SHOW_VIDEO_CALL_SCREEN_KEY, didShowVideoCallScreen); |
| 156 | super.onSaveInstanceState(out); |
| 157 | isVisible = false; |
| 158 | } |
| 159 | |
| 160 | @Override |
| 161 | protected void onStart() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 162 | Trace.beginSection("InCallActivity.onStart"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 163 | LogUtil.i("InCallActivity.onStart", ""); |
| 164 | super.onStart(); |
| 165 | isVisible = true; |
| 166 | showMainInCallFragment(); |
| 167 | common.onStart(); |
| 168 | if (ActivityCompat.isInMultiWindowMode(this) |
| 169 | && !getResources().getBoolean(R.bool.incall_dialpad_allowed)) { |
| 170 | // Hide the dialpad because there may not be enough room |
| 171 | showDialpadFragment(false, false); |
| 172 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 173 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | @Override |
| 177 | protected void onResume() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 178 | Trace.beginSection("InCallActivity.onResume"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 179 | LogUtil.i("InCallActivity.onResume", ""); |
| 180 | super.onResume(); |
| 181 | common.onResume(); |
| 182 | PseudoScreenState pseudoScreenState = InCallPresenter.getInstance().getPseudoScreenState(); |
| 183 | pseudoScreenState.addListener(this); |
| 184 | onPseudoScreenStateChanged(pseudoScreenState.isOn()); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 185 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | /** onPause is guaranteed to be called when the InCallActivity goes in the background. */ |
| 189 | @Override |
| 190 | protected void onPause() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 191 | Trace.beginSection("InCallActivity.onPause"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 192 | LogUtil.i("InCallActivity.onPause", ""); |
| 193 | super.onPause(); |
| 194 | common.onPause(); |
| 195 | InCallPresenter.getInstance().getPseudoScreenState().removeListener(this); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 196 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | @Override |
| 200 | protected void onStop() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 201 | Trace.beginSection("InCallActivity.onStop"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 202 | LogUtil.i("InCallActivity.onStop", ""); |
| 203 | super.onStop(); |
| 204 | common.onStop(); |
| 205 | isVisible = false; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 206 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | @Override |
| 210 | protected void onDestroy() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 211 | Trace.beginSection("InCallActivity.onDestroy"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 212 | LogUtil.i("InCallActivity.onDestroy", ""); |
| 213 | super.onDestroy(); |
| 214 | common.onDestroy(); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 215 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | @Override |
| 219 | public void finish() { |
| 220 | if (shouldCloseActivityOnFinish()) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 221 | // When user select incall ui from recents after the call is disconnected, it tries to launch |
| 222 | // a new InCallActivity but InCallPresenter is already teared down at this point, which causes |
| 223 | // crash. |
| 224 | // By calling finishAndRemoveTask() instead of finish() the task associated with |
| 225 | // InCallActivity is cleared completely. So system won't try to create a new InCallActivity in |
| 226 | // this case. |
| 227 | // |
| 228 | // Calling finish won't clear the task and normally when an activity finishes it shouldn't |
| 229 | // clear the task since there could be parent activity in the same task that's still alive. |
| 230 | // But InCallActivity is special since it's singleInstance which means it's root activity and |
| 231 | // only instance of activity in the task. So it should be safe to also remove task when |
| 232 | // finishing. |
| 233 | // It's also necessary in the sense of it's excluded from recents. So whenever the activity |
| 234 | // finishes, the task should also be removed since it doesn't make sense to go back to it in |
| 235 | // anyway anymore. |
| 236 | super.finishAndRemoveTask(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | |
| 240 | private boolean shouldCloseActivityOnFinish() { |
| 241 | if (!isVisible()) { |
| 242 | LogUtil.i( |
| 243 | "InCallActivity.shouldCloseActivityOnFinish", |
| 244 | "allowing activity to be closed because it's not visible"); |
| 245 | return true; |
| 246 | } |
| 247 | |
| 248 | if (common.hasPendingDialogs()) { |
| 249 | LogUtil.i( |
| 250 | "InCallActivity.shouldCloseActivityOnFinish", "dialog is visible, not closing activity"); |
| 251 | return false; |
| 252 | } |
| 253 | |
| 254 | AnswerScreen answerScreen = getAnswerScreen(); |
| 255 | if (answerScreen != null && answerScreen.hasPendingDialogs()) { |
| 256 | LogUtil.i( |
| 257 | "InCallActivity.shouldCloseActivityOnFinish", |
| 258 | "answer screen dialog is visible, not closing activity"); |
| 259 | return false; |
| 260 | } |
| 261 | |
| 262 | LogUtil.i( |
| 263 | "InCallActivity.shouldCloseActivityOnFinish", |
| 264 | "activity is visible and has no dialogs, allowing activity to close"); |
| 265 | return true; |
| 266 | } |
| 267 | |
| 268 | @Override |
| 269 | protected void onNewIntent(Intent intent) { |
| 270 | LogUtil.i("InCallActivity.onNewIntent", ""); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 271 | |
| 272 | // If the screen is off, we need to make sure it gets turned on for incoming calls. |
| 273 | // This normally works just fine thanks to FLAG_TURN_SCREEN_ON but that only works |
| 274 | // when the activity is first created. Therefore, to ensure the screen is turned on |
| 275 | // for the call waiting case, we recreate() the current activity. There should be no jank from |
| 276 | // this since the screen is already off and will remain so until our new activity is up. |
| 277 | if (!isVisible()) { |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 278 | common.onNewIntent(intent, true /* isRecreating */); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 279 | LogUtil.i("InCallActivity.onNewIntent", "Restarting InCallActivity to force screen on."); |
| 280 | recreate(); |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 281 | } else { |
| 282 | common.onNewIntent(intent, false /* isRecreating */); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 283 | } |
| 284 | } |
| 285 | |
| 286 | @Override |
| 287 | public void onBackPressed() { |
| 288 | LogUtil.i("InCallActivity.onBackPressed", ""); |
| 289 | if (!common.onBackPressed(didShowInCallScreen || didShowVideoCallScreen)) { |
| 290 | super.onBackPressed(); |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | @Override |
| 295 | public boolean onOptionsItemSelected(MenuItem item) { |
| 296 | LogUtil.i("InCallActivity.onOptionsItemSelected", "item: " + item); |
| 297 | if (item.getItemId() == android.R.id.home) { |
| 298 | onBackPressed(); |
| 299 | return true; |
| 300 | } |
| 301 | return super.onOptionsItemSelected(item); |
| 302 | } |
| 303 | |
| 304 | @Override |
| 305 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 306 | return common.onKeyUp(keyCode, event) || super.onKeyUp(keyCode, event); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | @Override |
| 310 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 311 | return common.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | public boolean isInCallScreenAnimating() { |
| 315 | return false; |
| 316 | } |
| 317 | |
| 318 | public void showConferenceFragment(boolean show) { |
| 319 | if (show) { |
| 320 | startActivity(new Intent(this, ManageConferenceActivity.class)); |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | public boolean showDialpadFragment(boolean show, boolean animate) { |
| 325 | boolean didChange = common.showDialpadFragment(show, animate); |
| 326 | if (didChange) { |
| 327 | // Note: onInCallScreenDialpadVisibilityChange is called here to ensure that the dialpad FAB |
| 328 | // repositions itself. |
| 329 | getInCallScreen().onInCallScreenDialpadVisibilityChange(show); |
| 330 | } |
| 331 | return didChange; |
| 332 | } |
| 333 | |
| 334 | public boolean isDialpadVisible() { |
| 335 | return common.isDialpadVisible(); |
| 336 | } |
| 337 | |
| 338 | public void onForegroundCallChanged(DialerCall newForegroundCall) { |
| 339 | common.updateTaskDescription(); |
| 340 | if (didShowAnswerScreen && newForegroundCall != null) { |
| 341 | if (newForegroundCall.getState() == State.DISCONNECTED |
| 342 | || newForegroundCall.getState() == State.IDLE) { |
| 343 | LogUtil.i( |
| 344 | "InCallActivity.onForegroundCallChanged", |
| 345 | "rejecting incoming call, not updating " + "window background color"); |
| 346 | } |
| 347 | } else { |
| 348 | LogUtil.v("InCallActivity.onForegroundCallChanged", "resetting background color"); |
| 349 | updateWindowBackgroundColor(0); |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | public void updateWindowBackgroundColor(@FloatRange(from = -1f, to = 1.0f) float progress) { |
| 354 | ThemeColorManager themeColorManager = InCallPresenter.getInstance().getThemeColorManager(); |
| 355 | @ColorInt int top; |
| 356 | @ColorInt int middle; |
| 357 | @ColorInt int bottom; |
| 358 | @ColorInt int gray = 0x66000000; |
| 359 | |
| 360 | if (ActivityCompat.isInMultiWindowMode(this)) { |
| 361 | top = themeColorManager.getBackgroundColorSolid(); |
| 362 | middle = themeColorManager.getBackgroundColorSolid(); |
| 363 | bottom = themeColorManager.getBackgroundColorSolid(); |
| 364 | } else { |
| 365 | top = themeColorManager.getBackgroundColorTop(); |
| 366 | middle = themeColorManager.getBackgroundColorMiddle(); |
| 367 | bottom = themeColorManager.getBackgroundColorBottom(); |
| 368 | } |
| 369 | |
| 370 | if (progress < 0) { |
| 371 | float correctedProgress = Math.abs(progress); |
| 372 | top = ColorUtils.blendARGB(top, gray, correctedProgress); |
| 373 | middle = ColorUtils.blendARGB(middle, gray, correctedProgress); |
| 374 | bottom = ColorUtils.blendARGB(bottom, gray, correctedProgress); |
| 375 | } |
| 376 | |
| 377 | boolean backgroundDirty = false; |
| 378 | if (backgroundDrawable == null) { |
| 379 | backgroundDrawableColors = new int[] {top, middle, bottom}; |
| 380 | backgroundDrawable = new GradientDrawable(Orientation.TOP_BOTTOM, backgroundDrawableColors); |
| 381 | backgroundDirty = true; |
| 382 | } else { |
| 383 | if (backgroundDrawableColors[0] != top) { |
| 384 | backgroundDrawableColors[0] = top; |
| 385 | backgroundDirty = true; |
| 386 | } |
| 387 | if (backgroundDrawableColors[1] != middle) { |
| 388 | backgroundDrawableColors[1] = middle; |
| 389 | backgroundDirty = true; |
| 390 | } |
| 391 | if (backgroundDrawableColors[2] != bottom) { |
| 392 | backgroundDrawableColors[2] = bottom; |
| 393 | backgroundDirty = true; |
| 394 | } |
| 395 | if (backgroundDirty) { |
| 396 | backgroundDrawable.setColors(backgroundDrawableColors); |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | if (backgroundDirty) { |
| 401 | getWindow().setBackgroundDrawable(backgroundDrawable); |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | public boolean isVisible() { |
| 406 | return isVisible; |
| 407 | } |
| 408 | |
| 409 | public boolean getCallCardFragmentVisible() { |
| 410 | return didShowInCallScreen || didShowVideoCallScreen; |
| 411 | } |
| 412 | |
| 413 | public void dismissKeyguard(boolean dismiss) { |
| 414 | common.dismissKeyguard(dismiss); |
| 415 | } |
| 416 | |
| 417 | public void showPostCharWaitDialog(String callId, String chars) { |
| 418 | common.showPostCharWaitDialog(callId, chars); |
| 419 | } |
| 420 | |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 421 | public void maybeShowErrorDialogOnDisconnect(DisconnectMessage disconnectMessage) { |
| 422 | common.maybeShowErrorDialogOnDisconnect(disconnectMessage); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | public void dismissPendingDialogs() { |
| 426 | if (isVisible) { |
| 427 | LogUtil.i("InCallActivity.dismissPendingDialogs", ""); |
| 428 | common.dismissPendingDialogs(); |
| 429 | AnswerScreen answerScreen = getAnswerScreen(); |
| 430 | if (answerScreen != null) { |
| 431 | answerScreen.dismissPendingDialogs(); |
| 432 | } |
| 433 | needDismissPendingDialogs = false; |
| 434 | } else { |
| 435 | // The activity is not visible and onSaveInstanceState may have been called so defer the |
| 436 | // dismissing action. |
| 437 | LogUtil.i( |
| 438 | "InCallActivity.dismissPendingDialogs", "defer actions since activity is not visible"); |
| 439 | needDismissPendingDialogs = true; |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | private void enableInCallOrientationEventListener(boolean enable) { |
| 444 | common.enableInCallOrientationEventListener(enable); |
| 445 | } |
| 446 | |
| 447 | public void setExcludeFromRecents(boolean exclude) { |
| 448 | common.setExcludeFromRecents(exclude); |
| 449 | } |
| 450 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 451 | @Nullable |
| 452 | public FragmentManager getDialpadFragmentManager() { |
| 453 | InCallScreen inCallScreen = getInCallScreen(); |
| 454 | if (inCallScreen != null) { |
| 455 | return inCallScreen.getInCallScreenFragment().getChildFragmentManager(); |
| 456 | } |
| 457 | return null; |
| 458 | } |
| 459 | |
| 460 | public int getDialpadContainerId() { |
| 461 | return getInCallScreen().getAnswerAndDialpadContainerResourceId(); |
| 462 | } |
| 463 | |
| 464 | @Override |
| 465 | public AnswerScreenDelegate newAnswerScreenDelegate(AnswerScreen answerScreen) { |
| 466 | DialerCall call = CallList.getInstance().getCallById(answerScreen.getCallId()); |
| 467 | if (call == null) { |
| 468 | // This is a work around for a bug where we attempt to create a new delegate after the call |
| 469 | // has already been removed. An example of when this can happen is: |
| 470 | // 1. incoming video call in landscape mode |
| 471 | // 2. remote party hangs up |
| 472 | // 3. activity switches from landscape to portrait |
| 473 | // At step #3 the answer fragment will try to create a new answer delegate but the call won't |
| 474 | // exist. In this case we'll simply return a stub delegate that does nothing. This is ok |
| 475 | // because this new state is transient and the activity will be destroyed soon. |
| 476 | LogUtil.i("InCallActivity.onPrimaryCallStateChanged", "call doesn't exist, using stub"); |
| 477 | return new AnswerScreenPresenterStub(); |
| 478 | } else { |
| 479 | return new AnswerScreenPresenter( |
| 480 | this, answerScreen, CallList.getInstance().getCallById(answerScreen.getCallId())); |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | @Override |
| 485 | public InCallScreenDelegate newInCallScreenDelegate() { |
| 486 | return new CallCardPresenter(this); |
| 487 | } |
| 488 | |
| 489 | @Override |
| 490 | public InCallButtonUiDelegate newInCallButtonUiDelegate() { |
| 491 | return new CallButtonPresenter(this); |
| 492 | } |
| 493 | |
| 494 | @Override |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 495 | public VideoCallScreenDelegate newVideoCallScreenDelegate(VideoCallScreen videoCallScreen) { |
| 496 | DialerCall dialerCall = CallList.getInstance().getCallById(videoCallScreen.getCallId()); |
| 497 | if (dialerCall != null && dialerCall.getVideoTech().shouldUseSurfaceView()) { |
| 498 | return dialerCall.getVideoTech().createVideoCallScreenDelegate(this, videoCallScreen); |
| 499 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 500 | return new VideoCallPresenter(); |
| 501 | } |
| 502 | |
| 503 | public void onPrimaryCallStateChanged() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 504 | Trace.beginSection("InCallActivity.onPrimaryCallStateChanged"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 505 | LogUtil.i("InCallActivity.onPrimaryCallStateChanged", ""); |
| 506 | showMainInCallFragment(); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 507 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | public void onWiFiToLteHandover(DialerCall call) { |
| 511 | common.showWifiToLteHandoverToast(call); |
| 512 | } |
| 513 | |
| 514 | public void onHandoverToWifiFailed(DialerCall call) { |
| 515 | common.showWifiFailedDialog(call); |
| 516 | } |
| 517 | |
Eric Erfanian | c857f90 | 2017-05-15 14:05:33 -0700 | [diff] [blame] | 518 | public void onInternationalCallOnWifi(@NonNull DialerCall call) { |
| 519 | LogUtil.enterBlock("InCallActivity.onInternationalCallOnWifi"); |
| 520 | common.showInternationalCallOnWifiDialog(call); |
| 521 | } |
| 522 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 523 | public void setAllowOrientationChange(boolean allowOrientationChange) { |
| 524 | if (!allowOrientationChange) { |
| 525 | setRequestedOrientation(InCallOrientationEventListener.ACTIVITY_PREFERENCE_DISALLOW_ROTATION); |
| 526 | } else { |
| 527 | setRequestedOrientation(InCallOrientationEventListener.ACTIVITY_PREFERENCE_ALLOW_ROTATION); |
| 528 | } |
| 529 | enableInCallOrientationEventListener(allowOrientationChange); |
| 530 | } |
| 531 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 532 | public void hideMainInCallFragment() { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 533 | LogUtil.i("InCallActivity.hideMainInCallFragment", ""); |
| 534 | if (didShowInCallScreen || didShowVideoCallScreen) { |
| 535 | FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); |
| 536 | hideInCallScreenFragment(transaction); |
| 537 | hideVideoCallScreenFragment(transaction); |
| 538 | transaction.commitAllowingStateLoss(); |
| 539 | getSupportFragmentManager().executePendingTransactions(); |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | private void showMainInCallFragment() { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 544 | Trace.beginSection("InCallActivity.showMainInCallFragment"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 545 | // If the activity's onStart method hasn't been called yet then defer doing any work. |
| 546 | if (!isVisible) { |
| 547 | LogUtil.i("InCallActivity.showMainInCallFragment", "not visible yet/anymore"); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 548 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 549 | return; |
| 550 | } |
| 551 | |
| 552 | // Don't let this be reentrant. |
| 553 | if (isInShowMainInCallFragment) { |
| 554 | LogUtil.i("InCallActivity.showMainInCallFragment", "already in method, bailing"); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 555 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 556 | return; |
| 557 | } |
| 558 | |
| 559 | isInShowMainInCallFragment = true; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 560 | ShouldShowUiResult shouldShowAnswerUi = getShouldShowAnswerUi(); |
| 561 | ShouldShowUiResult shouldShowVideoUi = getShouldShowVideoUi(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 562 | LogUtil.i( |
| 563 | "InCallActivity.showMainInCallFragment", |
| 564 | "shouldShowAnswerUi: %b, shouldShowVideoUi: %b, " |
| 565 | + "didShowAnswerScreen: %b, didShowInCallScreen: %b, didShowVideoCallScreen: %b", |
| 566 | shouldShowAnswerUi.shouldShow, |
Eric Erfanian | 10b34a5 | 2017-05-04 08:23:17 -0700 | [diff] [blame] | 567 | shouldShowVideoUi.shouldShow, |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 568 | didShowAnswerScreen, |
| 569 | didShowInCallScreen, |
| 570 | didShowVideoCallScreen); |
| 571 | // Only video call ui allows orientation change. |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 572 | setAllowOrientationChange(shouldShowVideoUi.shouldShow); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 573 | |
| 574 | FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); |
| 575 | boolean didChangeInCall; |
| 576 | boolean didChangeVideo; |
| 577 | boolean didChangeAnswer; |
| 578 | if (shouldShowAnswerUi.shouldShow) { |
| 579 | didChangeInCall = hideInCallScreenFragment(transaction); |
| 580 | didChangeVideo = hideVideoCallScreenFragment(transaction); |
| 581 | didChangeAnswer = showAnswerScreenFragment(transaction, shouldShowAnswerUi.call); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 582 | } else if (shouldShowVideoUi.shouldShow) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 583 | didChangeInCall = hideInCallScreenFragment(transaction); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 584 | didChangeVideo = showVideoCallScreenFragment(transaction, shouldShowVideoUi.call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 585 | didChangeAnswer = hideAnswerScreenFragment(transaction); |
| 586 | } else { |
| 587 | didChangeInCall = showInCallScreenFragment(transaction); |
| 588 | didChangeVideo = hideVideoCallScreenFragment(transaction); |
| 589 | didChangeAnswer = hideAnswerScreenFragment(transaction); |
| 590 | } |
| 591 | |
| 592 | if (didChangeInCall || didChangeVideo || didChangeAnswer) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 593 | Trace.beginSection("InCallActivity.commitTransaction"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 594 | transaction.commitNow(); |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 595 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 596 | Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this); |
| 597 | } |
| 598 | isInShowMainInCallFragment = false; |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 599 | Trace.endSection(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 600 | } |
| 601 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 602 | private ShouldShowUiResult getShouldShowAnswerUi() { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 603 | DialerCall call = CallList.getInstance().getIncomingCall(); |
| 604 | if (call != null) { |
| 605 | LogUtil.i("InCallActivity.getShouldShowAnswerUi", "found incoming call"); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 606 | return new ShouldShowUiResult(true, call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | call = CallList.getInstance().getVideoUpgradeRequestCall(); |
| 610 | if (call != null) { |
| 611 | LogUtil.i("InCallActivity.getShouldShowAnswerUi", "found video upgrade request"); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 612 | return new ShouldShowUiResult(true, call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | // Check if we're showing the answer screen and the call is disconnected. If this condition is |
| 616 | // true then we won't switch from the answer UI to the in call UI. This prevents flicker when |
| 617 | // the user rejects an incoming call. |
| 618 | call = CallList.getInstance().getFirstCall(); |
| 619 | if (call == null) { |
| 620 | call = CallList.getInstance().getBackgroundCall(); |
| 621 | } |
| 622 | if (didShowAnswerScreen && (call == null || call.getState() == State.DISCONNECTED)) { |
| 623 | LogUtil.i("InCallActivity.getShouldShowAnswerUi", "found disconnecting incoming call"); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 624 | return new ShouldShowUiResult(true, call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 625 | } |
| 626 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 627 | return new ShouldShowUiResult(false, null); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 628 | } |
| 629 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 630 | private static ShouldShowUiResult getShouldShowVideoUi() { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 631 | DialerCall call = CallList.getInstance().getFirstCall(); |
| 632 | if (call == null) { |
| 633 | LogUtil.i("InCallActivity.getShouldShowVideoUi", "null call"); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 634 | return new ShouldShowUiResult(false, null); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 635 | } |
| 636 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 637 | if (call.isVideoCall()) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 638 | LogUtil.i("InCallActivity.getShouldShowVideoUi", "found video call"); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 639 | return new ShouldShowUiResult(true, call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 640 | } |
| 641 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 642 | if (call.hasSentVideoUpgradeRequest()) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 643 | LogUtil.i("InCallActivity.getShouldShowVideoUi", "upgrading to video"); |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 644 | return new ShouldShowUiResult(true, call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 645 | } |
| 646 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 647 | return new ShouldShowUiResult(false, null); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | private boolean showAnswerScreenFragment(FragmentTransaction transaction, DialerCall call) { |
| 651 | // When rejecting a call the active call can become null in which case we should continue |
| 652 | // showing the answer screen. |
| 653 | if (didShowAnswerScreen && call == null) { |
| 654 | return false; |
| 655 | } |
| 656 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 657 | Assert.checkArgument(call != null, "didShowAnswerScreen was false but call was still null"); |
| 658 | |
| 659 | boolean isVideoUpgradeRequest = call.hasReceivedVideoUpgradeRequest(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 660 | |
| 661 | // Check if we're already showing an answer screen for this call. |
| 662 | if (didShowAnswerScreen) { |
| 663 | AnswerScreen answerScreen = getAnswerScreen(); |
| 664 | if (answerScreen.getCallId().equals(call.getId()) |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 665 | && answerScreen.isVideoCall() == call.isVideoCall() |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 666 | && answerScreen.isVideoUpgradeRequest() == isVideoUpgradeRequest |
| 667 | && !answerScreen.isActionTimeout()) { |
| 668 | LogUtil.d( |
| 669 | "InCallActivity.showAnswerScreenFragment", |
| 670 | "answer fragment exists for same call and has NOT been accepted/rejected/timed out"); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 671 | return false; |
| 672 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 673 | if (answerScreen.isActionTimeout()) { |
| 674 | LogUtil.i( |
| 675 | "InCallActivity.showAnswerScreenFragment", |
| 676 | "answer fragment exists but has been accepted/rejected and timed out"); |
| 677 | } else { |
| 678 | LogUtil.i( |
| 679 | "InCallActivity.showAnswerScreenFragment", |
| 680 | "answer fragment exists but arguments do not match"); |
| 681 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 682 | hideAnswerScreenFragment(transaction); |
| 683 | } |
| 684 | |
| 685 | // Show a new answer screen. |
| 686 | AnswerScreen answerScreen = |
Eric Erfanian | fc37b02 | 2017-03-21 10:11:17 -0700 | [diff] [blame] | 687 | AnswerBindings.createAnswerScreen( |
| 688 | call.getId(), |
| 689 | call.isVideoCall(), |
| 690 | isVideoUpgradeRequest, |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 691 | call.getVideoTech().isSelfManagedCamera(), |
| 692 | shouldAllowAnswerAndRelease(call), |
| 693 | CallList.getInstance().getBackgroundCall() != null); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 694 | transaction.add(R.id.main, answerScreen.getAnswerScreenFragment(), TAG_ANSWER_SCREEN); |
| 695 | |
| 696 | Logger.get(this).logScreenView(ScreenEvent.Type.INCOMING_CALL, this); |
| 697 | didShowAnswerScreen = true; |
| 698 | return true; |
| 699 | } |
| 700 | |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 701 | private boolean shouldAllowAnswerAndRelease(DialerCall call) { |
| 702 | if (CallList.getInstance().getActiveCall() == null) { |
| 703 | LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "no active call"); |
| 704 | return false; |
| 705 | } |
| 706 | if (getSystemService(TelephonyManager.class).getPhoneType() |
| 707 | == TelephonyManager.PHONE_TYPE_CDMA) { |
| 708 | LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "PHONE_TYPE_CDMA not supported"); |
| 709 | return false; |
| 710 | } |
| 711 | if (call.isVideoCall() || call.hasReceivedVideoUpgradeRequest()) { |
| 712 | LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "video call"); |
| 713 | return false; |
| 714 | } |
| 715 | if (!ConfigProviderBindings.get(this).getBoolean(CONFIG_ANSWER_AND_RELEASE_ENABLED, true)) { |
| 716 | LogUtil.i("InCallActivity.shouldAllowAnswerAndRelease", "disabled by config"); |
| 717 | return false; |
| 718 | } |
| 719 | |
| 720 | return true; |
| 721 | } |
| 722 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 723 | private boolean hideAnswerScreenFragment(FragmentTransaction transaction) { |
| 724 | if (!didShowAnswerScreen) { |
| 725 | return false; |
| 726 | } |
| 727 | AnswerScreen answerScreen = getAnswerScreen(); |
| 728 | if (answerScreen != null) { |
| 729 | transaction.remove(answerScreen.getAnswerScreenFragment()); |
| 730 | } |
| 731 | |
| 732 | didShowAnswerScreen = false; |
| 733 | return true; |
| 734 | } |
| 735 | |
| 736 | private boolean showInCallScreenFragment(FragmentTransaction transaction) { |
| 737 | if (didShowInCallScreen) { |
| 738 | return false; |
| 739 | } |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 740 | InCallScreen inCallScreen = InCallBindings.createInCallScreen(); |
| 741 | transaction.add(R.id.main, inCallScreen.getInCallScreenFragment(), TAG_IN_CALL_SCREEN); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 742 | Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this); |
| 743 | didShowInCallScreen = true; |
| 744 | return true; |
| 745 | } |
| 746 | |
| 747 | private boolean hideInCallScreenFragment(FragmentTransaction transaction) { |
| 748 | if (!didShowInCallScreen) { |
| 749 | return false; |
| 750 | } |
| 751 | InCallScreen inCallScreen = getInCallScreen(); |
| 752 | if (inCallScreen != null) { |
Eric Erfanian | 2ca4318 | 2017-08-31 06:57:16 -0700 | [diff] [blame^] | 753 | transaction.remove(inCallScreen.getInCallScreenFragment()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 754 | } |
| 755 | didShowInCallScreen = false; |
| 756 | return true; |
| 757 | } |
| 758 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 759 | private boolean showVideoCallScreenFragment(FragmentTransaction transaction, DialerCall call) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 760 | if (didShowVideoCallScreen) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 761 | VideoCallScreen videoCallScreen = getVideoCallScreen(); |
| 762 | if (videoCallScreen.getCallId().equals(call.getId())) { |
| 763 | return false; |
| 764 | } |
| 765 | LogUtil.i( |
| 766 | "InCallActivity.showVideoCallScreenFragment", |
| 767 | "video call fragment exists but arguments do not match"); |
| 768 | hideVideoCallScreenFragment(transaction); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 769 | } |
| 770 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 771 | LogUtil.i("InCallActivity.showVideoCallScreenFragment", "call: %s", call); |
| 772 | |
Eric Erfanian | 9050823 | 2017-03-24 09:31:16 -0700 | [diff] [blame] | 773 | VideoCallScreen videoCallScreen = |
| 774 | VideoBindings.createVideoCallScreen( |
| 775 | call.getId(), call.getVideoTech().shouldUseSurfaceView()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 776 | transaction.add(R.id.main, videoCallScreen.getVideoCallScreenFragment(), TAG_VIDEO_CALL_SCREEN); |
| 777 | |
| 778 | Logger.get(this).logScreenView(ScreenEvent.Type.INCALL, this); |
| 779 | didShowVideoCallScreen = true; |
| 780 | return true; |
| 781 | } |
| 782 | |
| 783 | private boolean hideVideoCallScreenFragment(FragmentTransaction transaction) { |
| 784 | if (!didShowVideoCallScreen) { |
| 785 | return false; |
| 786 | } |
| 787 | VideoCallScreen videoCallScreen = getVideoCallScreen(); |
| 788 | if (videoCallScreen != null) { |
| 789 | transaction.remove(videoCallScreen.getVideoCallScreenFragment()); |
| 790 | } |
| 791 | didShowVideoCallScreen = false; |
| 792 | return true; |
| 793 | } |
| 794 | |
| 795 | AnswerScreen getAnswerScreen() { |
| 796 | return (AnswerScreen) getSupportFragmentManager().findFragmentByTag(TAG_ANSWER_SCREEN); |
| 797 | } |
| 798 | |
| 799 | InCallScreen getInCallScreen() { |
| 800 | return (InCallScreen) getSupportFragmentManager().findFragmentByTag(TAG_IN_CALL_SCREEN); |
| 801 | } |
| 802 | |
| 803 | VideoCallScreen getVideoCallScreen() { |
| 804 | return (VideoCallScreen) getSupportFragmentManager().findFragmentByTag(TAG_VIDEO_CALL_SCREEN); |
| 805 | } |
| 806 | |
| 807 | @Override |
| 808 | public void onPseudoScreenStateChanged(boolean isOn) { |
| 809 | LogUtil.i("InCallActivity.onPseudoScreenStateChanged", "isOn: " + isOn); |
| 810 | pseudoBlackScreenOverlay.setVisibility(isOn ? View.GONE : View.VISIBLE); |
| 811 | } |
| 812 | |
| 813 | /** |
| 814 | * For some touch related issue, turning off the screen can be faked by drawing a black view over |
| 815 | * the activity. All touch events started when the screen is "off" is rejected. |
| 816 | * |
| 817 | * @see PseudoScreenState |
| 818 | */ |
| 819 | @Override |
| 820 | public boolean dispatchTouchEvent(MotionEvent event) { |
| 821 | // Reject any gesture that started when the screen is in the fake off state. |
| 822 | if (touchDownWhenPseudoScreenOff) { |
| 823 | if (event.getAction() == MotionEvent.ACTION_UP) { |
| 824 | touchDownWhenPseudoScreenOff = false; |
| 825 | } |
| 826 | return true; |
| 827 | } |
| 828 | // Reject all touch event when the screen is in the fake off state. |
| 829 | if (!InCallPresenter.getInstance().getPseudoScreenState().isOn()) { |
| 830 | if (event.getAction() == MotionEvent.ACTION_DOWN) { |
| 831 | touchDownWhenPseudoScreenOff = true; |
| 832 | LogUtil.i("InCallActivity.dispatchTouchEvent", "touchDownWhenPseudoScreenOff"); |
| 833 | } |
| 834 | return true; |
| 835 | } |
| 836 | return super.dispatchTouchEvent(event); |
| 837 | } |
| 838 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 839 | private static class ShouldShowUiResult { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 840 | public final boolean shouldShow; |
| 841 | public final DialerCall call; |
| 842 | |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame] | 843 | ShouldShowUiResult(boolean shouldShow, DialerCall call) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 844 | this.shouldShow = shouldShow; |
| 845 | this.call = call; |
| 846 | } |
| 847 | } |
| 848 | } |