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.support.annotation.FloatRange; |
| 21 | import android.support.annotation.NonNull; |
| 22 | import android.support.v4.os.UserManagerCompat; |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame^] | 23 | import android.telecom.VideoProfile; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 24 | import com.android.dialer.common.Assert; |
| 25 | import com.android.dialer.common.LogUtil; |
| 26 | import com.android.incallui.answer.protocol.AnswerScreen; |
| 27 | import com.android.incallui.answer.protocol.AnswerScreenDelegate; |
| 28 | import com.android.incallui.answerproximitysensor.AnswerProximitySensor; |
| 29 | import com.android.incallui.answerproximitysensor.PseudoScreenState; |
| 30 | import com.android.incallui.call.DialerCall; |
| 31 | |
| 32 | /** Manages changes for an incoming call screen. */ |
| 33 | public class AnswerScreenPresenter |
| 34 | implements AnswerScreenDelegate, DialerCall.CannedTextResponsesLoadedListener { |
| 35 | @NonNull private final Context context; |
| 36 | @NonNull private final AnswerScreen answerScreen; |
| 37 | @NonNull private final DialerCall call; |
| 38 | |
| 39 | public AnswerScreenPresenter( |
| 40 | @NonNull Context context, @NonNull AnswerScreen answerScreen, @NonNull DialerCall call) { |
| 41 | LogUtil.i("AnswerScreenPresenter.constructor", null); |
| 42 | this.context = Assert.isNotNull(context); |
| 43 | this.answerScreen = Assert.isNotNull(answerScreen); |
| 44 | this.call = Assert.isNotNull(call); |
| 45 | if (isSmsResponseAllowed(call)) { |
| 46 | answerScreen.setTextResponses(call.getCannedSmsResponses()); |
| 47 | } |
| 48 | call.addCannedTextResponsesLoadedListener(this); |
| 49 | |
| 50 | PseudoScreenState pseudoScreenState = InCallPresenter.getInstance().getPseudoScreenState(); |
| 51 | if (AnswerProximitySensor.shouldUse(context, call)) { |
| 52 | new AnswerProximitySensor(context, call, pseudoScreenState); |
| 53 | } else { |
| 54 | pseudoScreenState.setOn(true); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public void onAnswerScreenUnready() { |
| 60 | call.removeCannedTextResponsesLoadedListener(this); |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public void onDismissDialog() { |
| 65 | InCallPresenter.getInstance().onDismissDialog(); |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public void onRejectCallWithMessage(String message) { |
| 70 | call.reject(true /* rejectWithMessage */, message); |
| 71 | onDismissDialog(); |
| 72 | } |
| 73 | |
| 74 | @Override |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame^] | 75 | public void onAnswer(boolean answerVideoAsAudio) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 76 | if (answerScreen.isVideoUpgradeRequest()) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame^] | 77 | if (answerVideoAsAudio) { |
| 78 | call.getVideoTech().acceptVideoRequestAsAudio(); |
| 79 | } else { |
| 80 | call.getVideoTech().acceptVideoRequest(); |
| 81 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 82 | } else { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame^] | 83 | if (answerVideoAsAudio) { |
| 84 | call.answer(VideoProfile.STATE_AUDIO_ONLY); |
| 85 | } else { |
| 86 | call.answer(); |
| 87 | } |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public void onReject() { |
| 93 | if (answerScreen.isVideoUpgradeRequest()) { |
Eric Erfanian | d5e47f6 | 2017-03-15 14:41:07 -0700 | [diff] [blame^] | 94 | call.getVideoTech().declineVideoRequest(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 95 | } else { |
| 96 | call.reject(false /* rejectWithMessage */, null); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public void onCannedTextResponsesLoaded(DialerCall call) { |
| 102 | if (isSmsResponseAllowed(call)) { |
| 103 | answerScreen.setTextResponses(call.getCannedSmsResponses()); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public void updateWindowBackgroundColor(@FloatRange(from = -1f, to = 1.0f) float progress) { |
| 109 | InCallActivity activity = (InCallActivity) answerScreen.getAnswerScreenFragment().getActivity(); |
| 110 | if (activity != null) { |
| 111 | activity.updateWindowBackgroundColor(progress); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | private boolean isSmsResponseAllowed(DialerCall call) { |
| 116 | return UserManagerCompat.isUserUnlocked(context) |
| 117 | && call.can(android.telecom.Call.Details.CAPABILITY_RESPOND_VIA_TEXT); |
| 118 | } |
| 119 | } |