FileDocCategorySizeDatePackage
MonthAdapter.javaAPI DocAndroid 5.1 API6894Thu Mar 12 22:22:50 GMT 2015com.android.datetimepicker.date

MonthAdapter

public abstract class MonthAdapter extends android.widget.BaseAdapter implements com.android.datetimepicker.date.MonthView.OnDayClickListener
An adapter for a list of {@link MonthView} items.

Fields Summary
private static final String
TAG
private final android.content.Context
mContext
protected final DatePickerController
mController
private CalendarDay
mSelectedDay
protected static int
WEEK_7_OVERHANG_HEIGHT
protected static final int
MONTHS_IN_YEAR
Constructors Summary
public MonthAdapter(android.content.Context context, DatePickerController controller)

        mContext = context;
        mController = controller;
        init();
        setSelectedDay(mController.getSelectedDay());
    
Methods Summary
public abstract MonthViewcreateMonthView(android.content.Context context)

public intgetCount()

        return ((mController.getMaxYear() - mController.getMinYear()) + 1) * MONTHS_IN_YEAR;
    
public java.lang.ObjectgetItem(int position)

        return null;
    
public longgetItemId(int position)

        return position;
    
public com.android.datetimepicker.date.MonthAdapter$CalendarDaygetSelectedDay()

        return mSelectedDay;
    
public android.view.ViewgetView(int position, android.view.View convertView, android.view.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;
    
public booleanhasStableIds()

        return true;
    
protected voidinit()
Set up the gesture detector and selected time

        mSelectedDay = new CalendarDay(System.currentTimeMillis());
    
private booleanisSelectedDayInMonth(int year, int month)

        return mSelectedDay.year == year && mSelectedDay.month == month;
    
public voidonDayClick(MonthView view, com.android.datetimepicker.date.MonthAdapter$CalendarDay day)

        if (day != null) {
            onDayTapped(day);
        }
    
protected voidonDayTapped(com.android.datetimepicker.date.MonthAdapter$CalendarDay day)
Maintains the same hour/min/sec but moves the day to the tapped day.

param
day The day that was tapped

        mController.tryVibrate();
        mController.onDayOfMonthSelected(day.year, day.month, day.day);
        setSelectedDay(day);
    
public voidsetSelectedDay(com.android.datetimepicker.date.MonthAdapter$CalendarDay day)
Updates the selected day and related parameters.

param
day The day to highlight

        mSelectedDay = day;
        notifyDataSetChanged();