@Override
  public void onBackPressed() {
    Log.i(this, "onBackPressed");

    // BACK is also used to exit out of any "special modes" of the
    // in-call UI:

    if (!mConferenceManagerFragment.isVisible() && !mCallCardFragment.isVisible()) {
      return;
    }

    if (mDialpadFragment != null && mDialpadFragment.isVisible()) {
      mCallButtonFragment.displayDialpad(false /* show */, true /* animate */);
      return;
    } else if (mConferenceManagerFragment.isVisible()) {
      showConferenceCallManager(false);
      return;
    }

    // Always disable the Back key while an incoming call is ringing
    final Call call = CallList.getInstance().getIncomingCall();
    if (call != null) {
      Log.d(this, "Consume Back press for an incoming call");
      return;
    }

    // Nothing special to do.  Fall back to the default behavior.
    super.onBackPressed();
  }
 @Override
 public boolean onKeyUp(int keyCode, KeyEvent event) {
   // push input to the dialer.
   if (mDialpadFragment != null
       && (mDialpadFragment.isVisible())
       && (mDialpadFragment.onDialerKeyUp(event))) {
     return true;
   } else if (keyCode == KeyEvent.KEYCODE_CALL) {
     // Always consume CALL to be sure the PhoneWindow won't do anything with it
     return true;
   }
   return super.onKeyUp(keyCode, event);
 }
  @Override
  protected void onResume() {
    Log.i(this, "onResume()...");
    super.onResume();

    mIsForegroundActivity = true;

    InCallPresenter.getInstance().setThemeColors();
    InCallPresenter.getInstance().onUiShowing(true);

    if (mShowDialpadRequested) {
      mCallButtonFragment.displayDialpad(true /* show */, mAnimateDialpadOnShow /* animate */);
      mShowDialpadRequested = false;
      mAnimateDialpadOnShow = false;

      if (mDialpadFragment != null) {
        mDialpadFragment.setDtmfText(mDtmfText);
        mDtmfText = null;
      }
    }

    if (mShowPostCharWaitDialogOnResume) {
      showPostCharWaitDialog(mShowPostCharWaitDialogCallId, mShowPostCharWaitDialogChars);
    }
  }
 @Override
 protected void onSaveInstanceState(Bundle out) {
   out.putBoolean(SHOW_DIALPAD_EXTRA, mCallButtonFragment.isDialpadVisible());
   if (mDialpadFragment != null) {
     out.putString(DIALPAD_TEXT_EXTRA, mDialpadFragment.getDtmfText());
   }
   super.onSaveInstanceState(out);
 }
  private boolean handleDialerKeyDown(int keyCode, KeyEvent event) {
    Log.v(this, "handleDialerKeyDown: keyCode " + keyCode + ", event " + event + "...");

    // As soon as the user starts typing valid dialable keys on the
    // keyboard (presumably to type DTMF tones) we start passing the
    // key events to the DTMFDialer's onDialerKeyDown.
    if (mDialpadFragment != null && mDialpadFragment.isVisible()) {
      return mDialpadFragment.onDialerKeyDown(event);

      // TODO: If the dialpad isn't currently visible, maybe
      // consider automatically bringing it up right now?
      // (Just to make sure the user sees the digits widget...)
      // But this probably isn't too critical since it's awkward to
      // use the hard keyboard while in-call in the first place,
      // especially now that the in-call UI is portrait-only...
    }

    return false;
  }
  public void displayDialpad(boolean showDialpad, boolean animate) {
    // If the dialpad is already visible, don't animate in. If it's gone, don't animate out.
    if ((showDialpad && isDialpadVisible()) || (!showDialpad && !isDialpadVisible())) {
      return;
    }
    // We don't do a FragmentTransaction on the hide case because it will be dealt with when
    // the listener is fired after an animation finishes.
    if (!animate) {
      showDialpad(showDialpad);
    } else {
      if (showDialpad) {
        showDialpad(true);
        mDialpadFragment.animateShowDialpad();
      }
      mCallCardFragment.onDialpadVisiblityChange(showDialpad);
      mDialpadFragment.getView().startAnimation(showDialpad ? mSlideIn : mSlideOut);
    }

    InCallPresenter.getInstance().getProximitySensor().onDialpadVisible(showDialpad);
  }
  // onPause is guaranteed to be called when the InCallActivity goes
  // in the background.
  @Override
  protected void onPause() {
    Log.d(this, "onPause()...");
    super.onPause();

    mIsForegroundActivity = false;

    if (mDialpadFragment != null) {
      mDialpadFragment.onDialerKeyUp(null);
    }

    InCallPresenter.getInstance().onUiShowing(false);
    if (isFinishing()) {
      InCallPresenter.getInstance().unsetActivity(this);
    }
  }
 public boolean isDialpadVisible() {
   return mDialpadFragment != null && mDialpadFragment.isVisible();
 }