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