private void onGridItemClickListener(CalndarGridItem sender) { // 更新选中效果 selectedGridItem.ClearSelectedEffect(); if (!sender.daysAreEqual(TODAY)) { sender.SetSelectedEffect(); } selectedGridItem = sender; // 更新任务事件列表 refreshEventList(); }
/** * 创建日期格子,包括星期页签 */ private void refreshCalenderGrid(int offsetMonth) { // 重置当前月 currentMonthCounter = offsetMonth; if (selectedGridItem != null) { selectedGridItem.ClearSelectedEffect(); } // 计算当前选择的月 以及上一个月 下一个月 DateTime today = DateTime.Today; // 如果不是本月 if (offsetMonth != 0) { today = today.AddMonths(offsetMonth); } // 下个月 DateTime nextMonth = today.AddMonths(1); // 上个月 DateTime prevMonth = today.AddMonths(-1); // 本月的第一天 DateTime temp = new DateTime(today.Year, today.Month, 1); int dayOfWeek = (int)temp.DayOfWeek; int list_index = 7; // 显示上个月剩余的天数 int dayOfPrevMonth = System.DateTime.DaysInMonth(prevMonth.Year, prevMonth.Month); for (int i = dayOfWeek - 1; i >= 0; i--) { CalndarGridItem item = mCalenderItemList[list_index++]; item.ResetItem(); //item.setDayText((dayOfPrevMonth - i) + ""); item.setDateTime(new DateTime(prevMonth.Year, prevMonth.Month, (dayOfPrevMonth - i))); item.setTextColor(Color.FromArgb(50, 63, 86)); } // 显示本月的天数 int daysOfCurrentMonth = System.DateTime.DaysInMonth(today.Year, today.Month); for (int i = 1; i <= daysOfCurrentMonth && list_index < mCalenderItemList.Count; i++) { string day = i.ToString(); // 创建日期格子 CalndarGridItem item = mCalenderItemList[list_index++]; item.ResetItem(); item.setDateTime(new DateTime(today.Year, today.Month, i)); item.setTextColor(Color.FromArgb(255, 255, 255)); // 今天 if (offsetMonth == 0 && i == DateTime.Today.Day) { item.makeToDay(); //首次启动没有选择item,就选中今天 if (selectedGridItem == null) { selectedGridItem = item; } } String key = Utils.GetDateString(today, day); if (mEventData.ContainsKey(key.GetHashCode())) { if (offsetMonth <= 0 && i < TODAY.Day) { item.hadNote(); } else { item.hasNote(); } } } // 显示下一个月的前几天 int daysOfNextMonth = dayOfWeek - 1 + daysOfCurrentMonth; for (int i = 1; i < 42 - daysOfNextMonth; i++) { CalndarGridItem item = mCalenderItemList[list_index++]; item.ResetItem(); item.setDateTime(new DateTime(nextMonth.Year, nextMonth.Month, i)); item.setTextColor(Color.FromArgb(50, 63, 86)); } // 设置界面年月 currentMonth.Text = today.ToString("MMMM"); currentYear.Text = today.Year + ""; // 设置选择 if (!selectedGridItem.daysAreEqual(TODAY)) { selectedGridItem.SetSelectedEffect(); } refreshEventList(); }