YearPickerViewpublic class YearPickerView extends ListView implements OnDateChangedListener, AdapterView.OnItemClickListenerDisplays 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 int | getFirstPositionOffset()
final View firstChild = getChildAt(0);
if (firstChild == null) {
return 0;
}
return firstChild.getTop();
| public int | getYearSelectedCircleColor()
return mYearSelectedCircleColor;
| public void | init(DatePickerController controller)
mController = controller;
mController.registerOnDateChangedListener(this);
updateAdapterData();
onDateChanged();
| public void | onDateChanged()
updateAdapterData();
mAdapter.notifyDataSetChanged();
postSetSelectionCentered(
mController.getSelectedDay().get(Calendar.YEAR) - mMinDate.get(Calendar.YEAR));
| public void | onInitializeAccessibilityEvent(android.view.accessibility.AccessibilityEvent event)
super.onInitializeAccessibilityEvent(event);
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
event.setFromIndex(0);
event.setToIndex(0);
}
| public void | onItemClick(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 void | postSetSelectionCentered(int position)
postSetSelectionFromTop(position, mViewSize / 2 - mChildSize / 2);
| public void | postSetSelectionFromTop(int position, int offset)
post(new Runnable() {
@Override
public void run() {
setSelectionFromTop(position, offset);
requestLayout();
}
});
| void | setItemTextAppearance(int resId)
mAdapter.setItemTextAppearance(resId);
| public void | setRange(java.util.Calendar min, java.util.Calendar max)
mMinDate.setTimeInMillis(min.getTimeInMillis());
mMaxDate.setTimeInMillis(max.getTimeInMillis());
updateAdapterData();
| public void | setYearSelectedCircleColor(int color)
if (color != mYearSelectedCircleColor) {
mYearSelectedCircleColor = color;
}
requestLayout();
| private void | updateAdapterData()
mAdapter.clear();
final int maxYear = mMaxDate.get(Calendar.YEAR);
for (int year = mMinDate.get(Calendar.YEAR); year <= maxYear; year++) {
mAdapter.add(year);
}
|
|