No one has a library similar to this Range DatePicker

enter image description here

I meanwhile, only use this, but it is not practical.

https://github.com/borax12/MaterialDateRangePicker

Addition:

enter image description here

  • four
  • it will be difficult to show the gap if the dates are in different months, for example. - Vladyslav Matviienko
  • @metalurgus, this lib can do that) - YuriySPb
  • @Yuriy SPb, yes, I already looked at the changelog. I wonder how they display this ... - Vladyslav Matviienko
  • @metalurgus, they have a fairly flexible system of using selectors, background and text color for each cell. For example, I did so that the extreme dates are marked in circles, and everything between them is a broad line. - Yuriy SPb

1 answer 1

The essence of the Material Calendar View decorators is as follows:

  1. You create a decorator in which you define which dates should be decorated and how
  2. To decorate differently the end, the beginning and the middle of the date range, you need 2 decorators.
  3. For the first, send CalendarDay to the beginning and end of the gap. In the decorator method shouldDecorate (CalendarDay day), return the result of comparing the incoming day with the days passed to the decorator when it was created.

So you can assign a different background / selector / text color for different selected days.

Here are examples of decorators for the boundaries of the interval of dates and for their middle.

private class StartDayViewDecorator implements DayViewDecorator { private static final int NUM_OF_DAY_CELLS_FROM_LEFT_TO_RIGHT = 7; private CalendarDay startDay; private boolean start; private StartDayViewDecorator(CalendarDay calendarDays, boolean start) { startDay = calendarDays; this.start = start; } @Override public boolean shouldDecorate(CalendarDay day) { return day.equals(startDay); } @Override public void decorate(DayViewFacade view) { int topBottomPadding = getResources().getDimensionPixelSize(R.dimen.default_margin_small); int halfCellWidth = Utils.getScreenWidth() / NUM_OF_DAY_CELLS_FROM_LEFT_TO_RIGHT / 2 + topBottomPadding; if (start) { LayerDrawable bg = (LayerDrawable) ContextCompat.getDrawable(getActivity(), R.drawable.bg_circle_primary_with_padding_and_rect_start); bg.setLayerInset(0, halfCellWidth, topBottomPadding, 0, topBottomPadding); bg.setLayerInset(1, 0, topBottomPadding, 0, topBottomPadding); view.setBackgroundDrawable(bg); } else { LayerDrawable bg = (LayerDrawable) ContextCompat.getDrawable(getActivity(), R.drawable.bg_circle_primary_with_padding_and_rect_end); bg.setLayerInset(0, 0, topBottomPadding, 0, topBottomPadding); bg.setLayerInset(1, 0, topBottomPadding, halfCellWidth - topBottomPadding, topBottomPadding); bg.setLayerInset(2, 0, topBottomPadding, 0, topBottomPadding); view.setBackgroundDrawable(bg); } view.setSelectionDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.calendar_day_selector_out_range_transparent)); view.addSpan(new ForegroundColorSpan(Color.WHITE)); } } private class InnerDayViewDecorator implements DayViewDecorator { private Set<CalendarDay> mCalendarDays; private InnerDayViewDecorator(Set<CalendarDay> calendarDays) { mCalendarDays = calendarDays; } @Override public boolean shouldDecorate(CalendarDay day) { return mCalendarDays.contains(day); } @Override public void decorate(DayViewFacade view) { view.setSelectionDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.calendar_day_selector_out_range_transparent)); view.setBackgroundDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.calendar_day_selector_in_range)); view.addSpan(new ForegroundColorSpan(Color.WHITE)); } }