@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();
  }
  private void initializeInCall() {
    if (mCallCardFragment == null) {
      mCallCardFragment =
          (CallCardFragment) getFragmentManager().findFragmentById(R.id.callCardFragment);
    }

    mChildFragmentManager = mCallCardFragment.getChildFragmentManager();

    if (mCallButtonFragment == null) {
      mCallButtonFragment =
          (CallButtonFragment) mChildFragmentManager.findFragmentById(R.id.callButtonFragment);
      mCallButtonFragment.getView().setVisibility(View.INVISIBLE);
    }

    if (mAnswerFragment == null) {
      mAnswerFragment =
          (AnswerFragment) mChildFragmentManager.findFragmentById(R.id.answerFragment);
    }

    if (mConferenceManagerFragment == null) {
      mConferenceManagerFragment =
          (ConferenceManagerFragment)
              getFragmentManager().findFragmentById(R.id.conferenceManagerFragment);
      mConferenceManagerFragment.getView().setVisibility(View.INVISIBLE);
    }
  }
  @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);
 }
 /**
  * Simulates a user click to hide the dialpad. This will update the UI to show the call card,
  * update the checked state of the dialpad button, and update the proximity sensor state.
  */
 public void hideDialpadForDisconnect() {
   mCallButtonFragment.displayDialpad(false /* show */, true /* animate */);
 }