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

YearPickerView

public class YearPickerView extends android.widget.ListView implements android.widget.AdapterView.OnItemClickListener, com.android.datetimepicker.date.DatePickerDialog.OnDateChangedListener
Displays a selectable list of years.

Fields Summary
private static final String
TAG
private final DatePickerController
mController
private YearAdapter
mAdapter
private int
mViewSize
private int
mChildSize
private TextViewWithCircularIndicator
mSelectedView
Constructors Summary
public YearPickerView(android.content.Context context, DatePickerController controller)

param
context


           
         
        super(context);
        mController = controller;
        mController.registerOnDateChangedListener(this);
        ViewGroup.LayoutParams frame = new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT);
        setLayoutParams(frame);
        Resources res = context.getResources();
        mViewSize = res.getDimensionPixelOffset(R.dimen.date_picker_view_animator_height);
        mChildSize = res.getDimensionPixelOffset(R.dimen.year_label_height);
        setVerticalFadingEdgeEnabled(true);
        setFadingEdgeLength(mChildSize / 3);
        init(context);
        setOnItemClickListener(this);
        setSelector(new StateListDrawable());
        setDividerHeight(0);
        onDateChanged();
    
Methods Summary
public intgetFirstPositionOffset()

        final View firstChild = getChildAt(0);
        if (firstChild == null) {
            return 0;
        }
        return firstChild.getTop();
    
private static intgetYearFromTextView(android.widget.TextView view)

        return Integer.valueOf(view.getText().toString());
    
private voidinit(android.content.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);
    
public voidonDateChanged()

        mAdapter.notifyDataSetChanged();
        postSetSelectionCentered(mController.getSelectedDay().year - mController.getMinYear());
    
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(android.widget.AdapterView parent, android.view.View view, int position, long id)

        mController.tryVibrate();
        TextViewWithCircularIndicator clickedView = (TextViewWithCircularIndicator) view;
        if (clickedView != null) {
            if (clickedView != mSelectedView) {
                if (mSelectedView != null) {
                    mSelectedView.drawIndicator(false);
                    mSelectedView.requestLayout();
                }
                clickedView.drawIndicator(true);
                clickedView.requestLayout();
                mSelectedView = clickedView;
            }
            mController.onYearSelected(getYearFromTextView(clickedView));
            mAdapter.notifyDataSetChanged();
        }
    
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();
            }
        });