CalendarConstraints.Builder

public final class CalendarConstraints.Builder


Builder for com.google.android.material.datepicker.CalendarConstraints.

Summary

Public constructors

Public methods

CalendarConstraints

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

Limits valid dates to those for which isValid is true.

Public constructors

Builder

public Builder()

Public methods

build

public CalendarConstraints build()

Builds the CalendarConstraints object using the set parameters or defaults.

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();

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.

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();

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();

setValidator

public CalendarConstraints.Builder setValidator(CalendarConstraints.DateValidator validator)

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