1e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen/* 2e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen * Copyright (C) 2013 The Android Open Source Project 3e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen * 4e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen * Licensed under the Apache License, Version 2.0 (the "License"); 5e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen * you may not use this file except in compliance with the License. 6e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen * You may obtain a copy of the License at 7e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen * 8e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen * http://www.apache.org/licenses/LICENSE-2.0 9e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen * 10e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen * Unless required by applicable law or agreed to in writing, software 11e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen * distributed under the License is distributed on an "AS IS" BASIS, 12e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen * See the License for the specific language governing permissions and 14e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen * limitations under the License 15e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen */ 16e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen 17e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chenpackage com.android.incallui; 18e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen 19e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chenimport android.telephony.PhoneNumberUtils; 20e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen 21e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen/** 22e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen * Logic for call buttons. 23e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen */ 24e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chenpublic class DialpadPresenter extends Presenter<DialpadPresenter.DialpadUi> 25e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen implements InCallPresenter.InCallStateListener { 26e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen 27d11c7a03578697637f97e26758ac5bd96c85e967Ihab Awad private Call mCall; 28d11c7a03578697637f97e26758ac5bd96c85e967Ihab Awad 29e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen @Override 30e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen public void onUiReady(DialpadUi ui) { 31e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen super.onUiReady(ui); 324012cdcc2beecb20b7d5efb3fb869f8326dbe861Sailesh Nepal InCallPresenter.getInstance().addListener(this); 33d644aef567decca5d6351bb4def4b4e65517836eYorke Lee mCall = CallList.getInstance().getOutgoingOrActive(); 34e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen } 35e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen 36e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen @Override 374012cdcc2beecb20b7d5efb3fb869f8326dbe861Sailesh Nepal public void onUiUnready(DialpadUi ui) { 384012cdcc2beecb20b7d5efb3fb869f8326dbe861Sailesh Nepal super.onUiUnready(ui); 394012cdcc2beecb20b7d5efb3fb869f8326dbe861Sailesh Nepal InCallPresenter.getInstance().removeListener(this); 404012cdcc2beecb20b7d5efb3fb869f8326dbe861Sailesh Nepal } 414012cdcc2beecb20b7d5efb3fb869f8326dbe861Sailesh Nepal 424012cdcc2beecb20b7d5efb3fb869f8326dbe861Sailesh Nepal @Override 43f003346e5f9ba29e869a881bcca2e59d6ea8e0f6Nancy Chen public void onStateChange(InCallPresenter.InCallState oldState, 44f003346e5f9ba29e869a881bcca2e59d6ea8e0f6Nancy Chen InCallPresenter.InCallState newState, CallList callList) { 45d644aef567decca5d6351bb4def4b4e65517836eYorke Lee mCall = callList.getOutgoingOrActive(); 46d11c7a03578697637f97e26758ac5bd96c85e967Ihab Awad Log.d(this, "DialpadPresenter mCall = " + mCall); 47e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen } 48e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen 49e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen /** 50e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen * Processes the specified digit as a DTMF key, by playing the 51e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen * appropriate DTMF tone, and appending the digit to the EditText 52e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen * field that displays the DTMF digits sent so far. 53e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen * 54e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen */ 55e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen public final void processDtmf(char c) { 56a4bd83ad639b349fa16dbd07225017fcbf6ed550Chiao Cheng Log.d(this, "Processing dtmf key " + c); 57e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen // if it is a valid key, then update the display and send the dtmf tone. 58d11c7a03578697637f97e26758ac5bd96c85e967Ihab Awad if (PhoneNumberUtils.is12Key(c) && mCall != null) { 59248a6687e8075e9730217be73c54ee4f95501a0eSailesh Nepal Log.d(this, "updating display and sending dtmf tone for '" + c + "'"); 60248a6687e8075e9730217be73c54ee4f95501a0eSailesh Nepal 61248a6687e8075e9730217be73c54ee4f95501a0eSailesh Nepal // Append this key to the "digits" widget. 62248a6687e8075e9730217be73c54ee4f95501a0eSailesh Nepal getUi().appendDigitsToField(c); 639124b77e489772fb7c6aac36f83d86ffdf83748fJay Shrauner // Plays the tone through Telecom. 644b293f0f08030c97e1bb54d2f79ac2fb1a6e29aeTyler Gunn TelecomAdapter.getInstance().playDtmfTone(mCall.getId(), c); 65e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen } else { 66a4bd83ad639b349fa16dbd07225017fcbf6ed550Chiao Cheng Log.d(this, "ignoring dtmf request for '" + c + "'"); 67e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen } 68e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen } 69e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen 70e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen /** 71e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen * Stops the local tone based on the phone type. 72e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen */ 7372dd0d42c60418da0e006ea9ea39fb2da2898a05Santos Cordon public void stopDtmf() { 74d11c7a03578697637f97e26758ac5bd96c85e967Ihab Awad if (mCall != null) { 75d11c7a03578697637f97e26758ac5bd96c85e967Ihab Awad Log.d(this, "stopping remote tone"); 764b293f0f08030c97e1bb54d2f79ac2fb1a6e29aeTyler Gunn TelecomAdapter.getInstance().stopDtmfTone(mCall.getId()); 77d11c7a03578697637f97e26758ac5bd96c85e967Ihab Awad } 78e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen } 79e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen 80e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen public interface DialpadUi extends Ui { 81e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen void setVisible(boolean on); 82e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen void appendDigitsToField(char digit); 83e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen } 84e7097d78980eccdc2425266db92a3e88f4f5c1a5Christine Chen} 85