private void showDialpadFragment(boolean animate) {
   mDialpadFragment.setAdjustTranslationForAnimation(animate);
   final FragmentTransaction ft = getFragmentManager().beginTransaction();
   if (animate) {
     ft.setCustomAnimations(R.anim.slide_in, 0);
   } else {
     mDialpadFragment.setYFraction(0);
   }
   ft.show(mDialpadFragment);
   ft.commit();
 }
 public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
   if (mDialpadFragment == null) return;
   if (clearDialpad) {
     mDialpadFragment.clearDialpad();
   }
   if (!mDialpadFragment.isVisible()) return;
   mDialpadFragment.setAdjustTranslationForAnimation(animate);
   final FragmentTransaction ft = getFragmentManager().beginTransaction();
   if (animate) {
     ft.setCustomAnimations(0, R.anim.slide_out);
   }
   ft.hide(mDialpadFragment);
   ft.commit();
 }
 @Override
 public void onBackPressed() {
   if (mDialpadFragment != null && mDialpadFragment.isVisible()) {
     hideDialpadFragment(true, false);
   } else if (getInSearchUi()) {
     mSearchView.setText(null);
     mDialpadFragment.clearDialpad();
   } else if (isTaskRoot()) {
     // Instead of stopping, simply push this to the back of the stack.
     // This is only done when running at the top of the stack;
     // otherwise, we have been launched by someone else so need to
     // allow the user to go back to the caller.
     moveTaskToBack(false);
   } else {
     super.onBackPressed();
   }
 }
  /**
   * Sets the current tab based on the intent's request type
   *
   * @param intent Intent that contains information about which tab should be selected
   */
  private void displayFragment(Intent intent) {
    // If we got here by hitting send and we're in call forward along to the in-call activity
    boolean recentCallsRequest =
        Calls.CONTENT_TYPE.equals(intent.resolveType(getContentResolver()));
    if (isSendKeyWhileInCall(intent, recentCallsRequest)) {
      finish();
      return;
    }

    if (mDialpadFragment != null) {
      final boolean phoneIsInUse = phoneIsInUse();
      if (phoneIsInUse || isDialIntent(intent)) {
        mDialpadFragment.setStartedFromNewIntent(true);
        if (phoneIsInUse && !mDialpadFragment.isVisible()) {
          mInCallDialpadUp = true;
        }
        showDialpadFragment(false);
      }
    }
  }
 @Override
 public void onDialpadQueryChanged(String query) {
   final String normalizedQuery =
       SmartDialNameMatcher.normalizeNumber(query, SmartDialNameMatcher.LATIN_SMART_DIAL_MAP);
   if (!TextUtils.equals(mSearchView.getText(), normalizedQuery)) {
     if (DEBUG) {
       Log.d(TAG, "onDialpadQueryChanged - new query: " + query);
     }
     if (mDialpadFragment == null || !mDialpadFragment.isVisible()) {
       // This callback can happen if the dialpad fragment is recreated because of
       // activity destruction. In that case, don't update the search view because
       // that would bring the user back to the search fragment regardless of the
       // previous state of the application. Instead, just return here and let the
       // fragment manager correctly figure out whatever fragment was last displayed.
       return;
     }
     mSearchView.setText(normalizedQuery);
   }
 }
 @Override
 public void onClick(View view) {
   switch (view.getId()) {
     case R.id.overflow_menu:
       {
         mOverflowMenu.show();
         break;
       }
     case R.id.dialpad_button:
       // Reset the boolean flag that tracks whether the dialpad was up because
       // we were in call. Regardless of whether it was true before, we want to
       // show the dialpad because the user has explicitly clicked the dialpad
       // button.
       mInCallDialpadUp = false;
       showDialpadFragment(true);
       break;
     case R.id.call_history_on_dialpad_button:
     case R.id.call_history_button:
       // Use explicit CallLogActivity intent instead of ACTION_VIEW +
       // CONTENT_TYPE, so that we always open our call log from our dialer
       final Intent intent = new Intent(this, CallLogActivity.class);
       startActivity(intent);
       break;
     case R.id.search_close_button:
       // Clear the search field
       if (!TextUtils.isEmpty(mSearchView.getText())) {
         mDialpadFragment.clearDialpad();
         mSearchView.setText("");
       }
       break;
     case R.id.voice_search_button:
       final Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
       startActivityForResult(voiceIntent, ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
       break;
     default:
       {
         Log.wtf(TAG, "Unexpected onClick event from " + view);
         break;
       }
   }
 }
 private boolean isDialpadShowing() {
   return mDialpadFragment != null && mDialpadFragment.isVisible();
 }