Skip to content

Commit

Permalink
Disabled days outside of setDateRange.
Browse files Browse the repository at this point in the history
Removed limit on min year must be greater than max year.
  • Loading branch information
raymondlam committed Dec 11, 2013
1 parent 54287f9 commit ce0465d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions datetimepicker-library/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<color name="blue">#ff33b5e5</color>
<color name="darker_blue">#ff0099cc</color>
<color name="date_picker_text_normal">#ff999999</color>
<color name="date_picker_text_disabled">#ffcccccc</color>
<color name="calendar_header">#ff999999</color>
<color name="date_picker_view_animator">#fff2f2f2</color>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,6 @@ public void setOnDateSetListener(OnDateSetListener onDateSetListener) {
}

public void setYearRange(int minYear, int maxYear) {
if (maxYear <= minYear)
throw new IllegalArgumentException("Year end must be larger than year start");
if (maxYear > MAX_YEAR)
throw new IllegalArgumentException("max year end must < " + MAX_YEAR);
if (minYear < MIN_YEAR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,19 @@ public View getView(int position, View convertView, ViewGroup parent) {
int selectedDay = -1;
if (isSelectedDayInMonth(year, month))
selectedDay = this.mSelectedDay.day;
int startDay = -1;
int endDay = 31;
if (this.mController.getStartMonth() == month && this.mController.getMinYear() == year)
startDay = this.mController.getStartDay();
if (this.mController.getEndMonth() == month && this.mController.getMaxYear() == year)
endDay = this.mController.getEndDay();
simpleMonthView.reuse();
monthParams.put("selected_day", Integer.valueOf(selectedDay));
monthParams.put("year", Integer.valueOf(year));
monthParams.put("month", Integer.valueOf(month));
monthParams.put("week_start", Integer.valueOf(this.mController.getFirstDayOfWeek()));
monthParams.put("start_day", Integer.valueOf(startDay));
monthParams.put("end_day", Integer.valueOf(endDay));
simpleMonthView.setMonthParams(monthParams);
simpleMonthView.invalidate();
return simpleMonthView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public class SimpleMonthView extends View {
protected int mWeekStart = 1;
protected int mWidth;
protected int mYear;
protected int mDayDisabledTextColor;
protected int mStartDay;
protected int mEndDay;
private DateFormatSymbols mDateFormatSymbols = new DateFormatSymbols();

public SimpleMonthView(Context context) {
Expand All @@ -73,6 +76,7 @@ public SimpleMonthView(Context context) {
this.mDayOfWeekTypeface = resources.getString(R.string.day_of_week_label_typeface);
this.mMonthTitleTypeface = resources.getString(R.string.sans_serif);
this.mDayTextColor = resources.getColor(R.color.date_picker_text_normal);
this.mDayDisabledTextColor = resources.getColor(R.color.date_picker_text_disabled);
this.mTodayNumberColor = resources.getColor(R.color.blue);
this.mMonthTitleColor = resources.getColor(R.color.white);
this.mMonthTitleBGColor = resources.getColor(R.color.circle_background);
Expand Down Expand Up @@ -149,8 +153,11 @@ protected void drawMonthNums(Canvas canvas) {
int x = paddingDay * (1 + dayOffset * 2) + this.mPadding;
if (this.mSelectedDay == day)
canvas.drawCircle(x, y - MINI_DAY_NUMBER_TEXT_SIZE / 3, DAY_SELECTED_CIRCLE_SIZE, this.mSelectedCirclePaint);

if ((this.mHasToday) && (this.mToday == day))
this.mMonthNumPaint.setColor(this.mTodayNumberColor);
else if (day < this.mStartDay || day > this.mEndDay)
this.mMonthNumPaint.setColor(this.mDayDisabledTextColor);
else
this.mMonthNumPaint.setColor(this.mDayTextColor);
canvas.drawText(String.format("%d", day), x, y, this.mMonthNumPaint);
Expand All @@ -171,7 +178,9 @@ public SimpleMonthAdapter.CalendarDay getDayFromLocation(float x, float y) {

int yDay = (int) (y - MONTH_HEADER_SIZE) / this.mRowHeight;
int day = 1 + ((int) ((x - padding) * this.mNumDays / (this.mWidth - padding - this.mPadding)) - findDayOffset()) + yDay * this.mNumDays;

// If day out of range
if (day < this.mStartDay || day > this.mEndDay)
return null;
return new SimpleMonthAdapter.CalendarDay(this.mYear, this.mMonth, day);
}

Expand Down Expand Up @@ -254,6 +263,8 @@ public void setMonthParams(HashMap<String, Integer> monthParams) {
this.mSelectedDay = ((Integer) monthParams.get("selected_day")).intValue();
this.mMonth = ((Integer) monthParams.get("month")).intValue();
this.mYear = ((Integer) monthParams.get("year")).intValue();
this.mStartDay = ((Integer) monthParams.get("start_day")).intValue();
this.mEndDay = ((Integer) monthParams.get("end_day")).intValue();
Time time = new Time(Time.getCurrentTimezone());
time.setToNow();
this.mHasToday = false;
Expand Down

0 comments on commit ce0465d

Please sign in to comment.