summaryrefslogtreecommitdiff
path: root/core/java/android/widget/CalendarView.java
diff options
context:
space:
mode:
authorSvetoslav Ganov <svetoslavganov@google.com>2011-09-14 20:18:08 -0700
committerSvetoslav Ganov <svetoslavganov@google.com>2011-09-15 11:26:08 -0700
commitf1189e9a462dcc85918607159c433d9cd23de0bf (patch)
tree618880244eb320e7fdffe159afa8128bbff3fd75 /core/java/android/widget/CalendarView.java
parentea515aeafa01de6f50c854ee381b972ef2478284 (diff)
CalendarView diregarding XML attributes.
1. CalendarView was disregarding XMl attributes. 2. CalendarView was trying to set the current date to today without checking where today is between min and max date. bug:5116456 Change-Id: Ie5a81826a3cd028f42e18a7985461fa283839171
Diffstat (limited to 'core/java/android/widget/CalendarView.java')
-rw-r--r--core/java/android/widget/CalendarView.java20
1 files changed, 14 insertions, 6 deletions
diff --git a/core/java/android/widget/CalendarView.java b/core/java/android/widget/CalendarView.java
index 1b713c3786d4..9cbe8db412b1 100644
--- a/core/java/android/widget/CalendarView.java
+++ b/core/java/android/widget/CalendarView.java
@@ -339,10 +339,8 @@ public class CalendarView extends FrameLayout {
// initialization based on locale
setCurrentLocale(Locale.getDefault());
- TypedValue calendarViewStyle = new TypedValue();
- context.getTheme().resolveAttribute(R.attr.calendarViewStyle, calendarViewStyle, true);
- TypedArray attributesArray = context.obtainStyledAttributes(calendarViewStyle.resourceId,
- R.styleable.CalendarView);
+ TypedArray attributesArray = context.obtainStyledAttributes(attrs, R.styleable.CalendarView,
+ R.attr.calendarViewStyle, 0);
mShowWeekNumber = attributesArray.getBoolean(R.styleable.CalendarView_showWeekNumber,
DEFAULT_SHOW_WEEK_NUMBER);
mFirstDayOfWeek = attributesArray.getInt(R.styleable.CalendarView_firstDayOfWeek,
@@ -355,6 +353,9 @@ public class CalendarView extends FrameLayout {
if (TextUtils.isEmpty(maxDate) || !parseDate(maxDate, mMaxDate)) {
parseDate(DEFAULT_MAX_DATE, mMaxDate);
}
+ if (mMaxDate.before(mMinDate)) {
+ throw new IllegalArgumentException("Max date cannot be before min date.");
+ }
mShownWeekCount = attributesArray.getInt(R.styleable.CalendarView_shownWeekCount,
DEFAULT_SHOWN_WEEK_COUNT);
mSelectedWeekBackgroundColor = attributesArray.getColor(
@@ -407,9 +408,16 @@ public class CalendarView extends FrameLayout {
setUpListView();
setUpAdapter();
- // go to today now
+ // go to today or whichever is close to today min or max date
mTempDate.setTimeInMillis(System.currentTimeMillis());
- goTo(mTempDate, false, true, true);
+ if (mTempDate.before(mMinDate)) {
+ goTo(mMinDate, false, true, true);
+ } else if (mMaxDate.before(mTempDate)) {
+ goTo(mMaxDate, false, true, true);
+ } else {
+ goTo(mTempDate, false, true, true);
+ }
+
invalidate();
}