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