Esempio n. 1
0
 private void updateUi() {
   int ourMonth = month.getMonth();
   for (DayView dayView : monthDayViews) {
     CalendarDay day = dayView.getDate();
     dayView.setupSelection(
         showOtherDates, day.isInRange(minDate, maxDate), day.getMonth() == ourMonth);
   }
   postInvalidate();
 }
Esempio n. 2
0
  public MonthView(@NonNull MaterialCalendarView view, CalendarDay month, int firstDayOfWeek) {
    super(view.getContext());
    this.mcv = view;
    this.month = month;
    this.firstDayOfWeek = firstDayOfWeek;

    setClipChildren(false);
    setClipToPadding(false);

    Calendar calendar = resetAndGetWorkingCalendar();

    for (int i = 0; i < DEFAULT_DAYS_IN_WEEK; i++) {
      WeekDayView weekDayView = new WeekDayView(getContext(), CalendarUtils.getDayOfWeek(calendar));
      weekDayViews.add(weekDayView);
      addView(weekDayView);
      calendar.add(DATE, 1);
    }

    calendar = resetAndGetWorkingCalendar();

    for (int r = 0; r < DEFAULT_MAX_WEEKS; r++) {
      for (int i = 0; i < DEFAULT_DAYS_IN_WEEK; i++) {
        CalendarDay day = CalendarDay.from(calendar);
        DayView dayView = new DayView(getContext(), day);
        dayView.setOnClickListener(this);
        monthDayViews.add(dayView);
        addView(dayView, new LayoutParams());

        calendar.add(DATE, 1);
      }
    }
  }
Esempio n. 3
0
 private Calendar resetAndGetWorkingCalendar() {
   month.copyTo(tempWorkingCalendar);
   tempWorkingCalendar.setFirstDayOfWeek(firstDayOfWeek);
   int dow = CalendarUtils.getDayOfWeek(tempWorkingCalendar);
   int delta = firstDayOfWeek - dow;
   // If the delta is positive, we want to remove a week
   boolean removeRow = showOtherMonths(showOtherDates) ? delta >= 0 : delta > 0;
   if (removeRow) {
     delta -= DEFAULT_DAYS_IN_WEEK;
   }
   tempWorkingCalendar.add(DATE, delta);
   return tempWorkingCalendar;
 }
Esempio n. 4
0
  public void setFirstDayOfWeek(int dayOfWeek) {
    this.firstDayOfWeek = dayOfWeek;

    Calendar calendar = resetAndGetWorkingCalendar();
    calendar.set(DAY_OF_WEEK, dayOfWeek);
    for (WeekDayView dayView : weekDayViews) {
      dayView.setDayOfWeek(calendar);
      calendar.add(DATE, 1);
    }

    calendar = resetAndGetWorkingCalendar();
    for (DayView dayView : monthDayViews) {
      CalendarDay day = CalendarDay.from(calendar);
      dayView.setDay(day);
      calendar.add(DATE, 1);
    }

    updateUi();
  }
 /**
  * Determine if this day is within a specified range
  *
  * @param minDate the earliest day, may be null
  * @param maxDate the latest day, may be null
  * @return true if the between (inclusive) the min and max dates.
  */
 public boolean isInRange(@Nullable CalendarDay minDate, @Nullable CalendarDay maxDate) {
   return !(minDate != null && minDate.isAfter(this))
       && !(maxDate != null && maxDate.isBefore(this));
 }