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

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 setFirstDayOfWeek(int firstDayOfWeek)

Sets what the first day of the week is; e.g., Calendar.SUNDAY in the U.S., Calendar.MONDAY in France.

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 CalendarConstraints.DateValidator.isValid(long) is true.

Inherited methods

Public constructors

Builder

public Builder ()

Public methods

build

public CalendarConstraints build ()

Builds the CalendarConstraints object using the set parameters or defaults.

Returns
CalendarConstraints

setEnd

public 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

setFirstDayOfWeek

public CalendarConstraints.Builder setFirstDayOfWeek (int firstDayOfWeek)

Sets what the first day of the week is; e.g., Calendar.SUNDAY in the U.S., Calendar.MONDAY in France.

Parameters
firstDayOfWeek int

Returns
CalendarConstraints.Builder

setOpenAt

public 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

public 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

public CalendarConstraints.Builder setValidator (CalendarConstraints.DateValidator validator)

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

Parameters
validator CalendarConstraints.DateValidator

Returns
CalendarConstraints.Builder