Beispiel #1
0
  @SuppressLint("NewApi")
  @SuppressWarnings("unchecked")
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    SimpleMonthView v;
    HashMap<String, Integer> drawingParams = null;
    if (convertView != null) {
      v = (SimpleMonthView) convertView;
      // We store the drawing parameters in the view so it can be recycled
      drawingParams = (HashMap<String, Integer>) v.getTag();
    } else {
      v = new SimpleMonthView(mContext);
      // Set up the new view
      LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
      v.setLayoutParams(params);
      v.setClickable(true);
      v.setOnDayClickListener(this);
    }
    if (drawingParams == null) {
      drawingParams = new HashMap<String, Integer>();
    }
    drawingParams.clear();

    final int month = position % MONTHS_IN_YEAR;
    final int year = position / MONTHS_IN_YEAR + mController.getMinYear();
    Log.d(TAG, "Year: " + year + ", Month: " + month);

    int selectedDay = -1;
    if (isSelectedDayInMonth(year, month)) {
      selectedDay = mSelectedDay.day;
    }

    // Invokes requestLayout() to ensure that the recycled view is set with the appropriate
    // height/number of weeks before being displayed.
    v.reuse();

    drawingParams.put(SimpleMonthView.VIEW_PARAMS_SELECTED_DAY, selectedDay);
    drawingParams.put(SimpleMonthView.VIEW_PARAMS_YEAR, year);
    drawingParams.put(SimpleMonthView.VIEW_PARAMS_MONTH, month);
    drawingParams.put(SimpleMonthView.VIEW_PARAMS_WEEK_START, mController.getFirstDayOfWeek());
    v.setMonthParams(drawingParams);
    v.invalidate();
    return v;
  }
Beispiel #2
0
 public SimpleMonthAdapter(Context context, CalendarDatePickerController controller) {
   mContext = context;
   mController = controller;
   init();
   setSelectedDay(mController.getSelectedDay());
 }
Beispiel #3
0
 /**
  * Maintains the same hour/min/sec but moves the day to the tapped day.
  *
  * @param day The day that was tapped
  */
 protected void onDayTapped(CalendarDay day) {
   mController.tryVibrate();
   mController.onDayOfMonthSelected(day.year, day.month, day.day);
   setSelectedDay(day);
 }
Beispiel #4
0
 @Override
 public int getCount() {
   return ((mController.getMaxYear() - mController.getMinYear()) + 1) * MONTHS_IN_YEAR;
 }