Android - Working example of how to disable weekends using Square's TimeSquare Calendar

2.3k Views Asked by At

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

3

There are 3 best solutions below

0
On

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

 }
4
On

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);
  }
});
0
On

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