Search in sources :

Example 1 with DisableDecorator

use of com.pangpangzhu.p2papp.test.calendardecorators.DisableDecorator in project GitTest by xiaoxige.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    materialCalendarView = (MaterialCalendarView) findViewById(R.id.materialCalendarView);
    disableDecorator = new DisableDecorator(this);
    broadDecorator = new BroadDecorator(this);
    // 三年前
    Calendar mixTime = Calendar.getInstance();
    mixTime.add(Calendar.MONTH, -3 * 12);
    // 二十年后
    Calendar maxTime = Calendar.getInstance();
    maxTime.add(Calendar.YEAR, 5);
    maxTime.set(Calendar.DAY_OF_MONTH, maxTime.getActualMaximum(Calendar.DAY_OF_MONTH));
    materialCalendarView.addDecorators(new DefaultDecorator(this), disableDecorator, broadDecorator, descDecorator, mSelectDecorator);
    materialCalendarView.setTopbarVisible(true);
    materialCalendarView.setDynamicHeightEnabled(true);
    materialCalendarView.setSelectionMode(MaterialCalendarView.SELECTION_MODE_SINGLE);
    materialCalendarView.state().edit().setCalendarDisplayMode(CalendarMode.MONTHS).setMinimumDate(mixTime.getTime()).setMaximumDate(maxTime.getTime()).commit();
    materialCalendarView.setSelectedDate(CalendarDay.today());
    materialCalendarView.invalidateDecorators();
    materialCalendarView.setOnDateChangedListener(new OnDateSelectedListener() {

        @Override
        public void onDateSelected(@NonNull MaterialCalendarView widget, @NonNull CalendarDay date, boolean selected) {
            List<CalendarDay> dates = new ArrayList<>();
            dates.add(date);
            mSelectDecorator.setDays(dates);
            descDecorator.setDays(dates);
            materialCalendarView.invalidateDecorators();
        }

        @Override
        public void onDisableDateSelected(@NonNull MaterialCalendarView widget, @NonNull CalendarDay date, boolean selected) {
        }
    });
}
Also used : DisableDecorator(com.pangpangzhu.p2papp.test.calendardecorators.DisableDecorator) Calendar(java.util.Calendar) DefaultDecorator(com.pangpangzhu.p2papp.test.calendardecorators.DefaultDecorator) BroadDecorator(com.pangpangzhu.p2papp.test.calendardecorators.BroadDecorator) ArrayList(java.util.ArrayList) List(java.util.List) OnDateSelectedListener(com.prolificinteractive.materialcalendarview.OnDateSelectedListener) MaterialCalendarView(com.prolificinteractive.materialcalendarview.MaterialCalendarView) CalendarDay(com.prolificinteractive.materialcalendarview.CalendarDay)

Aggregations

BroadDecorator (com.pangpangzhu.p2papp.test.calendardecorators.BroadDecorator)1 DefaultDecorator (com.pangpangzhu.p2papp.test.calendardecorators.DefaultDecorator)1 DisableDecorator (com.pangpangzhu.p2papp.test.calendardecorators.DisableDecorator)1 CalendarDay (com.prolificinteractive.materialcalendarview.CalendarDay)1 MaterialCalendarView (com.prolificinteractive.materialcalendarview.MaterialCalendarView)1 OnDateSelectedListener (com.prolificinteractive.materialcalendarview.OnDateSelectedListener)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 List (java.util.List)1