Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public class DatePickerDialog extends DialogFragment implements View.OnClickList
private HashSet<OnDateChangedListener> mListeners = new HashSet<OnDateChangedListener>();
private OnDateSetListener mCallBack;

private boolean mYearOnly = false;

private AccessibleDateAnimator mAnimator;
private boolean mDelayAnimation = true;
private long mLastVibrate;
Expand Down Expand Up @@ -108,6 +110,7 @@ public static DatePickerDialog newInstance(OnDateSetListener onDateSetListener,
return datePickerDialog;
}

public void setYearOnly(boolean yearOnly) { mYearOnly = yearOnly; }

public void setVibrate(boolean vibrate) {
mVibrate = vibrate;
Expand Down Expand Up @@ -314,6 +317,7 @@ public void onClick(View view) {
mYearPickerView.postSetSelectionFromTop(listPosition, listPositionOffset);
}
}
setCurrentView(mYearOnly ? YEAR_VIEW : MONTH_AND_DAY_VIEW);
return view;
}

Expand Down Expand Up @@ -348,9 +352,9 @@ public void onSaveInstanceState(Bundle bundle) {
bundle.putInt(KEY_CURRENT_VIEW, mCurrentView);

int listPosition = -1;
if (mCurrentView == 0) {
if (mCurrentView == MONTH_AND_DAY_VIEW) {
listPosition = mDayPickerView.getMostVisiblePosition();
} if (mCurrentView == 1) {
} if (mCurrentView == YEAR_VIEW) {
listPosition = mYearPickerView.getFirstVisiblePosition();
bundle.putInt(KEY_LIST_POSITION_OFFSET, mYearPickerView.getFirstPositionOffset());
}
Expand All @@ -362,6 +366,8 @@ public void onYearSelected(int year) {
adjustDayInMonthIfNeeded(mCalendar.get(Calendar.MONTH), year);
mCalendar.set(Calendar.YEAR, year);
updatePickers();
if (mYearOnly)
onDoneButtonClick();
setCurrentView(MONTH_AND_DAY_VIEW);
updateDisplay(true);
}
Expand Down