/**
  * 仅将focus的焦点对准指定的index,而不触发ItemClick事件。 比如,日历滑动到下一个月的动作前,将焦点对准指定位置,
  * 但是由于未必滑动到一个月,所以,可以仅将焦点先对准index位置。
  */
 public void setPreFocus(int index) {
   if (index < 0 || index > 41) return;
   mLastFocusIndex = index;
   mLastFocusCell.setFocusForce(false);
   mLastFocusCell = mWrappers.get(index);
   mLastFocusCell.setFocusForce(true);
   isPreFocus = true;
 }
 public void setFocusOnDay(DateInfo date, int day) {
   mLastFocusIndex = mDateHelper.dayOfWeek(date) + day - 2;
   mLastFocusCell.setFocusForce(false);
   mLastFocusCell = mWrappers.get(mLastFocusIndex);
   mLastFocusCell.setFocusForce(true);
   if (null != dateClickListener) onDateClick(mLastFocusIndex);
   isPreFocus = false;
 }
 public void setFocus(int index) {
   if (index < 0 || index > 41) return;
   if (!isPreFocus || mLastFocusIndex != index) {
     mLastFocusIndex = index;
     mLastFocusCell.setFocusForce(false);
     mLastFocusCell = mWrappers.get(index);
     mLastFocusCell.setFocusForce(true);
   }
   if (null != dateClickListener) onDateClick(mLastFocusIndex);
   isPreFocus = false;
 }
 @Override
 public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
   DateWrapper tp = mWrappers.get(pos);
   if (tp.isEnable()) {
     mLastFocusIndex = pos;
     mLastFocusCell.setFocusForce(false);
     mLastFocusCell = tp;
     mLastFocusCell.setFocus(true);
     if (null != dateClickListener) onDateClick(pos);
     isPreFocus = false;
   } else if ((pos == 38 || pos == 40) && null != dateClickListener) {
     dateClickListener.dateClick(pos, null, null, null, 0);
   }
 }
  /** 此函数要求calendar必须从1号开始,并且对此不做检查。 */
  public void setCalendar(DateInfo referDate) {
    // 创建临时日期数据mDate
    mDateHelper.setDate(referDate, mDate);
    // 创建本月日历,为逻辑上简洁,对齐到本月1日
    if (mDate.gDay != 1) {
      mDateHelper.addDays(mDate, 1 - mDate.gDay);
    }
    mWeekday = mDateHelper.dayOfWeek(mDate);

    mMonthLength = mDateHelper.daysInMonth(mDate.gYear, mDate.gMonth);
    int lastOffset = mWeekday - 1;
    int nextOffset = lastOffset + mMonthLength;

    // 除夕,母亲节,父亲节这三个节日没有具体日期,
    // 在想到更好实现办法前,暂时先特殊处理
    mChuxiIndex = mMuqinjieIndex = mFuqinjieIndex = -1;
    if (5 == mDate.gMonth) {
      mMuqinjieIndex = (mWeekday == 1 ? 7 : 14);
    } else if (6 == mDate.gMonth) {
      mFuqinjieIndex = (mWeekday == 1 ? 14 : 21);
    }
    mSectionIndex = mWeekday + mDateHelper.sectionalTerm(mDate.gYear, mDate.gMonth) - 2;
    mPrincipleIndex = mWeekday + mDateHelper.principleTerm(mDate.gYear, mDate.gMonth) - 2;
    int tpMonth = mDate.gMonth + 1;
    if (tpMonth > 12) tpMonth = 1;
    int tpYear = (tpMonth == 1 ? (mDate.gYear + 1) : mDate.gYear);
    int tpSectionIndex = nextOffset + mDateHelper.sectionalTerm(tpYear, tpMonth) - 1;
    mDateHelper.addDays(mDate, -lastOffset);

    DateWrapper date = null;
    String gFest = null, cFest = null;
    for (int i = 0; i < 42; ++i) {
      date = mWrappers.get(i);
      date.setEnable(i < lastOffset ? false : (i >= nextOffset ? false : true));
      date.setSolar(mDateHelper.gregorianDateNames[mDate.gDay]);
      date.setLunar(mDateHelper.chineseDateNames[mDate.cDay]);

      cFest = dbHelper.getAcFest(mDate.cMonth, mDate.cDay);

      if (i == mSectionIndex) gFest = mDateHelper.GetSectionalTermName(mDate.gMonth);
      else if (i == mPrincipleIndex) gFest = mDateHelper.GetPrincipleTermName(mDate.gMonth);
      else if (i == tpSectionIndex) gFest = mDateHelper.GetSectionalTermName(tpMonth);
      else gFest = dbHelper.getAgFest(mDate.gMonth, mDate.gDay);

      if (null != gFest && null == cFest) {
        if (5 == mDate.gMonth) {
          if (mMuqinjieIndex == i) {
            cFest = gFest;
            gFest = muqinjie;
          }
        } else if (6 == mDate.gMonth) {
          if (mFuqinjieIndex == i) {
            cFest = gFest;
            gFest = fuqinjie;
          }
        }
      } else {
        if (5 == mDate.gMonth) {
          if (mMuqinjieIndex == i) gFest = muqinjie;
        } else if (6 == mDate.gMonth) {
          if (mFuqinjieIndex == i) gFest = fuqinjie;
        }
      }

      if (null == gFest) {
        if (cFest != null) date.setHint(cFest);
        else date.setHint(null);
      } else {
        date.setHint(gFest);
        if (cFest != null) date.setLunar(cFest);
      }

      mDateHelper.rollUpOneDay(mDate);
      if (1 == mDate.cDay && 1 == mDate.cMonth) {
        if (null == gFest) date.setHint(chuxi);
        else date.setLunar(chuxi);
        mChuxiIndex = i;
      }
    }

    mDateHelper.setDate(referDate, mDate);
  }