FileDocCategorySizeDatePackage
YearPickerView.javaAPI DocAndroid 5.1 API6347Thu Mar 12 22:22:10 GMT 2015android.widget

YearPickerView

public class YearPickerView extends ListView implements OnDateChangedListener, AdapterView.OnItemClickListener
Displays a selectable list of years.

Fields Summary
private final Calendar
mMinDate
private final Calendar
mMaxDate
private final YearAdapter
mAdapter
private final int
mViewSize
private final int
mChildSize
private DatePickerController
mController
private int
mSelectedPosition
private int
mYearSelectedCircleColor
Constructors Summary
public YearPickerView(android.content.Context context)


       
        this(context, null);
    
public YearPickerView(android.content.Context context, android.util.AttributeSet attrs)

        this(context, attrs, R.attr.listViewStyle);
    
public YearPickerView(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr)

        this(context, attrs, defStyleAttr, 0);
    
public YearPickerView(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr, int defStyleRes)

        super(context, attrs, defStyleAttr, defStyleRes);

        final LayoutParams frame = new LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        setLayoutParams(frame);

        final Resources res = context.getResources();
        mViewSize = res.getDimensionPixelOffset(R.dimen.datepicker_view_animator_height);
        mChildSize = res.getDimensionPixelOffset(R.dimen.datepicker_year_label_height);

        setVerticalFadingEdgeEnabled(true);
        setFadingEdgeLength(mChildSize / 3);

        final int paddingTop = res.getDimensionPixelSize(
                R.dimen.datepicker_year_picker_padding_top);
        setPadding(0, paddingTop, 0, 0);

        setOnItemClickListener(this);
        setDividerHeight(0);

        mAdapter = new YearAdapter(getContext(), R.layout.year_label_text_view);
        setAdapter(mAdapter);
    
Methods Summary
public intgetFirstPositionOffset()

        final View firstChild = getChildAt(0);
        if (firstChild == null) {
            return 0;
        }
        return firstChild.getTop();
    
public intgetYearSelectedCircleColor()

        return mYearSelectedCircleColor;
    
public voidinit(DatePickerController controller)

        mController = controller;
        mController.registerOnDateChangedListener(this);

        updateAdapterData();

        onDateChanged();
    
public voidonDateChanged()

        updateAdapterData();
        mAdapter.notifyDataSetChanged();
        postSetSelectionCentered(
                mController.getSelectedDay().get(Calendar.YEAR) - mMinDate.get(Calendar.YEAR));
    
public voidonInitializeAccessibilityEvent(android.view.accessibility.AccessibilityEvent event)

        super.onInitializeAccessibilityEvent(event);

        if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
            event.setFromIndex(0);
            event.setToIndex(0);
        }
    
public voidonItemClick(AdapterView parent, android.view.View view, int position, long id)

        mController.tryVibrate();
        if (position != mSelectedPosition) {
            mSelectedPosition = position;
            mAdapter.notifyDataSetChanged();
        }
        mController.onYearSelected(mAdapter.getItem(position));
    
public voidpostSetSelectionCentered(int position)

        postSetSelectionFromTop(position, mViewSize / 2 - mChildSize / 2);
    
public voidpostSetSelectionFromTop(int position, int offset)

        post(new Runnable() {

            @Override
            public void run() {
                setSelectionFromTop(position, offset);
                requestLayout();
            }
        });
    
voidsetItemTextAppearance(int resId)

        mAdapter.setItemTextAppearance(resId);
    
public voidsetRange(java.util.Calendar min, java.util.Calendar max)

        mMinDate.setTimeInMillis(min.getTimeInMillis());
        mMaxDate.setTimeInMillis(max.getTimeInMillis());

        updateAdapterData();
    
public voidsetYearSelectedCircleColor(int color)

        if (color != mYearSelectedCircleColor) {
            mYearSelectedCircleColor = color;
        }
        requestLayout();
    
private voidupdateAdapterData()

        mAdapter.clear();

        final int maxYear = mMaxDate.get(Calendar.YEAR);
        for (int year = mMinDate.get(Calendar.YEAR); year <= maxYear; year++) {
            mAdapter.add(year);
        }