Code example for Calendar

Methods: after, before, equals, get, getActualMaximum, getActualMinimum, set, setTimeInMillis

0
        updateSpinners(); 
        mMonthChangedListener = onMonthChangedListener;
    } 
 
    private boolean isNewDate(int year, int month) {
        return (mCurrentDate.get(Calendar.YEAR) != year
                || mCurrentDate.get(Calendar.MONTH) != month);
    } 
 
    private void setDate(int year, int month) {
        mCurrentDate.set(year, month, 1);
        if (mCurrentDate.before(mMinDate)) {
            mCurrentDate.setTimeInMillis(mMinDate.getTimeInMillis());
        } else if (mCurrentDate.after(mMaxDate)) {
            mCurrentDate.setTimeInMillis(mMaxDate.getTimeInMillis());
        } 
    } 
 
    private void updateSpinners() { 
        // set the spinner ranges respecting the min and max dates 
        if (mCurrentDate.equals(mMinDate)) {
            mMonthSpinner.setDisplayedValues(null);
            mMonthSpinner.setMinValue(mCurrentDate.get(Calendar.MONTH));
            mMonthSpinner.setMaxValue(mCurrentDate.getActualMaximum(Calendar.MONTH));
            mMonthSpinner.setWrapSelectorWheel(false);
        } else if (mCurrentDate.equals(mMaxDate)) {
            mMonthSpinner.setDisplayedValues(null);
            mMonthSpinner.setMinValue(mCurrentDate.getActualMinimum(Calendar.MONTH));
            mMonthSpinner.setMaxValue(mCurrentDate.get(Calendar.MONTH));
            mMonthSpinner.setWrapSelectorWheel(false);
        } else { 
            mMonthSpinner.setDisplayedValues(null);
            mMonthSpinner.setMinValue(0);
            mMonthSpinner.setMaxValue(11);
            mMonthSpinner.setWrapSelectorWheel(true);
        } 
 
        // make sure the month names are a zero based array 
        // with the months in the month spinner 
        String[] displayedValues = Arrays.copyOfRange(mShortMonths,
                mMonthSpinner.getMinValue(), mMonthSpinner.getMaxValue() + 1);
        mMonthSpinner.setDisplayedValues(displayedValues);
 
        // year spinner range does not change based on the current date 
        mYearSpinner.setMinValue(mMinDate.get(Calendar.YEAR));
        mYearSpinner.setMaxValue(mMaxDate.get(Calendar.YEAR));
        mYearSpinner.setWrapSelectorWheel(false);
 
        // set the spinner values 
        mYearSpinner.setValue(mCurrentDate.get(Calendar.YEAR));
        mMonthSpinner.setValue(mCurrentDate.get(Calendar.MONTH));
    } 
 
    /** 
     * @return The selected year. 
     */ 
    public int getYear() { 
        return mCurrentDate.get(Calendar.YEAR);
    } 
 
    /** 
     * @return The selected month. 
     */ 
    public int getMonth() { 
        return mCurrentDate.get(Calendar.MONTH);
    } 
 
    /** 
     * @return The selected day of month. 
     */