Example usage for java.util Calendar DECEMBER

List of usage examples for java.util Calendar DECEMBER

Introduction

In this page you can find the example usage for java.util Calendar DECEMBER.

Prototype

int DECEMBER

To view the source code for java.util Calendar DECEMBER.

Click Source Link

Document

Value of the #MONTH field indicating the twelfth month of the year in the Gregorian and Julian calendars.

Usage

From source file:net.sourceforge.openutils.mgnlcriteria.jcr.query.lucene.AclSearchIndexTest.java

/**
 * Tests that the execution of a query on all pets returns dogs only, because of an ACL rule.
 * @throws Exception//  www.j av a  2  s.  c  om
 */
@Test
public void testDogsOnly() throws Exception {
    Context ctx = MgnlContext.getInstance();
    final AccessManager wrappedAM = ctx.getAccessManager(RepositoryConstants.WEBSITE);

    Assert.assertNotNull(wrappedAM, "AccessManager is null");

    final AccessManager wrapperAM = new AccessManager() {

        public boolean isGranted(String path, long permissions) {
            // ACL rule: deny permission on pets subtree
            if (StringUtils.startsWith(path, "/pets/")) {
                // ACL rule: read permission on dogs subtree
                return StringUtils.startsWith(path, "/pets/dogs/");
            }
            return wrappedAM.isGranted(path, permissions);
        }

        public void setPermissionList(List<Permission> permissions) {
            wrappedAM.setPermissionList(permissions);
        }

        public List<Permission> getPermissionList() {
            return wrappedAM.getPermissionList();
        }

        public long getPermissions(String path) {
            return wrappedAM.getPermissions(path);
        }
    };
    MgnlContext.setInstance(new ContextDecorator(MgnlContext.getInstance()) {

        /**
         * {@inheritDoc}
         */
        @Override
        public AccessManager getAccessManager(String name) {
            if (RepositoryConstants.WEBSITE.equals(name)) {
                return wrapperAM;
            }
            return super.getAccessManager(name);
        }
    });
    try {
        Calendar begin = Calendar.getInstance();
        begin.set(1999, Calendar.JANUARY, 1);
        Calendar end = Calendar.getInstance();
        end.set(2001, Calendar.DECEMBER, 31);

        Criteria criteria = JCRCriteriaFactory.createCriteria().setWorkspace(RepositoryConstants.WEBSITE)
                .setBasePath("/pets").add(Restrictions.between("@birthDate", begin, end))
                .addOrder(Order.asc("@birthDate"));

        // Query results:
        // --- 9 (title=Lucky, petType=bird, birthDate=1999-08-06)
        // --- 6 (title=George, petType=snake, birthDate=2000-01-20)
        // --- 4 (title=Jewel, petType=dog, birthDate=2000-03-07)
        // --- 11 (title=Freddy, petType=bird, birthDate=2000-03-09)
        // --- 12 (title=Lucky, petType=dog, birthDate=2000-06-24)
        // --- 1 (title=Leo, petType=cat, birthDate=2000-09-07)
        // --- 5 (title=Iggy, petType=lizard, birthDate=2000-11-30)
        // --- 3 (title=Rosy, petType=dog, birthDate=2001-04-17)
        AdvancedResult result = criteria.execute();

        // Accessible results (dogs only):
        // --- 4 (title=Jewel, petType=dog, birthDate=2000-03-07)
        // --- 12 (title=Lucky, petType=dog, birthDate=2000-06-24)
        // --- 3 (title=Rosy, petType=dog, birthDate=2001-04-17)
        ResultIterator<? extends Node> iterator = result.getItems();

        Assert.assertTrue(iterator.hasNext());
        Assert.assertEquals(CriteriaTestUtils.name(iterator.next()), "4");
        Assert.assertTrue(iterator.hasNext());
        Assert.assertEquals(CriteriaTestUtils.name(iterator.next()), "12");
        Assert.assertTrue(iterator.hasNext());
        Assert.assertEquals(CriteriaTestUtils.name(iterator.next()), "3");
        Assert.assertFalse(iterator.hasNext());
    } finally {
        MgnlContext.setInstance(((ContextDecorator) MgnlContext.getInstance()).getWrappedContext());
    }
}

From source file:br.msf.commons.util.AbstractDateUtils.java

/**
 * Returns the month name for the given month index.
 * <p/>//from  w  w w .  j  a v  a 2  s .co m
 * Beware! its zero indexed, so JANUARY = 0, FEBRUARY = 1 and so on...
 *
 * @param month  The month index.
 * @param locale The desired locale.
 * @return The month name for the given index.
 */
public static String monthName(final int month, final Locale locale) {
    if (month < Calendar.JANUARY || month > Calendar.DECEMBER) {
        throw new IllegalArgumentException("Month must be between [Calendar.JANUARY, Calendar.DECEMBER].");
    }
    return (new GregorianCalendar(year(), month, 1)).getDisplayName(Calendar.MONTH, Calendar.LONG,
            LocaleUtils.getNullSafeLocale(locale));
}

From source file:edu.umm.radonc.ca_dash.model.TxInstanceFacade.java

public TreeMap<Date, SynchronizedDescriptiveStatistics> getWeeklySummaryStatsAbs(Date startDate, Date endDate,
        Long hospitalser, String filter, boolean includeWeekends, boolean ptflag, boolean scheduledFlag) {
    Calendar cal = new GregorianCalendar();
    TreeMap<Date, SynchronizedDescriptiveStatistics> retval = new TreeMap<>();

    //SET TO BEGINNING OF WK FOR ABSOLUTE CALC
    cal.setTime(startDate);/*from   w  ww  .  j a  va2s.  c  o m*/
    cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
    startDate = cal.getTime();

    List<Object[]> events = getDailyCounts(startDate, endDate, hospitalser, filter, false, ptflag,
            scheduledFlag);

    DateFormat df = new SimpleDateFormat("MM/dd/yy");
    cal.setTime(startDate);
    cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
    int wk = cal.get(Calendar.WEEK_OF_YEAR);
    int mo = cal.get(Calendar.MONTH);
    int yr = cal.get(Calendar.YEAR);
    if (mo == Calendar.DECEMBER && wk == 1) {
        yr = yr + 1;
    } else if (mo == Calendar.JANUARY && wk == 52) {
        yr = yr - 1;
    }
    String currYrWk = yr + "-" + String.format("%02d", wk);
    //String prevYrWk = "";
    String prevYrWk = currYrWk;
    SynchronizedDescriptiveStatistics currStats = new SynchronizedDescriptiveStatistics();
    int i = 0;
    while (cal.getTime().before(endDate) && i < events.size()) {

        Object[] event = events.get(i);
        Date d = (Date) event[0];
        Long count = (Long) event[1];

        cal.setTime(d);
        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        wk = cal.get(Calendar.WEEK_OF_YEAR);
        mo = cal.get(Calendar.MONTH);
        yr = cal.get(Calendar.YEAR);
        if (mo == Calendar.DECEMBER && wk == 1) {
            yr = yr + 1;
        } else if (mo == Calendar.JANUARY && wk == 52) {
            yr = yr - 1;
        }
        currYrWk = yr + "-" + String.format("%02d", wk);

        if (!(prevYrWk.equals(currYrWk))) {
            GregorianCalendar lastMon = new GregorianCalendar();
            lastMon.setTime(cal.getTime());
            lastMon.add(Calendar.DATE, -7);
            retval.put(lastMon.getTime(), currStats);
            currStats = new SynchronizedDescriptiveStatistics();
        }

        prevYrWk = currYrWk;

        currStats.addValue(count);
        i++;
    }
    retval.put(cal.getTime(), currStats);

    return retval;
}

From source file:Negocio.Produccion.Planificacion.GanttDemo.java

/**
 * Creates a sample dataset for a Gantt chart.
 *
 * @return The dataset.//from  w  w w .  ja  v  a  2 s  .co  m
 */
public static IntervalCategoryDataset createDataset() {

    final TaskSeries s1 = new TaskSeries("Scheduled");
    s1.add(new Task("Write Proposal",
            new SimpleTimePeriod(date(1, Calendar.APRIL, 2001), date(5, Calendar.APRIL, 2001))));
    s1.add(new Task("Obtain Approval",
            new SimpleTimePeriod(date(9, Calendar.APRIL, 2001), date(9, Calendar.APRIL, 2001))));
    s1.add(new Task("Requirements Analysis",
            new SimpleTimePeriod(date(10, Calendar.APRIL, 2001), date(5, Calendar.MAY, 2001))));
    s1.add(new Task("Design Phase",
            new SimpleTimePeriod(date(6, Calendar.MAY, 2001), date(30, Calendar.MAY, 2001))));
    s1.add(new Task("Design Signoff",
            new SimpleTimePeriod(date(2, Calendar.JUNE, 2001), date(2, Calendar.JUNE, 2001))));
    s1.add(new Task("Alpha Implementation",
            new SimpleTimePeriod(date(3, Calendar.JUNE, 2001), date(31, Calendar.JULY, 2001))));
    s1.add(new Task("Design Review",
            new SimpleTimePeriod(date(1, Calendar.AUGUST, 2001), date(8, Calendar.AUGUST, 2001))));
    s1.add(new Task("Revised Design Signoff",
            new SimpleTimePeriod(date(10, Calendar.AUGUST, 2001), date(10, Calendar.AUGUST, 2001))));
    s1.add(new Task("Beta Implementation",
            new SimpleTimePeriod(date(12, Calendar.AUGUST, 2001), date(12, Calendar.SEPTEMBER, 2001))));
    s1.add(new Task("Testing",
            new SimpleTimePeriod(date(13, Calendar.SEPTEMBER, 2001), date(31, Calendar.OCTOBER, 2001))));
    s1.add(new Task("Final Implementation",
            new SimpleTimePeriod(date(1, Calendar.NOVEMBER, 2001), date(15, Calendar.NOVEMBER, 2001))));
    s1.add(new Task("Signoff",
            new SimpleTimePeriod(date(28, Calendar.NOVEMBER, 2001), date(30, Calendar.NOVEMBER, 2001))));

    final TaskSeries s2 = new TaskSeries("Actual");
    s2.add(new Task("Write Proposal",
            new SimpleTimePeriod(date(1, Calendar.APRIL, 2001), date(5, Calendar.APRIL, 2001))));
    s2.add(new Task("Obtain Approval",
            new SimpleTimePeriod(date(9, Calendar.APRIL, 2001), date(9, Calendar.APRIL, 2001))));
    s2.add(new Task("Requirements Analysis",
            new SimpleTimePeriod(date(10, Calendar.APRIL, 2001), date(15, Calendar.MAY, 2001))));
    s2.add(new Task("Design Phase",
            new SimpleTimePeriod(date(15, Calendar.MAY, 2001), date(17, Calendar.JUNE, 2001))));
    s2.add(new Task("Design Signoff",
            new SimpleTimePeriod(date(30, Calendar.JUNE, 2001), date(30, Calendar.JUNE, 2001))));
    s2.add(new Task("Alpha Implementation",
            new SimpleTimePeriod(date(1, Calendar.JULY, 2001), date(12, Calendar.SEPTEMBER, 2001))));
    s2.add(new Task("Design Review",
            new SimpleTimePeriod(date(12, Calendar.SEPTEMBER, 2001), date(22, Calendar.SEPTEMBER, 2001))));
    s2.add(new Task("Revised Design Signoff",
            new SimpleTimePeriod(date(25, Calendar.SEPTEMBER, 2001), date(27, Calendar.SEPTEMBER, 2001))));
    s2.add(new Task("Beta Implementation",
            new SimpleTimePeriod(date(27, Calendar.SEPTEMBER, 2001), date(30, Calendar.OCTOBER, 2001))));
    s2.add(new Task("Testing",
            new SimpleTimePeriod(date(31, Calendar.OCTOBER, 2001), date(17, Calendar.NOVEMBER, 2001))));
    s2.add(new Task("Final Implementation",
            new SimpleTimePeriod(date(18, Calendar.NOVEMBER, 2001), date(5, Calendar.DECEMBER, 2001))));
    s2.add(new Task("Signoff",
            new SimpleTimePeriod(date(10, Calendar.DECEMBER, 2001), date(11, Calendar.DECEMBER, 2001))));

    final TaskSeriesCollection collection = new TaskSeriesCollection();
    collection.add(s1);
    collection.add(s2);

    return collection;
}

From source file:com.gemstone.gemfire.rest.internal.web.controllers.RestAPIsWithSSLDUnitTest.java

public void doPutsInClientCache() {
    ClientCache cache = GemFireCacheImpl.getInstance();
    assertNotNull(cache);//from www.  j  a v  a 2s  . co m
    Region<String, Object> region = cache.getRegion(PEOPLE_REGION_NAME);

    // put person object
    final Person person1 = new Person(101L, "Mithali", "Dorai", "Raj",
            DateTimeUtils.createDate(1982, Calendar.DECEMBER, 4), Gender.FEMALE);
    final Person person2 = new Person(102L, "Sachin", "Ramesh", "Tendulkar",
            DateTimeUtils.createDate(1975, Calendar.DECEMBER, 14), Gender.MALE);
    final Person person3 = new Person(103L, "Saurabh", "Baburav", "Ganguly",
            DateTimeUtils.createDate(1972, Calendar.AUGUST, 29), Gender.MALE);
    final Person person4 = new Person(104L, "Rahul", "subrymanyam", "Dravid",
            DateTimeUtils.createDate(1979, Calendar.MARCH, 17), Gender.MALE);
    final Person person5 = new Person(105L, "Jhulan", "Chidambaram", "Goswami",
            DateTimeUtils.createDate(1983, Calendar.NOVEMBER, 25), Gender.FEMALE);

    region.put("1", person1);
    region.put("2", person2);
    region.put("3", person3);
    region.put("4", person4);
    region.put("5", person5);

    final Person person6 = new Person(101L, "Rahul", "Rajiv", "Gndhi",
            DateTimeUtils.createDate(1970, Calendar.MAY, 14), Gender.MALE);
    final Person person7 = new Person(102L, "Narendra", "Damodar", "Modi",
            DateTimeUtils.createDate(1945, Calendar.DECEMBER, 24), Gender.MALE);
    final Person person8 = new Person(103L, "Atal", "Bihari", "Vajpayee",
            DateTimeUtils.createDate(1920, Calendar.AUGUST, 9), Gender.MALE);
    final Person person9 = new Person(104L, "Soniya", "Rajiv", "Gandhi",
            DateTimeUtils.createDate(1929, Calendar.MARCH, 27), Gender.FEMALE);
    final Person person10 = new Person(104L, "Priyanka", "Robert", "Gandhi",
            DateTimeUtils.createDate(1973, Calendar.APRIL, 15), Gender.FEMALE);

    final Person person11 = new Person(104L, "Murali", "Manohar", "Joshi",
            DateTimeUtils.createDate(1923, Calendar.APRIL, 25), Gender.MALE);
    final Person person12 = new Person(104L, "Lalkrishna", "Parmhansh", "Advani",
            DateTimeUtils.createDate(1910, Calendar.JANUARY, 01), Gender.MALE);
    final Person person13 = new Person(104L, "Shushma", "kumari", "Swaraj",
            DateTimeUtils.createDate(1943, Calendar.AUGUST, 10), Gender.FEMALE);
    final Person person14 = new Person(104L, "Arun", "raman", "jetly",
            DateTimeUtils.createDate(1942, Calendar.OCTOBER, 27), Gender.MALE);
    final Person person15 = new Person(104L, "Amit", "kumar", "shah",
            DateTimeUtils.createDate(1958, Calendar.DECEMBER, 21), Gender.MALE);
    final Person person16 = new Person(104L, "Shila", "kumari", "Dixit",
            DateTimeUtils.createDate(1927, Calendar.FEBRUARY, 15), Gender.FEMALE);

    Map<String, Object> userMap = new HashMap<String, Object>();
    userMap.put("6", person6);
    userMap.put("7", person7);
    userMap.put("8", person8);
    userMap.put("9", person9);
    userMap.put("10", person10);
    userMap.put("11", person11);
    userMap.put("12", person12);
    userMap.put("13", person13);
    userMap.put("14", person14);
    userMap.put("15", person15);
    userMap.put("16", person16);

    region.putAll(userMap);

    if (cache != null)
        cache.getLogger().info("Gemfire Cache Client: Puts successfully done");

}

From source file:org.apache.solr.handler.component.RuleManagerComponent.java

/**
 * Initialize the season mappings configuration used during replacements of the
 * $SEASON token in rule base categories & ranking rule boost expressions.
 *
 * The season mapping string should have this format:
 *
 * expressionA:1,2,3,4,5,6;expressionB:7,8,9,10,11,12
 *
 * where 1,2,3,4 are the months of the year (starting at 1=january)
 *
 * If there are missing months in the mapping, then they will be default to the following expression: *
 *
 * @param seasonMapping The season mapping parameter specified by the user in this component definition in solrconfig
 */// w w w  .  j  av a  2s.  c  o  m
protected void initSeasonMappings(String seasonMapping) {
    for (int i = Calendar.JANUARY; i <= Calendar.DECEMBER; i++) {
        seasonMapper[i] = DEFAULT_SEASON_MAPPER;
    }

    if (seasonMapping != null) {
        logger.info("Initializing season mapping: [" + seasonMapping + "]");
        String[] expressions = seasonMapping.split(";");
        if (expressions != null) {
            for (String expression : expressions) {
                String[] entry = expression.split(":");
                if (entry.length != 2) {
                    logger.error("Invalid season mapping expression: [" + expression
                            + "]. Correct format: [expression:1,2,3,4;] where 1,2,3,4 are the months of the year");
                } else {
                    String value = entry[0];
                    String[] months = entry[1].split(",");
                    for (int i = 0; i < months.length; i++) {
                        seasonMapper[Integer.parseInt(months[i]) - 1] = value;
                    }
                }
            }
        } else {
            logger.error(
                    "Please provide a valid season mapping configuration parameter. Valid format: [expressionA:1,2,3,4,5,6;expressionB:7,8,9,10,11,12]");
        }
    }
}

From source file:org.openmrs.module.reporting.common.DateUtilTest.java

@Test
@Verifies(value = "should correctly handle daylight savings time", method = "getTimespan(Date,Date,null)")
public void getTimespan_shouldCorrectlyHandleDaylightSavingsTime() throws Exception {
    // USA has daylight saving time.
    // in 2009 DST started March 8 and ended November 1

    Calendar cal = new GregorianCalendar(Locale.US);
    cal.set(Calendar.YEAR, 2009);
    cal.set(Calendar.DAY_OF_MONTH, 25);

    cal.set(Calendar.MONTH, Calendar.FEBRUARY);
    Date feb25 = cal.getTime();//from  w ww .ja  va 2s.c om

    cal.set(Calendar.MONTH, Calendar.MARCH);
    Date mar25 = cal.getTime();

    cal.set(Calendar.MONTH, Calendar.APRIL);
    Date apr25 = cal.getTime();

    cal.set(Calendar.MONTH, Calendar.OCTOBER);
    Date oct25 = cal.getTime();

    cal.set(Calendar.MONTH, Calendar.NOVEMBER);
    Date nov25 = cal.getTime();

    cal.set(Calendar.MONTH, Calendar.DECEMBER);
    Date dec25 = cal.getTime();

    testMessage("reporting.dateUtil.oneMonth reporting.dateUtil.ago", DateUtil.getTimespan(mar25, feb25));
    testMessage("reporting.dateUtil.oneMonth reporting.dateUtil.ago", DateUtil.getTimespan(apr25, mar25));
    testMessage("reporting.dateUtil.oneMonth reporting.dateUtil.ago", DateUtil.getTimespan(nov25, oct25));
    testMessage("reporting.dateUtil.oneMonth reporting.dateUtil.ago", DateUtil.getTimespan(dec25, nov25));
}

From source file:edu.northwestern.bioinformatics.studycalendar.dao.reporting.ScheduledActivitiesReportRowDaoTest.java

public void testSearchWithStartIdealDateFilter_Neg() {
    MutableRange<Date> range = new MutableRange<Date>();
    range.setStart(DateUtils.createDate(2007, Calendar.DECEMBER, 5));
    filters.setIdealDate(range);/* www.j a  v  a  2s .  co  m*/
    assertSearchWithResults();
}

From source file:connect.app.com.connect.calendar.DayPickerView.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public DayPickerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    mAccessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);

    //        final TypedArray a = context.obtainStyledAttributes(attrs,
    //                R.styleable.CalendarView, defStyleAttr, defStyleRes);
    ///*  ww w . ja  va  2 s.  c om*/
    //        final int firstDayOfWeek = a.getInt(R.styleable.CalendarView_firstDayOfWeek,
    //                LocaleData.get(Locale.getDefault()).firstDayOfWeek);
    final int firstDayOfWeek = 1;
    //
    //        final String minDate = a.getString(R.styleable.CalendarView_minDate);
    final String minDate = null;
    //        final String maxDate = a.getString(R.styleable.CalendarView_maxDate);
    final String maxDate = null;
    //
    //        final int monthTextAppearanceResId = a.getResourceId(
    //                R.styleable.CalendarView_monthTextAppearance,
    //                R.style.TextAppearance_Material_Widget_Calendar_Month);
    //        final int dayOfWeekTextAppearanceResId = a.getResourceId(
    //                R.styleable.CalendarView_weekDayTextAppearance,
    //                R.style.TextAppearance_Material_Widget_Calendar_DayOfWeek);
    //        final int dayTextAppearanceResId = a.getResourceId(
    //                R.styleable.CalendarView_dateTextAppearance,
    //                R.style.TextAppearance_Material_Widget_Calendar_Day);
    //
    //        final ColorStateList daySelectorColor = a.getColorStateList(
    //                R.styleable.CalendarView_daySelectorColor);
    //
    //        a.recycle();

    // Set up adapter.
    mAdapter = new DayPickerPagerAdapter(context, R.layout.layout_test, com.retrofit.R.id.scrollView);
    //        mAdapter.setMonthTextAppearance(monthTextAppearanceResId);
    //        mAdapter.setDayOfWeekTextAppearance(dayOfWeekTextAppearanceResId);
    //        mAdapter.setDayTextAppearance(dayTextAppearanceResId);
    //        mAdapter.setDaySelectorColor(daySelectorColor);

    final LayoutInflater inflater = LayoutInflater.from(context);
    final ViewGroup content = (ViewGroup) inflater.inflate(DEFAULT_LAYOUT, this, false);

    // Transfer all children from content to here.
    while (content.getChildCount() > 0) {
        final View child = content.getChildAt(0);
        content.removeViewAt(0);
        addView(child);
    }

    mPrevButton = (ImageButton) findViewById(R.id.prev);
    mPrevButton.setOnClickListener(mOnClickListener);

    mNextButton = (ImageButton) findViewById(R.id.next);
    mNextButton.setOnClickListener(mOnClickListener);

    mViewPager = (ViewPager) findViewById(R.id.day_picker_view_pager);
    mViewPager.setAdapter(mAdapter);
    mViewPager.setOnPageChangeListener(mOnPageChangedListener);

    // Proxy the month text color into the previous and next buttons.
    //        if (monthTextAppearanceResId != 0) {
    //            final TypedArray ta = mContext.obtainStyledAttributes(null,
    //                    ATTRS_TEXT_COLOR, 0, monthTextAppearanceResId);
    //            final ColorStateList monthColor = ta.getColorStateList(0);
    //            if (monthColor != null) {
    //                mPrevButton.setImageTintList(monthColor);
    //                mNextButton.setImageTintList(monthColor);
    //            }
    //            ta.recycle();
    //        }

    // Set up min and max dates.
    final Calendar tempDate = Calendar.getInstance();
    if (!CalendarView.parseDate(minDate, tempDate)) {
        tempDate.set(DEFAULT_START_YEAR, Calendar.JANUARY, 1);
    }
    final long minDateMillis = tempDate.getTimeInMillis();

    if (!CalendarView.parseDate(maxDate, tempDate)) {
        tempDate.set(DEFAULT_END_YEAR, Calendar.DECEMBER, 31);
    }
    final long maxDateMillis = tempDate.getTimeInMillis();

    if (maxDateMillis < minDateMillis) {
        throw new IllegalArgumentException("maxDate must be >= minDate");
    }

    final long setDateMillis = MathUtils.constrain(System.currentTimeMillis(), minDateMillis, maxDateMillis);

    setFirstDayOfWeek(firstDayOfWeek);
    setMinDate(minDateMillis);
    setMaxDate(maxDateMillis);
    setDate(setDateMillis, false);

    // Proxy selection callbacks to our own listener.
    mAdapter.setOnDaySelectedListener(new DayPickerPagerAdapter.OnDaySelectedListener() {
        @Override
        public void onDaySelected(DayPickerPagerAdapter adapter, Calendar day) {
            if (mOnDaySelectedListener != null) {
                mOnDaySelectedListener.onDaySelected(DayPickerView.this, day);
            }
        }
    });
}

From source file:com.tr4android.support.extension.picker.date.DayPickerView.java

public DayPickerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    mAccessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DatePickerDialog, defStyleAttr, 0); //TODO: add default style res

    final int firstDayOfWeek = a.getInt(R.styleable.DatePickerDialog_firstDayOfWeek,
            Calendar.getInstance(Locale.getDefault()).getFirstDayOfWeek());

    final String minDate = a.getString(R.styleable.DatePickerDialog_minDate);
    final String maxDate = a.getString(R.styleable.DatePickerDialog_maxDate);

    final int monthTextAppearanceResId = a.getResourceId(R.styleable.DatePickerDialog_monthTextAppearance,
            R.style.TextAppearance_Material_Widget_Calendar_Month);
    final int dayOfWeekTextAppearanceResId = a.getResourceId(R.styleable.DatePickerDialog_weekDayTextAppearance,
            R.style.TextAppearance_Material_Widget_Calendar_DayOfWeek);
    final int dayTextAppearanceResId = a.getResourceId(R.styleable.DatePickerDialog_dateTextAppearance,
            R.style.TextAppearance_Material_Widget_Calendar_Day);

    // Set up day selected color, if available.
    final ColorStateList daySelectorColor;
    if (a.hasValue(R.styleable.DatePickerDialog_daySelectorColor)) {
        daySelectorColor = a.getColorStateList(R.styleable.DatePickerDialog_daySelectorColor);
    } else {//from  www  . j  a va 2s.  c om
        final TypedArray ta = context.obtainStyledAttributes(new int[] { R.attr.colorControlActivated });
        daySelectorColor = ta.getColorStateList(0);
        ta.recycle();
    }

    // Set up day highlight color, if available.
    final ColorStateList dayHighlightColor;
    if (a.hasValue(R.styleable.DatePickerDialog_dayHighlightColor)) {
        dayHighlightColor = a.getColorStateList(R.styleable.DatePickerDialog_dayHighlightColor);
    } else {
        final TypedArray ta = context.obtainStyledAttributes(new int[] { R.attr.colorControlHighlight });
        dayHighlightColor = ta.getColorStateList(0);
        ta.recycle();
    }

    a.recycle();

    // Set up adapter.
    mAdapter = new DayPickerPagerAdapter(context, R.layout.day_picker_month_item_material, R.id.month_view);
    mAdapter.setMonthTextAppearance(monthTextAppearanceResId);
    mAdapter.setDayOfWeekTextAppearance(dayOfWeekTextAppearanceResId);
    mAdapter.setDayTextAppearance(dayTextAppearanceResId);
    mAdapter.setDaySelectorColor(daySelectorColor);
    mAdapter.setDayHighlightColor(dayHighlightColor);

    final LayoutInflater inflater = LayoutInflater.from(context);
    final ViewGroup content = (ViewGroup) inflater.inflate(DEFAULT_LAYOUT, this, false);

    // Transfer all children from content to here.
    while (content.getChildCount() > 0) {
        final View child = content.getChildAt(0);
        content.removeViewAt(0);
        addView(child);
    }

    mPrevButton = (ImageButton) findViewById(R.id.prev);
    mPrevButton.setOnClickListener(mOnClickListener);

    mNextButton = (ImageButton) findViewById(R.id.next);
    mNextButton.setOnClickListener(mOnClickListener);

    mViewPager = (ViewPager) findViewById(R.id.day_picker_view_pager);
    mViewPager.setAdapter(mAdapter);
    mViewPager.addOnPageChangeListener(mOnPageChangedListener);

    // Set up background of the previous and next buttons.
    ViewCompatUtils.setBackground(mPrevButton, PickerThemeUtils.getNavButtonBackground(context));
    ViewCompatUtils.setBackground(mNextButton, PickerThemeUtils.getNavButtonBackground(context));

    // Set up min and max dates.
    final Calendar tempDate = Calendar.getInstance();
    if (!parseDate(minDate, tempDate)) {
        tempDate.set(DEFAULT_START_YEAR, Calendar.JANUARY, 1);
    }
    final long minDateMillis = tempDate.getTimeInMillis();

    if (!parseDate(maxDate, tempDate)) {
        tempDate.set(DEFAULT_END_YEAR, Calendar.DECEMBER, 31);
    }
    final long maxDateMillis = tempDate.getTimeInMillis();

    if (maxDateMillis < minDateMillis) {
        throw new IllegalArgumentException("maxDate must be >= minDate");
    }

    final long setDateMillis = MathUtils.constrain(System.currentTimeMillis(), minDateMillis, maxDateMillis);

    setFirstDayOfWeek(firstDayOfWeek);
    setMinDate(minDateMillis);
    setMaxDate(maxDateMillis);
    setDate(setDateMillis, false);

    // Proxy selection callbacks to our own listener.
    mAdapter.setOnDaySelectedListener(new DayPickerPagerAdapter.OnDaySelectedListener() {
        @Override
        public void onDaySelected(DayPickerPagerAdapter adapter, Calendar day) {
            if (mOnDaySelectedListener != null) {
                mOnDaySelectedListener.onDaySelected(DayPickerView.this, day);
            }
        }
    });
}