private void init(Context context) { ArrayList<String> years = new ArrayList<String>(); for (int year = mController.getMinYear(); year <= mController.getMaxYear(); year++) { years.add(String.format("%d", year)); } mAdapter = new YearAdapter(context, R.layout.year_label_text_view, years); setAdapter(mAdapter); }
@SuppressLint("NewApi") @SuppressWarnings("unchecked") @Override public View getView(int position, View convertView, ViewGroup parent) { MonthView v; HashMap<String, Integer> drawingParams = null; if (convertView != null) { v = (MonthView) convertView; // We store the drawing parameters in the view so it can be recycled drawingParams = (HashMap<String, Integer>) v.getTag(); } else { v = createMonthView(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(); 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(MonthView.VIEW_PARAMS_SELECTED_DAY, selectedDay); drawingParams.put(MonthView.VIEW_PARAMS_YEAR, year); drawingParams.put(MonthView.VIEW_PARAMS_MONTH, month); drawingParams.put(MonthView.VIEW_PARAMS_WEEK_START, mController.getFirstDayOfWeek()); v.setMonthParams(drawingParams); v.invalidate(); return v; }
@Override public int getCount() { return ((mController.getMaxYear() - mController.getMinYear()) + 1) * MONTHS_IN_YEAR; }
public void onDateChanged() { mAdapter.notifyDataSetChanged(); postSetSelectionCentered(mController.getSelectedDay().year - mController.getMinYear()); }