private void updateDisplay(boolean announce) {
    if (mDayOfWeekView != null) {
      mDayOfWeekView.setText(
          mCalendar
              .getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault())
              .toUpperCase(Locale.getDefault()));
    }

    mSelectedMonthTextView.setText(
        mCalendar
            .getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault())
            .toUpperCase(Locale.getDefault()));
    mSelectedMonthTextViewEnd.setText(
        mCalendarEnd
            .getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.getDefault())
            .toUpperCase(Locale.getDefault()));
    mSelectedDayTextView.setText(DAY_FORMAT.format(mCalendar.getTime()));
    mSelectedDayTextViewEnd.setText(DAY_FORMAT.format(mCalendarEnd.getTime()));
    mYearView.setText(YEAR_FORMAT.format(mCalendar.getTime()));
    mYearViewEnd.setText(YEAR_FORMAT.format(mCalendarEnd.getTime()));

    // Accessibility.
    long millis = mCalendar.getTimeInMillis();
    long millisEnd = mCalendarEnd.getTimeInMillis();
    mAnimator.setDateMillis(millis);
    mAnimatorEnd.setDateMillis(millisEnd);
    int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR;
    String monthAndDayText = DateUtils.formatDateTime(getActivity(), millis, flags);
    String monthAndDayTextEnd = DateUtils.formatDateTime(getActivity(), millisEnd, flags);
    mMonthAndDayView.setContentDescription(monthAndDayText);
    mMonthAndDayViewEnd.setContentDescription(monthAndDayTextEnd);

    if (announce) {
      flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR;
      String fullDateText = DateUtils.formatDateTime(getActivity(), millis, flags);
      String fullDateTextEnd = DateUtils.formatDateTime(getActivity(), millisEnd, flags);
      Utils.tryAccessibilityAnnounce(mAnimator, fullDateText);
      Utils.tryAccessibilityAnnounce(mAnimatorEnd, fullDateTextEnd);
    }
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.d(TAG, "onCreateView: ");
    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    View view = inflater.inflate(R.layout.mdtp_date_picker_dialog, null);

    tabHost = (TabHost) view.findViewById(R.id.tabHost);
    tabHost.findViewById(R.id.tabHost);
    tabHost.setup();
    TabHost.TabSpec startDatePage = tabHost.newTabSpec("start");
    startDatePage.setContent(R.id.start_date_group);
    startDatePage.setIndicator("FROM");

    TabHost.TabSpec endDatePage = tabHost.newTabSpec("end");
    endDatePage.setContent(R.id.end_date_group);
    endDatePage.setIndicator("TO");

    tabHost.addTab(startDatePage);
    tabHost.addTab(endDatePage);

    mDayOfWeekView = (TextView) view.findViewById(R.id.date_picker_header);
    mMonthAndDayView = (LinearLayout) view.findViewById(R.id.date_picker_month_and_day);
    mMonthAndDayViewEnd = (LinearLayout) view.findViewById(R.id.date_picker_month_and_day_end);
    mMonthAndDayView.setOnClickListener(this);
    mMonthAndDayViewEnd.setOnClickListener(this);

    mSelectedMonthTextView = (TextView) view.findViewById(R.id.date_picker_month);
    mSelectedMonthTextViewEnd = (TextView) view.findViewById(R.id.date_picker_month_end);

    mSelectedDayTextView = (TextView) view.findViewById(R.id.date_picker_day);
    mSelectedDayTextViewEnd = (TextView) view.findViewById(R.id.date_picker_day_end);

    mYearView = (TextView) view.findViewById(R.id.date_picker_year);
    mYearViewEnd = (TextView) view.findViewById(R.id.date_picker_year_end);
    mYearView.setOnClickListener(this);
    mYearViewEnd.setOnClickListener(this);

    int listPosition = -1;
    int listPositionOffset = 0;
    int listPositionEnd = -1;
    int listPositionOffsetEnd = 0;
    int currentView = MONTH_AND_DAY_VIEW;
    int currentViewEnd = MONTH_AND_DAY_VIEW;
    if (savedInstanceState != null) {
      mWeekStart = savedInstanceState.getInt(KEY_WEEK_START);
      mWeekStartEnd = savedInstanceState.getInt(KEY_WEEK_START_END);
      mMinYear = savedInstanceState.getInt(KEY_YEAR_START);
      mMaxYear = savedInstanceState.getInt(KEY_YEAR_END);
      currentView = savedInstanceState.getInt(KEY_CURRENT_VIEW);
      currentViewEnd = savedInstanceState.getInt(KEY_CURRENT_VIEW_END);
      listPosition = savedInstanceState.getInt(KEY_LIST_POSITION);
      listPositionOffset = savedInstanceState.getInt(KEY_LIST_POSITION_OFFSET);
      listPositionEnd = savedInstanceState.getInt(KEY_LIST_POSITION_END);
      listPositionOffsetEnd = savedInstanceState.getInt(KEY_LIST_POSITION_OFFSET_END);
      mMinDate = (Calendar) savedInstanceState.getSerializable(KEY_MIN_DATE);
      mMaxDate = (Calendar) savedInstanceState.getSerializable(KEY_MAX_DATE);
      mMinDateEnd = (Calendar) savedInstanceState.getSerializable(KEY_MIN_DATE_END);
      mMaxDateEnd = (Calendar) savedInstanceState.getSerializable(KEY_MAX_DATE_END);
      highlightedDays = (Calendar[]) savedInstanceState.getSerializable(KEY_HIGHLIGHTED_DAYS);
      selectableDays = (Calendar[]) savedInstanceState.getSerializable(KEY_SELECTABLE_DAYS);
      highlightedDaysEnd =
          (Calendar[]) savedInstanceState.getSerializable(KEY_HIGHLIGHTED_DAYS_END);
      selectableDaysEnd = (Calendar[]) savedInstanceState.getSerializable(KEY_SELECTABLE_DAYS_END);
      mThemeDark = savedInstanceState.getBoolean(KEY_THEME_DARK);
      mAccentColor = savedInstanceState.getInt(KEY_ACCENT);
      mVibrate = savedInstanceState.getBoolean(KEY_VIBRATE);
      mDismissOnPause = savedInstanceState.getBoolean(KEY_DISMISS);
    }

    final Activity activity = getActivity();
    mDayPickerView =
        new com.borax12.materialdaterangepicker.date.SimpleDayPickerView(activity, this);
    mYearPickerView = new com.borax12.materialdaterangepicker.date.YearPickerView(activity, this);
    mDayPickerViewEnd =
        new com.borax12.materialdaterangepicker.date.SimpleDayPickerView(activity, this);
    mYearPickerViewEnd =
        new com.borax12.materialdaterangepicker.date.YearPickerView(activity, this);

    Resources res = getResources();
    mDayPickerDescription = res.getString(R.string.mdtp_day_picker_description);
    mSelectDay = res.getString(R.string.mdtp_select_day);
    mYearPickerDescription = res.getString(R.string.mdtp_year_picker_description);
    mSelectYear = res.getString(R.string.mdtp_select_year);

    int bgColorResource =
        mThemeDark
            ? R.color.mdtp_date_picker_view_animator_dark_theme
            : R.color.mdtp_date_picker_view_animator;
    view.setBackgroundColor(activity.getResources().getColor(bgColorResource));

    mAnimator =
        (com.borax12.materialdaterangepicker.date.AccessibleDateAnimator)
            view.findViewById(R.id.animator);
    mAnimatorEnd =
        (com.borax12.materialdaterangepicker.date.AccessibleDateAnimator)
            view.findViewById(R.id.animator_end);

    mAnimator.addView(mDayPickerView);
    mAnimator.addView(mYearPickerView);
    mAnimator.setDateMillis(mCalendar.getTimeInMillis());
    // TODO: Replace with animation decided upon by the design team.
    Animation animation = new AlphaAnimation(0.0f, 1.0f);
    animation.setDuration(ANIMATION_DURATION);
    mAnimator.setInAnimation(animation);
    // TODO: Replace with animation decided upon by the design team.
    Animation animation2 = new AlphaAnimation(1.0f, 0.0f);
    animation2.setDuration(ANIMATION_DURATION);
    mAnimator.setOutAnimation(animation2);

    mAnimatorEnd.addView(mDayPickerViewEnd);
    mAnimatorEnd.addView(mYearPickerViewEnd);
    mAnimatorEnd.setDateMillis(mCalendarEnd.getTimeInMillis());
    // TODO: Replace with animation decided upon by the design team.
    Animation animationEnd = new AlphaAnimation(0.0f, 1.0f);
    animationEnd.setDuration(ANIMATION_DURATION);
    mAnimatorEnd.setInAnimation(animation);
    // TODO: Replace with animation decided upon by the design team.
    Animation animation2End = new AlphaAnimation(1.0f, 0.0f);
    animation2End.setDuration(ANIMATION_DURATION);
    mAnimatorEnd.setOutAnimation(animation2);

    Button okButton = (Button) view.findViewById(R.id.ok);
    okButton.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            tryVibrate();
            if (mCallBack != null) {
              mCallBack.onDateSet(
                  DatePickerDialog.this,
                  mCalendar.get(Calendar.YEAR),
                  mCalendar.get(Calendar.MONTH),
                  mCalendar.get(Calendar.DAY_OF_MONTH),
                  mCalendarEnd.get(Calendar.YEAR),
                  mCalendarEnd.get(Calendar.MONTH),
                  mCalendarEnd.get(Calendar.DAY_OF_MONTH));
            }
            dismiss();
          }
        });
    okButton.setTypeface(TypefaceHelper.get(activity, "Roboto-Medium"));

    Button cancelButton = (Button) view.findViewById(R.id.cancel);
    cancelButton.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            tryVibrate();
            if (getDialog() != null) getDialog().cancel();
          }
        });
    cancelButton.setTypeface(TypefaceHelper.get(activity, "Roboto-Medium"));
    cancelButton.setVisibility(isCancelable() ? View.VISIBLE : View.GONE);

    // If an accent color has not been set manually, try and get it from the context
    if (mAccentColor == -1) {
      int accentColor = Utils.getAccentColorFromThemeIfAvailable(getActivity());
      if (accentColor != -1) {
        mAccentColor = accentColor;
      }
    }
    if (mAccentColor != -1) {
      if (mDayOfWeekView != null)
        mDayOfWeekView.setBackgroundColor(Utils.darkenColor(mAccentColor));
      view.findViewById(R.id.day_picker_selected_date_layout).setBackgroundColor(mAccentColor);
      view.findViewById(R.id.day_picker_selected_date_layout_end).setBackgroundColor(mAccentColor);
      okButton.setTextColor(mAccentColor);
      cancelButton.setTextColor(mAccentColor);
      mYearPickerView.setAccentColor(mAccentColor);
      mDayPickerView.setAccentColor(mAccentColor);
      mYearPickerViewEnd.setAccentColor(mAccentColor);
      mDayPickerViewEnd.setAccentColor(mAccentColor);
    }

    updateDisplay(false);
    setCurrentView(currentView);

    if (listPosition != -1) {
      if (currentView == MONTH_AND_DAY_VIEW) {
        mDayPickerView.postSetSelection(listPosition);
      } else if (currentView == YEAR_VIEW) {
        mYearPickerView.postSetSelectionFromTop(listPosition, listPositionOffset);
      }
    }

    if (listPositionEnd != -1) {
      if (currentViewEnd == MONTH_AND_DAY_VIEW) {
        mDayPickerViewEnd.postSetSelection(listPositionEnd);
      } else if (currentViewEnd == YEAR_VIEW) {
        mYearPickerViewEnd.postSetSelectionFromTop(listPositionEnd, listPositionOffsetEnd);
      }
    }

    mHapticFeedbackController = new HapticFeedbackController(activity);

    tabHost.setOnTabChangedListener(
        new TabHost.OnTabChangeListener() {
          @Override
          public void onTabChanged(String tabId) {
            com.borax12.materialdaterangepicker.date.MonthAdapter.CalendarDay calendarDay;
            if (tabId == "start") {
              calendarDay =
                  new com.borax12.materialdaterangepicker.date.MonthAdapter.CalendarDay(
                      mCalendar.getTimeInMillis());
              mDayPickerView.goTo(calendarDay, true, true, false);
            } else {
              calendarDay =
                  new com.borax12.materialdaterangepicker.date.MonthAdapter.CalendarDay(
                      mCalendarEnd.getTimeInMillis());
              mDayPickerViewEnd.goTo(calendarDay, true, true, false);
            }
          }
        });
    return view;
  }