CalendarConstraints.Builder

public static final class CalendarConstraints.Builder
extends Object

java.lang.Object
   ↳ com.google.android.material.datepicker.CalendarConstraints.Builder


Builder for CalendarConstraints.

Summary

Public constructors

CalendarConstraints.Builder()

Public methods

CalendarConstraints build()

Builds the CalendarConstraints object using the set parameters or defaults.

CalendarConstraints.Builder setEnd(long month)

A UTC timeInMilliseconds contained within the latest month the calendar will page to.

CalendarConstraints.Builder setOpenAt(long month)

A UTC timeInMilliseconds contained within the month the calendar should openAt.

CalendarConstraints.Builder setStart(long month)

A UTC timeInMilliseconds contained within the earliest month the calendar will page to.

CalendarConstraints.Builder setValidator(CalendarConstraints.DateValidator validator)

Limits valid dates to those for which isValid(long) is true.

Inherited methods

From class java.lang.Object

Public constructors

CalendarConstraints.Builder

CalendarConstraints.Builder ()

Public methods

build

CalendarConstraints build ()

Builds the CalendarConstraints object using the set parameters or defaults.

Returns
CalendarConstraints

setEnd

CalendarConstraints.Builder setEnd (long month)

A UTC timeInMilliseconds contained within the latest month the calendar will page to. Defaults December, 2100.

If you have access to java.time in Java 8, you can obtain a long using java.time.ZonedDateTime.

LocalDateTime local = LocalDateTime.of(year, month, 1, 0, 0);
 local.atZone(ZoneId.ofOffset("UTC", ZoneOffset.UTC)).toInstant().toEpochMilli();
 

If you don't have access to java.time in Java 8, you can obtain this value using a java.util.Calendar instance from the UTC timezone.

Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
 c.set(year, month, 1);
 c.getTimeInMillis();
 

Parameters
month long

Returns
CalendarConstraints.Builder

setOpenAt

CalendarConstraints.Builder setOpenAt (long month)

A UTC timeInMilliseconds contained within the month the calendar should openAt. Defaults to the month containing today if within bounds; otherwise, defaults to the starting month.

If you have access to java.time in Java 8, you can obtain a long using java.time.ZonedDateTime.

LocalDateTime local = LocalDateTime.of(year, month, 1, 0, 0);
 local.atZone(ZoneId.ofOffset("UTC", ZoneOffset.UTC)).toInstant().toEpochMilli();
 

If you don't have access to java.time in Java 8, you can obtain this value using a java.util.Calendar instance from the UTC timezone.

Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
 c.set(year, month, 1);
 c.getTimeInMillis();
 

Parameters
month long

Returns
CalendarConstraints.Builder

setStart

CalendarConstraints.Builder setStart (long month)

A UTC timeInMilliseconds contained within the earliest month the calendar will page to. Defaults January, 1900.

If you have access to java.time in Java 8, you can obtain a long using java.time.ZonedDateTime.

LocalDateTime local = LocalDateTime.of(year, month, 1, 0, 0);
 local.atZone(ZoneId.ofOffset("UTC", ZoneOffset.UTC)).toInstant().toEpochMilli();
 

If you don't have access to java.time in Java 8, you can obtain this value using a java.util.Calendar instance from the UTC timezone.

Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
 c.set(year, month, 1);
 c.getTimeInMillis();
 

Parameters
month long

Returns
CalendarConstraints.Builder

setValidator

CalendarConstraints.Builder setValidator (CalendarConstraints.DateValidator validator)

Limits valid dates to those for which isValid(long) is true. Defaults to all dates as valid.

Parameters
validator CalendarConstraints.DateValidator

Returns
CalendarConstraints.Builder