一、概述
MaterialCalendarView是一個開源項目。功能強大支持多選、單選、標注等。
二、問題
1、其繼承自ViewGroup,故與CalendarView半毛錢關系都沒有,完全是一個新的類
2、其子類CalendarDay是經過調整的
CalendarDay date = new CalendarDay();
......
Log.e(LOG_TAG, "Date選中日期:" + date.getDate().getYear() + "-" + date.getDate().getMonth() + "-" + date.getDate().getDay());
Log.e(LOG_TAG, "Calendar選中日期:" + date.getCalendar().get(Calendar.YEAR) + "-" + (date.getCalendar().get(Calendar.MONTH) + 1) + "-" + date.getCalendar().get(Calendar.DAY_OF_MONTH));
得到的結果為
Date選中日期:116-3-6
Calendar選中日期:2016-4-30
即:
CalendarDay.getDate().getYear()得到的年份 = 真實年份 - 1900
CalendarDay.getDate().getMonth()得到的月份 = 真實年份 - 1
CalendarDay.getDate().getDay()得到的日 = 星期數 - 1
3、關於DayViewDecorator類
此類為抽象類,定義如下
/**
* Decorate Day views with drawables and text manipulation
*/
public interface DayViewDecorator {
/**
* Determine if a specific day should be decorated
*
* @param day {@linkplain CalendarDay} to possibly decorate
* @return true if this decorator should be applied to the provided day
*/
boolean shouldDecorate(CalendarDay day);
/**
* Set decoration options onto a facade to be applied to all relevant days
*
* @param view View to decorate
*/
void decorate(DayViewFacade view);
}
實際使用時,只需實現上述兩個方法即可,例如
public class EventDecorator implements DayViewDecorator {
private final int color;
private final HashSet<CalendarDay> dates;
public EventDecorator(int color, Collection<CalendarDay> dates) {
this.color = color;
this.dates = new HashSet<>(dates);
}
@Override
public boolean shouldDecorate(CalendarDay day) {
return dates.contains(day);
}
@Override
public void decorate(DayViewFacade view) {
view.addSpan(new DotSpan(5, color));
}
}
