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