Ejemplo n.º 1
0
 private final void onDateClick(int pos) {
   mDateHelper.setDate(mDate, mParamDate);
   mDateHelper.addDays(mParamDate, pos - mWeekday + 1);
   mParamFest.gFest = dbHelper.getAgFest(mParamDate.gMonth, mParamDate.gDay);
   mParamFest.cFest = dbHelper.getAcFest(mParamDate.cMonth, mParamDate.cDay);
   if (pos == mMuqinjieIndex) {
     if (5 == mParamDate.gMonth) mParamFest.other = muqinjie;
   } else if (pos == mFuqinjieIndex) {
     if (6 == mParamDate.gMonth) mParamFest.other = fuqinjie;
   } else if (pos == mChuxiIndex) {
     mParamFest.cFest = chuxi;
   }
   // 设置生日,在这里
   // TODO:
   String solarTerm = null;
   if (pos == mSectionIndex) {
     solarTerm = mDateHelper.GetSectionalTermName(mParamDate.gMonth);
   } else if (pos == mPrincipleIndex) {
     solarTerm = mDateHelper.GetPrincipleTermName(mParamDate.gMonth);
   }
   dateClickListener.dateClick(
       pos,
       mParamDate,
       mParamFest,
       solarTerm,
       StarIndexer.star(mParamDate.gMonth, mParamDate.gDay));
 }
Ejemplo n.º 2
0
  public CalendarPlugin(View base) {
    mGrid = (GridView) base.findViewById(R.id.grid_calendar);
    DateAdapter mAdapter = new DateAdapter(mGrid);
    mGrid.setAdapter(mAdapter);
    mWrappers = mAdapter.getWrappers();
    mDateHelper = DateHelper.getInstance();
    isPreFocus = false; // 确保如果setFocus首先被调用,可以将focus焦点至于相应cell
    mLastFocusCell = mWrappers.get(mLastFocusIndex);
    dbHelper = DbHelper.getInstance(mGrid.getContext());

    // 代理GridView的onClicklistener
    mGrid.setOnItemClickListener(this);
    // touch返回true,使workspace正常运行
    // mGrid.setOnTouchListener(this); // 因为有了onItemClickListener,这个就不需要了
    base.findViewById(R.id.table_weektitle).setOnTouchListener(this);
  }
Ejemplo n.º 3
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);
  }