0

I'm hoping to get a an example from someone who worked with Square's TimeSquare date-picker calendar. I wish to disable all the weekend dates for the coming year. Anyone achieved this?

Thanks

RMcGuigan
  • 1,147
  • 2
  • 7
  • 11

3 Answers3

1

Looking at the source code, try setDateSelectableFilter():

CalendarPickerView cpv=(CalendarPickerView)findViewById(R.id.whatever_you_called_it);

cpv.setDateSelectableFilter(new DateSelectableFilter() {
  @Override
  public boolean isDateSelectable(Date date) {
    int dow=date.get(Calendar.DAY_OF_WEEK);
    return (dow != Calendar.SATURDAY && dow != Calendar.SUNDAY);
  }
});
CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I seen that - but not 100% sure how to implement - I have written a method (javatime) - that returns all the "working days" for the next 3 months - but this calendar widget seems to want date ranges ... could you suggest a working solution - or start of one ..? – RMcGuigan May 13 '17 at 11:29
  • @RMcGuigan: Um, `DateSelectableFilter` has one method: `isDateSelectable(Date)`. It returns a `boolean`, presumably `true` if it is selectable, `false` otherwise. So, implement `isDateSelectable()` on your `DateSelectableFilter` implementation to return `true` for weekdays, `false` for weekends. Then, attach an instance of your `DateSelectableFilter` implementation to the `CalendarPickerView` via `setDateSelectableFilter()`. Whether or not the view uses date ranges is determined by the `SelectionMode`. – CommonsWare May 13 '17 at 11:37
  • @CommonsWare, How to change the color of the disabled date? – Rakesh Aug 06 '20 at 09:02
  • @Rakesh: Sorry, but I have no idea. – CommonsWare Aug 06 '20 at 11:58
0

For the sake of completeness and possibly save others some time. Here is the full, complete method body

public void init(final Calendar calendar) {
    maxDate = calendar.getTime();
    calendarView.setOnInvalidDateSelectedListener(null);

    calendarView.setDateSelectableFilter(new DateSelectableFilter() {

        Calendar cal=Calendar.getInstance();
        @Override
        public boolean isDateSelectable(Date date) {
            boolean isSelectable=true;
            cal.setTime(date);
            int dayOfWeek=cal.get(Calendar.DAY_OF_WEEK);

            if(dayOfWeek==Calendar.SATURDAY || dayOfWeek==Calendar.SUNDAY){
                isSelectable=false;
            }
            return isSelectable;
        }
    });
    calendarView.init(new Date(), maxDate).withSelectedDate(new Date());

 }
RMcGuigan
  • 1,147
  • 2
  • 7
  • 11
0

You can use below code for making weekends off in android-times-square calenderview, Just use this code before init.

calendar.setOnInvalidDateSelectedListener(null);
    calendar.setDateSelectableFilter(new DateSelectableFilter() {

        Calendar cal=Calendar.getInstance();
        @Override
        public boolean isDateSelectable(Date date) {
            boolean isSelecteable=true;
            cal.setTime(date);
            int dayOfWeek=cal.get(Calendar.DAY_OF_WEEK);        

                             //disable if weekend
            if(dayOfWeek==Calendar.SATURDAY || dayOfWeek==Calendar.SUNDAY){
               isSelecteable=false; 
            }
            return isSelecteable;
        }
    });
ishu
  • 123
  • 8