// 将一个月中的每一天的值添加入数组dayNuber中
 private void getDayTitles(int year, int month) {
   String lunarDay = "";
   for (int i = 0; i < dayNumber.length; i++) {
     if (i < daysOfWeek) { // 前一个月
       int temp = daysOfLastMonth - daysOfWeek + 1;
       lunarDay = lc.getLunarDate(year, month - 1, temp + i, false);
       dayNumber[i] = (temp + i) + "." + lunarDay;
     } else if (i < daysOfMonth + daysOfWeek) { // 本月
       String day = String.valueOf(i - daysOfWeek + 1); // 得到的日期
       lunarDay = lc.getLunarDate(year, month, i - daysOfWeek + 1, false);
       dayNumber[i] = i - daysOfWeek + 1 + "." + lunarDay;
       // 对于当前月才去标记当前日期
       if (sys_year.equals(String.valueOf(year))
           && sys_month.equals(String.valueOf(month))
           && sys_day.equals(day)) {
         // 笔记当前日期
         currentFlag = i;
       }
       setShowYear(String.valueOf(year));
       setShowMonth(String.valueOf(month));
       setAnimalsYear(lc.animalsYear(year));
       setLeapMonth(lc.leapMonth == 0 ? "" : String.valueOf(lc.leapMonth));
       setCyclical(lc.cyclical(year));
     } else { // 下一个月
       int iday = i - daysOfMonth - daysOfWeek + 1;
       lunarDay = lc.getLunarDate(year, month + 1, iday, false);
       dayNumber[i] = iday + "." + lunarDay;
     }
   }
 }
Ejemplo n.º 2
0
  public void setDate(int year, int month) {
    this.year = year;
    this.month = month;

    Calendar cToday = Calendar.getInstance();
    Calendar c = Calendar.getInstance();

    c.set(Calendar.YEAR, year);
    c.set(Calendar.MONTH, month);
    c.set(Calendar.DAY_OF_MONTH, 1);
    c.setFirstDayOfWeek(Calendar.MONDAY);

    LunarCalendar lc = new LunarCalendar(context);

    int day = c.get(Calendar.DAY_OF_WEEK) - 1;
    int dateOfMonth = c.getActualMaximum(Calendar.DATE);

    lstDays.clear();
    for (int i = 0; i < day - 1; i++) {
      lstDays.add(new Day());
    }
    for (int i = 0; i < dateOfMonth; i++) {
      Day item = new Day();
      item.year = year;
      item.month = month;
      item.day = i + 1;
      item.highlight = (lstDays.size() % 7 == 5) || (lstDays.size() % 7 == 6);
      item.today =
          (cToday.get(Calendar.MONTH) == item.month)
              && (cToday.get(Calendar.DAY_OF_MONTH) == item.day);
      item.selected = item.today;
      if (item.today) {
        todayIndex = lstDays.size();
      }
      LunarCalendarConvertUtil.parseLunarCalendar(item.year, item.month, item.day, lc);
      item.chineseDay = lc.getChinaDayString(true);
      lstDays.add(item);
    }

    while (lstDays.size() % 7 != 0) {
      lstDays.add(new Day());
    }

    lines = lstDays.size() > 35 ? 6 : 5;
  }