Skip to content

Commit ce0465d

Browse files
committed
Disabled days outside of setDateRange.
Removed limit on min year must be greater than max year.
1 parent 54287f9 commit ce0465d

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

datetimepicker-library/res/values/colors.xml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<color name="blue">#ff33b5e5</color>
99
<color name="darker_blue">#ff0099cc</color>
1010
<color name="date_picker_text_normal">#ff999999</color>
11+
<color name="date_picker_text_disabled">#ffcccccc</color>
1112
<color name="calendar_header">#ff999999</color>
1213
<color name="date_picker_view_animator">#fff2f2f2</color>
1314

datetimepicker-library/src/com/fourmob/datetimepicker/date/DatePickerDialog.java

-2
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,6 @@ public void setOnDateSetListener(OnDateSetListener onDateSetListener) {
353353
}
354354

355355
public void setYearRange(int minYear, int maxYear) {
356-
if (maxYear <= minYear)
357-
throw new IllegalArgumentException("Year end must be larger than year start");
358356
if (maxYear > MAX_YEAR)
359357
throw new IllegalArgumentException("max year end must < " + MAX_YEAR);
360358
if (minYear < MIN_YEAR)

datetimepicker-library/src/com/fourmob/datetimepicker/date/SimpleMonthAdapter.java

+8
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,19 @@ public View getView(int position, View convertView, ViewGroup parent) {
6161
int selectedDay = -1;
6262
if (isSelectedDayInMonth(year, month))
6363
selectedDay = this.mSelectedDay.day;
64+
int startDay = -1;
65+
int endDay = 31;
66+
if (this.mController.getStartMonth() == month && this.mController.getMinYear() == year)
67+
startDay = this.mController.getStartDay();
68+
if (this.mController.getEndMonth() == month && this.mController.getMaxYear() == year)
69+
endDay = this.mController.getEndDay();
6470
simpleMonthView.reuse();
6571
monthParams.put("selected_day", Integer.valueOf(selectedDay));
6672
monthParams.put("year", Integer.valueOf(year));
6773
monthParams.put("month", Integer.valueOf(month));
6874
monthParams.put("week_start", Integer.valueOf(this.mController.getFirstDayOfWeek()));
75+
monthParams.put("start_day", Integer.valueOf(startDay));
76+
monthParams.put("end_day", Integer.valueOf(endDay));
6977
simpleMonthView.setMonthParams(monthParams);
7078
simpleMonthView.invalidate();
7179
return simpleMonthView;

datetimepicker-library/src/com/fourmob/datetimepicker/date/SimpleMonthView.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ public class SimpleMonthView extends View {
6363
protected int mWeekStart = 1;
6464
protected int mWidth;
6565
protected int mYear;
66+
protected int mDayDisabledTextColor;
67+
protected int mStartDay;
68+
protected int mEndDay;
6669
private DateFormatSymbols mDateFormatSymbols = new DateFormatSymbols();
6770

6871
public SimpleMonthView(Context context) {
@@ -73,6 +76,7 @@ public SimpleMonthView(Context context) {
7376
this.mDayOfWeekTypeface = resources.getString(R.string.day_of_week_label_typeface);
7477
this.mMonthTitleTypeface = resources.getString(R.string.sans_serif);
7578
this.mDayTextColor = resources.getColor(R.color.date_picker_text_normal);
79+
this.mDayDisabledTextColor = resources.getColor(R.color.date_picker_text_disabled);
7680
this.mTodayNumberColor = resources.getColor(R.color.blue);
7781
this.mMonthTitleColor = resources.getColor(R.color.white);
7882
this.mMonthTitleBGColor = resources.getColor(R.color.circle_background);
@@ -149,8 +153,11 @@ protected void drawMonthNums(Canvas canvas) {
149153
int x = paddingDay * (1 + dayOffset * 2) + this.mPadding;
150154
if (this.mSelectedDay == day)
151155
canvas.drawCircle(x, y - MINI_DAY_NUMBER_TEXT_SIZE / 3, DAY_SELECTED_CIRCLE_SIZE, this.mSelectedCirclePaint);
156+
152157
if ((this.mHasToday) && (this.mToday == day))
153158
this.mMonthNumPaint.setColor(this.mTodayNumberColor);
159+
else if (day < this.mStartDay || day > this.mEndDay)
160+
this.mMonthNumPaint.setColor(this.mDayDisabledTextColor);
154161
else
155162
this.mMonthNumPaint.setColor(this.mDayTextColor);
156163
canvas.drawText(String.format("%d", day), x, y, this.mMonthNumPaint);
@@ -171,7 +178,9 @@ public SimpleMonthAdapter.CalendarDay getDayFromLocation(float x, float y) {
171178

172179
int yDay = (int) (y - MONTH_HEADER_SIZE) / this.mRowHeight;
173180
int day = 1 + ((int) ((x - padding) * this.mNumDays / (this.mWidth - padding - this.mPadding)) - findDayOffset()) + yDay * this.mNumDays;
174-
181+
// If day out of range
182+
if (day < this.mStartDay || day > this.mEndDay)
183+
return null;
175184
return new SimpleMonthAdapter.CalendarDay(this.mYear, this.mMonth, day);
176185
}
177186

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

0 commit comments

Comments
 (0)