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 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 
     31   private DialerCall mCall;
     32 
     33   @Override
     34   public void onUiReady(DialpadUi ui) {
     35     super.onUiReady(ui);
     36     InCallPresenter.getInstance().addListener(this);
     37     mCall = CallList.getInstance().getOutgoingOrActive();
     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) {
     51     mCall = callList.getOutgoingOrActive();
     52     Log.d(this, "DialpadPresenter mCall = " + mCall);
     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.
     62     if (PhoneNumberUtils.is12Key(c) && mCall != null) {
     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.
     71       TelecomAdapter.getInstance().playDtmfTone(mCall.getId(), c);
     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() {
     79     if (mCall != null) {
     80       Log.d(this, "stopping remote tone");
     81       TelecomAdapter.getInstance().stopDtmfTone(mCall.getId());
     82     }
     83   }
     84 
     85   public interface DialpadUi extends Ui {
     86 
     87     void setVisible(boolean on);
     88 
     89     void appendDigitsToField(char digit);
     90   }
     91 }
     92