public void setYearRange(int startYear, int endYear) {
   if (endYear <= startYear) {
     throw new IllegalArgumentException("Year end must be larger than year start");
   }
   mMinYear = startYear;
   mMaxYear = endYear;
   if (mDayPickerView != null) {
     mDayPickerView.onChange();
   }
 }
 public void setFirstDayOfWeek(int startOfWeek) {
   if (startOfWeek < Calendar.SUNDAY || startOfWeek > Calendar.SATURDAY) {
     throw new IllegalArgumentException(
         "Value must be between Calendar.SUNDAY and " + "Calendar.SATURDAY");
   }
   mWeekStart = startOfWeek;
   if (mDayPickerView != null) {
     mDayPickerView.onChange();
   }
 }
  @Override
  public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putInt(KEY_SELECTED_YEAR, mCalendar.get(Calendar.YEAR));
    outState.putInt(KEY_SELECTED_MONTH, mCalendar.get(Calendar.MONTH));
    outState.putInt(KEY_SELECTED_DAY, mCalendar.get(Calendar.DAY_OF_MONTH));
    outState.putInt(KEY_WEEK_START, mWeekStart);
    outState.putInt(KEY_YEAR_START, mMinYear);
    outState.putInt(KEY_YEAR_END, mMaxYear);
    int listPosition = mDayPickerView.getMostVisiblePosition();

    outState.putInt(KEY_LIST_POSITION, listPosition);
  }
  private void setCurrentView() {
    long millis = mCalendar.getTimeInMillis();

    ObjectAnimator pulseAnimator = Utils.getPulseAnimator(mMonthAndDayView, 0.9f, 1.05f);
    if (mDelayAnimation) {
      pulseAnimator.setStartDelay(ANIMATION_DELAY);
      mDelayAnimation = false;
    }
    mDayPickerView.onDateChanged();
    mMonthAndDayView.setSelected(true);

    pulseAnimator.start();

    int flags = DateUtils.FORMAT_SHOW_DATE;
    String dayString = DateUtils.formatDateTime(getActivity(), millis, flags);
    mAnimator.setContentDescription(mDayPickerDescription + ": " + dayString);
    Utils.tryAccessibilityAnnounce(mAnimator, mSelectDay);
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);

    View view = inflater.inflate(R.layout.calendar_date_picker_dialog, null);

    mDayOfWeekView = (TextView) view.findViewById(R.id.date_picker_header);
    mMonthAndDayView = (LinearLayout) view.findViewById(R.id.date_picker_month_and_day);
    mMonthAndDayView.setOnClickListener(this);
    mSelectedMonthTextView = (TextView) view.findViewById(R.id.date_picker_month);
    mSelectedDayTextView = (TextView) view.findViewById(R.id.date_picker_day);

    int listPosition = -1;

    if (savedInstanceState != null) {
      mWeekStart = savedInstanceState.getInt(KEY_WEEK_START);
      mMinYear = savedInstanceState.getInt(KEY_YEAR_START);
      mMaxYear = savedInstanceState.getInt(KEY_YEAR_END);
      listPosition = savedInstanceState.getInt(KEY_LIST_POSITION);
    }

    final Activity activity = getActivity();
    mDayPickerView = new SimpleDayPickerView(activity, this);

    Resources res = getResources();
    mDayPickerDescription = res.getString(R.string.day_picker_description);
    mSelectDay = res.getString(R.string.select_day);

    mAnimator = (AccessibleDateAnimator) view.findViewById(R.id.animator);
    mAnimator.addView(mDayPickerView);
    mAnimator.setDateMillis(mCalendar.getTimeInMillis());

    Animation animation = new AlphaAnimation(0.0f, 1.0f);
    animation.setDuration(ANIMATION_DURATION);
    mAnimator.setInAnimation(animation);

    Animation animation2 = new AlphaAnimation(1.0f, 0.0f);
    animation2.setDuration(ANIMATION_DURATION);
    mAnimator.setOutAnimation(animation2);

    Button mDoneButton = (Button) view.findViewById(R.id.done);
    mDoneButton.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            if (mCallBack != null) {
              mCallBack.onDateSet(
                  CalendarDatePickerDialog.this,
                  mCalendar.get(Calendar.YEAR),
                  mCalendar.get(Calendar.MONTH),
                  mCalendar.get(Calendar.DAY_OF_MONTH));
            }
            dismiss();
          }
        });

    updateDisplay(false);
    setCurrentView();

    if (listPosition != -1) {
      mDayPickerView.postSetSelection(listPosition);
    }

    return view;
  }