AnswerPresenter.java revision a4bd83ad639b349fa16dbd07225017fcbf6ed550
1/* 2 * Copyright (C) 2013 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 com.android.incallui.InCallPresenter.InCallState; 20import com.android.incallui.InCallPresenter.InCallStateListener; 21import com.android.services.telephony.common.Call; 22 23import java.util.ArrayList; 24 25/** 26 * Presenter for the Incoming call widget. 27 */ 28public class AnswerPresenter extends Presenter<AnswerPresenter.AnswerUi> 29 implements InCallStateListener { 30 31 private Call mCall; 32 private ArrayList<String> mTextResponses; 33 34 @Override 35 public void onUiReady(AnswerUi ui) { 36 super.onUiReady(ui); 37 } 38 39 @Override 40 public void onStateChange(InCallState state, CallList callList) { 41 if (state == InCallState.INCOMING) { 42 getUi().showAnswerUi(true); 43 mCall = callList.getIncomingCall(); 44 mTextResponses = callList.getTextResponses(mCall); 45 if (mTextResponses != null) { 46 getUi().showTextButton(true); 47 getUi().configureMessageDialogue(mTextResponses); 48 } else { 49 getUi().showTextButton(false); 50 } 51 Log.d(this, "Showing incoming with: " + mCall); 52 } else { 53 getUi().showAnswerUi(false); 54 mCall = null; 55 } 56 } 57 58 public void onAnswer() { 59 if (mCall == null) { 60 return; 61 } 62 63 Log.d(this, "onAnswer " + mCall.getCallId()); 64 65 CallCommandClient.getInstance().answerCall(mCall.getCallId()); 66 } 67 68 public void onDecline() { 69 if (mCall == null) { 70 return; 71 } 72 73 Log.d(this, "onDecline " + mCall.getCallId()); 74 75 CallCommandClient.getInstance().rejectCall(mCall.getCallId(), false, null); 76 } 77 78 public void onText() { 79 getUi().showMessageDialogue(); 80 } 81 82 public void rejectCallWithMessage(String message) { 83 Log.d(this, "sendTextToDefaultActivity()..."); 84 CallCommandClient.getInstance().rejectCall(mCall.getCallId(), true, message); 85 getUi().dismissPopup(); 86 } 87 88 interface AnswerUi extends Ui { 89 public void showAnswerUi(boolean show); 90 public void showTextButton(boolean show); 91 public boolean isMessageDialogueShowing(); 92 public void showMessageDialogue(); 93 public void dismissPopup(); 94 public void configureMessageDialogue(ArrayList<String> textResponses); 95 } 96} 97