Search in sources :

Example 11 with LocalDate

use of org.threeten.bp.LocalDate in project Douya by DreaminginCodeZH.

the class CalendarDay method getDateText.

public String getDateText(Context context) {
    LocalDate date = getDate();
    String datePattern = context.getString(R.string.calendar_date_pattern);
    return date.format(DateTimeFormatter.ofPattern(datePattern));
}
Also used : LocalDate(org.threeten.bp.LocalDate)

Example 12 with LocalDate

use of org.threeten.bp.LocalDate in project material-calendarview by prolificinteractive.

the class MaterialCalendarView method commit.

private void commit(State state) {
    // Use the calendarDayToShow to determine which date to focus on for the case of switching between month and week views
    CalendarDay calendarDayToShow = null;
    if (adapter != null && state.cacheCurrentPosition) {
        calendarDayToShow = adapter.getItem(pager.getCurrentItem());
        if (calendarMode != state.calendarMode) {
            CalendarDay currentlySelectedDate = getSelectedDate();
            if (calendarMode == CalendarMode.MONTHS && currentlySelectedDate != null) {
                // Going from months to weeks
                LocalDate lastVisibleCalendar = calendarDayToShow.getDate();
                CalendarDay lastVisibleCalendarDay = CalendarDay.from(lastVisibleCalendar.plusDays(1));
                if (currentlySelectedDate.equals(calendarDayToShow) || (currentlySelectedDate.isAfter(calendarDayToShow) && currentlySelectedDate.isBefore(lastVisibleCalendarDay))) {
                    // Currently selected date is within view, so center on that
                    calendarDayToShow = currentlySelectedDate;
                }
            } else if (calendarMode == CalendarMode.WEEKS) {
                // Going from weeks to months
                LocalDate lastVisibleCalendar = calendarDayToShow.getDate();
                CalendarDay lastVisibleCalendarDay = CalendarDay.from(lastVisibleCalendar.plusDays(6));
                if (currentlySelectedDate != null && (currentlySelectedDate.equals(calendarDayToShow) || currentlySelectedDate.equals(lastVisibleCalendarDay) || (currentlySelectedDate.isAfter(calendarDayToShow) && currentlySelectedDate.isBefore(lastVisibleCalendarDay)))) {
                    // Currently selected date is within view, so center on that
                    calendarDayToShow = currentlySelectedDate;
                } else {
                    calendarDayToShow = lastVisibleCalendarDay;
                }
            }
        }
    }
    this.state = state;
    // Save states parameters
    calendarMode = state.calendarMode;
    firstDayOfWeek = state.firstDayOfWeek;
    minDate = state.minDate;
    maxDate = state.maxDate;
    showWeekDays = state.showWeekDays;
    // Recreate adapter
    final CalendarPagerAdapter<?> newAdapter;
    switch(calendarMode) {
        case MONTHS:
            newAdapter = new MonthPagerAdapter(this);
            break;
        case WEEKS:
            newAdapter = new WeekPagerAdapter(this);
            break;
        default:
            throw new IllegalArgumentException("Provided display mode which is not yet implemented");
    }
    if (adapter == null) {
        adapter = newAdapter;
    } else {
        adapter = adapter.migrateStateAndReturn(newAdapter);
    }
    adapter.setShowWeekDays(showWeekDays);
    pager.setAdapter(adapter);
    setRangeDates(minDate, maxDate);
    // Reset height params after mode change
    int tileHeight = showWeekDays ? calendarMode.visibleWeeksCount + DAY_NAMES_ROW : calendarMode.visibleWeeksCount;
    pager.setLayoutParams(new LayoutParams(tileHeight));
    setCurrentDate(selectionMode == SELECTION_MODE_SINGLE && !adapter.getSelectedDates().isEmpty() ? adapter.getSelectedDates().get(0) : CalendarDay.today());
    if (calendarDayToShow != null) {
        pager.setCurrentItem(adapter.getIndexForDay(calendarDayToShow));
    }
    invalidateDecorators();
    updateUi();
}
Also used : LocalDate(org.threeten.bp.LocalDate) SuppressLint(android.annotation.SuppressLint)

Example 13 with LocalDate

use of org.threeten.bp.LocalDate in project material-calendarview by prolificinteractive.

the class MaterialCalendarView method getWeekCountBasedOnMode.

private int getWeekCountBasedOnMode() {
    int weekCount = calendarMode.visibleWeeksCount;
    final boolean isInMonthsMode = calendarMode.equals(CalendarMode.MONTHS);
    if (isInMonthsMode && mDynamicHeightEnabled && adapter != null && pager != null) {
        final LocalDate cal = adapter.getItem(pager.getCurrentItem()).getDate();
        final LocalDate tempLastDay = cal.withDayOfMonth(cal.lengthOfMonth());
        weekCount = tempLastDay.get(WeekFields.of(firstDayOfWeek, 1).weekOfMonth());
    }
    return showWeekDays ? weekCount + DAY_NAMES_ROW : weekCount;
}
Also used : LocalDate(org.threeten.bp.LocalDate) SuppressLint(android.annotation.SuppressLint)

Example 14 with LocalDate

use of org.threeten.bp.LocalDate in project material-calendarview by prolificinteractive.

the class DisableDaysActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_basic);
    ButterKnife.bind(this);
    // Add a decorator to disable prime numbered days
    widget.addDecorator(new PrimeDayDisableDecorator());
    // Add a second decorator that explicitly enables days <= 10. This will work because
    // decorators are applied in order, and the system allows re-enabling
    widget.addDecorator(new EnableOneToTenDecorator());
    final LocalDate calendar = LocalDate.now();
    widget.setSelectedDate(calendar);
    final LocalDate min = LocalDate.of(calendar.getYear(), Month.JANUARY, 1);
    final LocalDate max = LocalDate.of(calendar.getYear() + 1, Month.OCTOBER, 31);
    widget.state().edit().setMinimumDate(min).setMaximumDate(max).commit();
}
Also used : LocalDate(org.threeten.bp.LocalDate)

Example 15 with LocalDate

use of org.threeten.bp.LocalDate in project material-calendarview by prolificinteractive.

the class SwappableBasicActivityDecorated method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_basic_modes);
    ButterKnife.bind(this);
    widget.setOnDateChangedListener(this);
    widget.setShowOtherDates(MaterialCalendarView.SHOW_ALL);
    final LocalDate instance = LocalDate.now();
    widget.setSelectedDate(instance);
    final LocalDate min = LocalDate.of(instance.getYear(), Month.JANUARY, 1);
    final LocalDate max = LocalDate.of(instance.getYear(), Month.DECEMBER, 31);
    widget.state().edit().setMinimumDate(min).setMaximumDate(max).commit();
    widget.addDecorators(new MySelectorDecorator(this), new HighlightWeekendsDecorator(), oneDayDecorator);
}
Also used : HighlightWeekendsDecorator(com.prolificinteractive.materialcalendarview.sample.decorators.HighlightWeekendsDecorator) MySelectorDecorator(com.prolificinteractive.materialcalendarview.sample.decorators.MySelectorDecorator) LocalDate(org.threeten.bp.LocalDate)

Aggregations

LocalDate (org.threeten.bp.LocalDate)20 SuppressLint (android.annotation.SuppressLint)4 ZonedDateTime (org.threeten.bp.ZonedDateTime)4 Nullable (android.support.annotation.Nullable)2 View (android.view.View)2 HighlightWeekendsDecorator (com.prolificinteractive.materialcalendarview.sample.decorators.HighlightWeekendsDecorator)2 MySelectorDecorator (com.prolificinteractive.materialcalendarview.sample.decorators.MySelectorDecorator)2 MainActivity (kogvet.eye.MainActivity)2 Test (org.junit.Test)2 TemporalField (org.threeten.bp.temporal.TemporalField)2 DatePickerDialog (android.app.DatePickerDialog)1 TimePickerDialog (android.app.TimePickerDialog)1 NonNull (android.support.annotation.NonNull)1 TabLayout (android.support.design.widget.TabLayout)1 DatePicker (android.widget.DatePicker)1 TimePicker (android.widget.TimePicker)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1