Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 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 | |
| 17 | package com.android.incallui; |
| 18 | |
| 19 | import android.telephony.PhoneNumberUtils; |
| 20 | import com.android.incallui.DialpadPresenter.DialpadUi; |
| 21 | import com.android.incallui.baseui.Presenter; |
| 22 | import com.android.incallui.baseui.Ui; |
| 23 | import com.android.incallui.call.CallList; |
| 24 | import com.android.incallui.call.DialerCall; |
| 25 | import com.android.incallui.call.TelecomAdapter; |
| 26 | |
| 27 | /** Logic for call buttons. */ |
| 28 | public class DialpadPresenter extends Presenter<DialpadUi> |
| 29 | implements InCallPresenter.InCallStateListener { |
| 30 | |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 31 | private DialerCall call; |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 32 | |
| 33 | @Override |
| 34 | public void onUiReady(DialpadUi ui) { |
| 35 | super.onUiReady(ui); |
| 36 | InCallPresenter.getInstance().addListener(this); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 37 | call = CallList.getInstance().getOutgoingOrActive(); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | @Override |
| 41 | public void onUiUnready(DialpadUi ui) { |
| 42 | super.onUiUnready(ui); |
| 43 | InCallPresenter.getInstance().removeListener(this); |
| 44 | } |
| 45 | |
| 46 | @Override |
| 47 | public void onStateChange( |
| 48 | InCallPresenter.InCallState oldState, |
| 49 | InCallPresenter.InCallState newState, |
| 50 | CallList callList) { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 51 | call = callList.getOutgoingOrActive(); |
| 52 | Log.d(this, "DialpadPresenter mCall = " + call); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Processes the specified digit as a DTMF key, by playing the appropriate DTMF tone, and |
| 57 | * appending the digit to the EditText field that displays the DTMF digits sent so far. |
| 58 | */ |
| 59 | public final void processDtmf(char c) { |
| 60 | Log.d(this, "Processing dtmf key " + c); |
| 61 | // if it is a valid key, then update the display and send the dtmf tone. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 62 | if (PhoneNumberUtils.is12Key(c) && call != null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 63 | Log.d(this, "updating display and sending dtmf tone for '" + c + "'"); |
| 64 | |
| 65 | // Append this key to the "digits" widget. |
| 66 | DialpadUi dialpadUi = getUi(); |
| 67 | if (dialpadUi != null) { |
| 68 | dialpadUi.appendDigitsToField(c); |
| 69 | } |
| 70 | // Plays the tone through Telecom. |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 71 | TelecomAdapter.getInstance().playDtmfTone(call.getId(), c); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 72 | } else { |
| 73 | Log.d(this, "ignoring dtmf request for '" + c + "'"); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | /** Stops the local tone based on the phone type. */ |
| 78 | public void stopDtmf() { |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 79 | if (call != null) { |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 80 | Log.d(this, "stopping remote tone"); |
linyuh | 183cb71 | 2017-12-27 17:02:37 -0800 | [diff] [blame] | 81 | TelecomAdapter.getInstance().stopDtmfTone(call.getId()); |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | |
| 85 | public interface DialpadUi extends Ui { |
| 86 | |
Eric Erfanian | ccca315 | 2017-02-22 16:32:36 -0800 | [diff] [blame] | 87 | void appendDigitsToField(char digit); |
| 88 | } |
| 89 | } |