blob: e6fbdc22d6419808ba701e9baeee57814f713da0 [file] [log] [blame]
Eric Erfanianccca3152017-02-22 16:32:36 -08001/*
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 android.telephony.PhoneNumberUtils;
20import com.android.incallui.DialpadPresenter.DialpadUi;
21import com.android.incallui.baseui.Presenter;
22import com.android.incallui.baseui.Ui;
23import com.android.incallui.call.CallList;
24import com.android.incallui.call.DialerCall;
25import com.android.incallui.call.TelecomAdapter;
26
27/** Logic for call buttons. */
28public class DialpadPresenter extends Presenter<DialpadUi>
29 implements InCallPresenter.InCallStateListener {
30
linyuh183cb712017-12-27 17:02:37 -080031 private DialerCall call;
Eric Erfanianccca3152017-02-22 16:32:36 -080032
33 @Override
34 public void onUiReady(DialpadUi ui) {
35 super.onUiReady(ui);
36 InCallPresenter.getInstance().addListener(this);
linyuh183cb712017-12-27 17:02:37 -080037 call = CallList.getInstance().getOutgoingOrActive();
Eric Erfanianccca3152017-02-22 16:32:36 -080038 }
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) {
linyuh183cb712017-12-27 17:02:37 -080051 call = callList.getOutgoingOrActive();
52 Log.d(this, "DialpadPresenter mCall = " + call);
Eric Erfanianccca3152017-02-22 16:32:36 -080053 }
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.
linyuh183cb712017-12-27 17:02:37 -080062 if (PhoneNumberUtils.is12Key(c) && call != null) {
Eric Erfanianccca3152017-02-22 16:32:36 -080063 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.
linyuh183cb712017-12-27 17:02:37 -080071 TelecomAdapter.getInstance().playDtmfTone(call.getId(), c);
Eric Erfanianccca3152017-02-22 16:32:36 -080072 } 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() {
linyuh183cb712017-12-27 17:02:37 -080079 if (call != null) {
Eric Erfanianccca3152017-02-22 16:32:36 -080080 Log.d(this, "stopping remote tone");
linyuh183cb712017-12-27 17:02:37 -080081 TelecomAdapter.getInstance().stopDtmfTone(call.getId());
Eric Erfanianccca3152017-02-22 16:32:36 -080082 }
83 }
84
85 public interface DialpadUi extends Ui {
86
Eric Erfanianccca3152017-02-22 16:32:36 -080087 void appendDigitsToField(char digit);
88 }
89}