public DayItem() { setBackground(-1); setLabelTextColor(0xFF333333); setLabelTextSize(14); setSubLabelTextColor(0xFF333333); setSubLabelTextSize(8); }
public void notifyDataChanged() { if (dayItem == null) return; if (dayItem.getBackground() != -1) setBackgroundResource(dayItem.getBackground()); tvLabel.setTextColor(dayItem.getLabelTextColor()); tvLabel.setTextSize(TypedValue.COMPLEX_UNIT_SP, dayItem.getLabelTextSize()); tvLabel.setText(TextUtils.isEmpty(dayItem.getLabel()) ? "" : dayItem.getLabel()); tvSubLabel.setTextColor(dayItem.getSubLabelTextColor()); tvSubLabel.setTextSize(TypedValue.COMPLEX_UNIT_SP, dayItem.getSubLabelTextSize()); tvSubLabel.setText(TextUtils.isEmpty(dayItem.getSubLabel()) ? "" : dayItem.getSubLabel()); } }
/** * 添加上个月的最后几天 * * @param dayItems */ private static void addNextMonthDays(List<DayItem> dayItems, int count) { if (count == 0) return; DayItem lastItem = dayItems.get(dayItems.size() - 1); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(lastItem.getDate()); for (int i = 0; i < count; i++) { calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) + 1); DayItem item = new DayItem(); item.setKey(1); item.setDate(calendar.getTimeInMillis()); item.setLabel(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH))); dayItems.add(item); } }
private void initMonthView(int year, int month){ List<DayItem> dayItems = MonthUtils.getMonthDays(year, month); for (int i = 0; i < dayItems.size(); i++) { boolean enable = new Random().nextBoolean(); DayItem item = dayItems.get(i); switch (item.getKey()){ case -1://上个月的最后几天 case 1://下个月的前几天 item.setBackground(R.drawable.circle_gray_light_shape); break; case 0://本月的所有天数 item.setBackground(R.drawable.circle_theme_light_shape); break; } item.setSubLabel(enable ? "可约" : "不可约"); item.setSubLabelTextColor(enable ? Color.YELLOW : 0xFF666666); } monthView.setDays(dayItems); }
/** * 添加上个月的最后几天 * * @param dayItems */ private static void addPreMonthDays(List<DayItem> dayItems) { DayItem firstItem = dayItems.get(0); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(firstItem.getDate()); int weekDay = calendar.get(Calendar.DAY_OF_WEEK); if (weekDay > Calendar.SUNDAY) { calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH) - 1); DayItem item = new DayItem(); item.setKey(-1); item.setDate(calendar.getTimeInMillis()); item.setLabel(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH))); dayItems.add(0, item); addPreMonthDays(dayItems); } }
/** * 添加本月所有天数 * * @param dayItems */ private static void addCurrentMonthDays(List<DayItem> dayItems, int year, int month) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month - 1); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); int curMonthDayCount = getMonthDayCount(calendar); for (int i = 0; i < curMonthDayCount; i++) { calendar.set(Calendar.DAY_OF_MONTH, i + 1); DayItem item = new DayItem(); item.setKey(0); item.setDate(calendar.getTimeInMillis()); item.setLabel(String.valueOf(calendar.get(Calendar.DAY_OF_MONTH))); dayItems.add(item); } }