Loading core/java/android/widget/DatePicker.java +39 −26 Original line number Diff line number Diff line Loading @@ -99,8 +99,8 @@ public class DatePicker extends FrameLayout { OnChangeListener onChangeListener = new OnChangeListener() { public void onChange(NumberPicker picker, int oldVal, int newVal) { notifyDateChanged(); updateMiniMonth(); updateDateUnchecked(mYearPicker.getCurrent(), mMonthPicker.getCurrent(), mDayPicker.getCurrent()); } }; Loading Loading @@ -135,7 +135,7 @@ public class DatePicker extends FrameLayout { mMiniMonthDayPicker.setRange(mTempCalendar, endRangeDate); mMiniMonthDayPicker.setOnDateChangeListener(new DayPicker.OnSelectedDayChangeListener() { public void onSelectedDayChange(DayPicker view, int year, int month, int monthDay) { updateDate(year, month, monthDay); updateDateUnchecked(year, month, monthDay); } }); Loading Loading @@ -238,26 +238,7 @@ public class DatePicker extends FrameLayout { if (mYearPicker.getCurrent() != year || mDayPicker.getCurrent() != dayOfMonth || mMonthPicker.getCurrent() != month) { updatePickers(year, month, dayOfMonth); updateMiniMonth(); notifyDateChanged(); } } /** * @return The short month abbreviations. */ private String[] getShortMonths() { final Locale currentLocale = Locale.getDefault(); if (currentLocale.equals(mMonthLocale)) { return mShortMonths; } else { for (int i = 0; i < mNumberOfMonths; i++) { mShortMonths[i] = DateUtils.getMonthString(Calendar.JANUARY + i, DateUtils.LENGTH_MEDIUM); } mMonthLocale = currentLocale; return mShortMonths; updateDateUnchecked(year, month, dayOfMonth); } } Loading Loading @@ -297,15 +278,47 @@ public class DatePicker extends FrameLayout { updateDate(year, monthOfYear, dayOfMonth); } /** * Updates the current date. * * @param year The year. * @param month The month which is <strong>starting from zero</strong>. * @param dayOfMonth The day of the month. */ private void updateDateUnchecked(int year, int month, int dayOfMonth) { updatePickers(year, month, dayOfMonth); updateMiniMonth(); notifyDateChanged(); } /** * @return The short month abbreviations. */ private String[] getShortMonths() { final Locale currentLocale = Locale.getDefault(); if (currentLocale.equals(mMonthLocale)) { return mShortMonths; } else { for (int i = 0; i < mNumberOfMonths; i++) { mShortMonths[i] = DateUtils.getMonthString(Calendar.JANUARY + i, DateUtils.LENGTH_MEDIUM); } mMonthLocale = currentLocale; return mShortMonths; } } /** * Updates the pickers with the given <code>year</code>, <code>month</code>, * and <code>dayOfMonth</code>. If the provided values designate an inconsistent * date the values are normalized before updating the pickers. */ private void updatePickers(int year, int month, int dayOfMonth) { // make sure the date is normalized mTempCalendar.clear(); mTempCalendar.set(year, month, dayOfMonth); // larger fields are not updated and the day is adjusted without wrapping mTempCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); mTempCalendar.roll(Calendar.MONTH, month - mTempCalendar.get(Calendar.MONTH)); mTempCalendar.roll(Calendar.YEAR, year - mTempCalendar.get(Calendar.YEAR)); mYearPicker.setCurrent(mTempCalendar.get(Calendar.YEAR)); mMonthPicker.setCurrent(mTempCalendar.get(Calendar.MONTH)); mDayPicker.setRange(1, mTempCalendar.getActualMaximum(Calendar.DAY_OF_MONTH)); Loading core/java/android/widget/DayPicker.java +34 −24 Original line number Diff line number Diff line Loading @@ -278,14 +278,14 @@ public class DayPicker extends FrameLayout { * * @hide */ protected Calendar mStartRangeDate = Calendar.getInstance(); protected Calendar mRangeStartDate = Calendar.getInstance(); /** * The end date of the range supported by this picker. * * @hide */ protected Calendar mEndRangeDate = Calendar.getInstance(); protected Calendar mRangeEndDate = Calendar.getInstance(); /** * String for formatting the month name in the title text view. Loading Loading @@ -341,10 +341,10 @@ public class DayPicker extends FrameLayout { } // set default range mStartRangeDate.clear(); mStartRangeDate.set(1900, 0, 1); mEndRangeDate.clear(); mEndRangeDate.set(2100, 0, 1); mRangeStartDate.clear(); mRangeStartDate.set(1900, 0, 1); mRangeEndDate.clear(); mRangeEndDate.set(2100, 0, 1); setUpHeader(); updateHeader(); Loading @@ -367,14 +367,16 @@ public class DayPicker extends FrameLayout { */ public void setRange(Calendar startRangeDate, Calendar endRangeDate) { boolean doSetupAdapter = false; if (mStartRangeDate.get(Calendar.DAY_OF_YEAR) != startRangeDate.get(Calendar.DAY_OF_YEAR) || mStartRangeDate.get(Calendar.YEAR) != startRangeDate.get(Calendar.YEAR)) { mStartRangeDate = startRangeDate; if (mRangeStartDate.get(Calendar.DAY_OF_YEAR) != startRangeDate.get(Calendar.DAY_OF_YEAR) || mRangeStartDate.get(Calendar.YEAR) != startRangeDate.get(Calendar.YEAR)) { mRangeStartDate.setTimeInMillis(startRangeDate.getTimeInMillis()); mRangeStartDate.setTimeZone(startRangeDate.getTimeZone()); doSetupAdapter = true; } if (mEndRangeDate.get(Calendar.DAY_OF_YEAR) != endRangeDate.get(Calendar.DAY_OF_YEAR) || mEndRangeDate.get(Calendar.YEAR) != endRangeDate.get(Calendar.YEAR)) { mEndRangeDate = endRangeDate; if (mRangeEndDate.get(Calendar.DAY_OF_YEAR) != endRangeDate.get(Calendar.DAY_OF_YEAR) || mRangeEndDate.get(Calendar.YEAR) != endRangeDate.get(Calendar.YEAR)) { mRangeEndDate.setTimeInMillis(endRangeDate.getTimeInMillis()); mRangeEndDate.setTimeZone(endRangeDate.getTimeZone()); doSetupAdapter = true; } Loading @@ -398,7 +400,7 @@ public class DayPicker extends FrameLayout { * @return The selected day. */ public Calendar getSelectedDay() { return mAdapter.mSelectedDay; return (Calendar) mAdapter.mSelectedDay.clone(); } /** Loading Loading @@ -524,6 +526,11 @@ public class DayPicker extends FrameLayout { * @param setSelected Whether to set the given time as selected * @param forceScroll Whether to recenter even if the time is already * visible. * * @throws IllegalArgumentException of the provided date is before the * range start of after the range end. * * @see #setRange(Calendar, Calendar) */ public void goTo(int year, int month, int dayOfMonth, boolean animate, boolean setSelected, boolean forceScroll) { Loading @@ -545,13 +552,16 @@ public class DayPicker extends FrameLayout { * @param setSelected Whether to set the given time as selected. * @param forceScroll Whether to recenter even if the time is already * visible. * * @throws IllegalArgumentException of the provided date is before the * range start of after the range end. * * @see #setRange(Calendar, Calendar) */ public void goTo(Calendar date, boolean animate, boolean setSelected, boolean forceScroll) { long timeInMillis = date.getTimeInMillis(); if (timeInMillis < mStartRangeDate.getTimeInMillis() || timeInMillis > mEndRangeDate.getTimeInMillis()) { throw new IllegalArgumentException("Time not between " + mStartRangeDate.getTime() + " and " + mEndRangeDate.getTime()); if (date.before(mRangeStartDate) || date.after(mRangeEndDate)) { throw new IllegalArgumentException("Time not between " + mRangeStartDate.getTime() + " and " + mRangeEndDate.getTime()); } // Find the first and last entirely visible weeks int firstFullyVisiblePosition = mListView.getFirstVisiblePosition(); Loading Loading @@ -698,16 +708,16 @@ public class DayPicker extends FrameLayout { * @hide */ protected int getWeeksDelta(Calendar toDate) { if (toDate.before(mStartRangeDate)) { throw new IllegalArgumentException("fromDate: " + mStartRangeDate.getTime() if (toDate.before(mRangeStartDate)) { throw new IllegalArgumentException("fromDate: " + mRangeStartDate.getTime() + " does not precede toDate: " + toDate.getTime()); } int fromDateDayOfWeek = mStartRangeDate.get(Calendar.DAY_OF_WEEK); int fromDateDayOfWeek = mRangeStartDate.get(Calendar.DAY_OF_WEEK); long diff = (fromDateDayOfWeek - toDate.getFirstDayOfWeek()) * MILLIS_IN_DAY; if (diff < 0) { diff = diff + MILLIS_IN_WEEK; } long refDay = mStartRangeDate.getTimeInMillis() - diff; long refDay = mRangeStartDate.getTimeInMillis() - diff; return (int) ((toDate.getTimeInMillis() - refDay) / MILLIS_IN_WEEK); } Loading Loading @@ -864,7 +874,7 @@ public class DayPicker extends FrameLayout { protected void init() { mGestureDetector = new GestureDetector(mContext, new CalendarGestureListener()); mSelectedWeek = getWeeksDelta(mSelectedDay); mTotalWeekCount = getWeeksDelta(mEndRangeDate); mTotalWeekCount = getWeeksDelta(mRangeEndDate); } /** Loading core/java/android/widget/NumberPicker.java +23 −5 Original line number Diff line number Diff line Loading @@ -843,6 +843,10 @@ public class NumberPicker extends LinearLayout { * @see #setWrapSelectorWheel(boolean) */ public void setRange(int start, int end, String[] displayedValues, boolean wrapSelectorWheel) { if (start == mStart && end == mEnd) { return; } if (start < 0 || end < 0) { throw new IllegalArgumentException("start and end must be > 0"); } Loading @@ -863,8 +867,7 @@ public class NumberPicker extends LinearLayout { mInputText.setRawInputType(InputType.TYPE_CLASS_NUMBER); } // make sure cached string representations are dropped mSelectorIndexToStringCache.clear(); resetSelectorIndices(); } /** Loading @@ -876,6 +879,9 @@ public class NumberPicker extends LinearLayout { * of the number picker. */ public void setCurrent(int current) { if (mCurrent == current) { return; } if (current < mStart || current > mEnd) { throw new IllegalArgumentException("current should be >= start and <= end"); } Loading Loading @@ -1010,6 +1016,18 @@ public class NumberPicker extends LinearLayout { } } /** * Resets the selector indices and clear the cached * string representation of these indices. */ private void resetSelectorIndices() { mSelectorIndexToStringCache.clear(); int[] selectorIdices = getSelectorIndices(); for (int i = 0; i < selectorIdices.length; i++) { selectorIdices[i] = Integer.MIN_VALUE; } } /** * Sets the current value of this NumberPicker, and sets mPrevious to the * previous value. If current is greater than mEnd less than mStart, the Loading Loading @@ -1177,9 +1195,9 @@ public class NumberPicker extends LinearLayout { */ private int getWrappedSelectorIndex(int selectorIndex) { if (selectorIndex > mEnd) { return (Math.abs(selectorIndex) - mEnd); return mStart + selectorIndex - mEnd - 1; } else if (selectorIndex < mStart) { return (mEnd - Math.abs(selectorIndex)); return mEnd + selectorIndex - mStart + 1; } return selectorIndex; } Loading Loading
core/java/android/widget/DatePicker.java +39 −26 Original line number Diff line number Diff line Loading @@ -99,8 +99,8 @@ public class DatePicker extends FrameLayout { OnChangeListener onChangeListener = new OnChangeListener() { public void onChange(NumberPicker picker, int oldVal, int newVal) { notifyDateChanged(); updateMiniMonth(); updateDateUnchecked(mYearPicker.getCurrent(), mMonthPicker.getCurrent(), mDayPicker.getCurrent()); } }; Loading Loading @@ -135,7 +135,7 @@ public class DatePicker extends FrameLayout { mMiniMonthDayPicker.setRange(mTempCalendar, endRangeDate); mMiniMonthDayPicker.setOnDateChangeListener(new DayPicker.OnSelectedDayChangeListener() { public void onSelectedDayChange(DayPicker view, int year, int month, int monthDay) { updateDate(year, month, monthDay); updateDateUnchecked(year, month, monthDay); } }); Loading Loading @@ -238,26 +238,7 @@ public class DatePicker extends FrameLayout { if (mYearPicker.getCurrent() != year || mDayPicker.getCurrent() != dayOfMonth || mMonthPicker.getCurrent() != month) { updatePickers(year, month, dayOfMonth); updateMiniMonth(); notifyDateChanged(); } } /** * @return The short month abbreviations. */ private String[] getShortMonths() { final Locale currentLocale = Locale.getDefault(); if (currentLocale.equals(mMonthLocale)) { return mShortMonths; } else { for (int i = 0; i < mNumberOfMonths; i++) { mShortMonths[i] = DateUtils.getMonthString(Calendar.JANUARY + i, DateUtils.LENGTH_MEDIUM); } mMonthLocale = currentLocale; return mShortMonths; updateDateUnchecked(year, month, dayOfMonth); } } Loading Loading @@ -297,15 +278,47 @@ public class DatePicker extends FrameLayout { updateDate(year, monthOfYear, dayOfMonth); } /** * Updates the current date. * * @param year The year. * @param month The month which is <strong>starting from zero</strong>. * @param dayOfMonth The day of the month. */ private void updateDateUnchecked(int year, int month, int dayOfMonth) { updatePickers(year, month, dayOfMonth); updateMiniMonth(); notifyDateChanged(); } /** * @return The short month abbreviations. */ private String[] getShortMonths() { final Locale currentLocale = Locale.getDefault(); if (currentLocale.equals(mMonthLocale)) { return mShortMonths; } else { for (int i = 0; i < mNumberOfMonths; i++) { mShortMonths[i] = DateUtils.getMonthString(Calendar.JANUARY + i, DateUtils.LENGTH_MEDIUM); } mMonthLocale = currentLocale; return mShortMonths; } } /** * Updates the pickers with the given <code>year</code>, <code>month</code>, * and <code>dayOfMonth</code>. If the provided values designate an inconsistent * date the values are normalized before updating the pickers. */ private void updatePickers(int year, int month, int dayOfMonth) { // make sure the date is normalized mTempCalendar.clear(); mTempCalendar.set(year, month, dayOfMonth); // larger fields are not updated and the day is adjusted without wrapping mTempCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); mTempCalendar.roll(Calendar.MONTH, month - mTempCalendar.get(Calendar.MONTH)); mTempCalendar.roll(Calendar.YEAR, year - mTempCalendar.get(Calendar.YEAR)); mYearPicker.setCurrent(mTempCalendar.get(Calendar.YEAR)); mMonthPicker.setCurrent(mTempCalendar.get(Calendar.MONTH)); mDayPicker.setRange(1, mTempCalendar.getActualMaximum(Calendar.DAY_OF_MONTH)); Loading
core/java/android/widget/DayPicker.java +34 −24 Original line number Diff line number Diff line Loading @@ -278,14 +278,14 @@ public class DayPicker extends FrameLayout { * * @hide */ protected Calendar mStartRangeDate = Calendar.getInstance(); protected Calendar mRangeStartDate = Calendar.getInstance(); /** * The end date of the range supported by this picker. * * @hide */ protected Calendar mEndRangeDate = Calendar.getInstance(); protected Calendar mRangeEndDate = Calendar.getInstance(); /** * String for formatting the month name in the title text view. Loading Loading @@ -341,10 +341,10 @@ public class DayPicker extends FrameLayout { } // set default range mStartRangeDate.clear(); mStartRangeDate.set(1900, 0, 1); mEndRangeDate.clear(); mEndRangeDate.set(2100, 0, 1); mRangeStartDate.clear(); mRangeStartDate.set(1900, 0, 1); mRangeEndDate.clear(); mRangeEndDate.set(2100, 0, 1); setUpHeader(); updateHeader(); Loading @@ -367,14 +367,16 @@ public class DayPicker extends FrameLayout { */ public void setRange(Calendar startRangeDate, Calendar endRangeDate) { boolean doSetupAdapter = false; if (mStartRangeDate.get(Calendar.DAY_OF_YEAR) != startRangeDate.get(Calendar.DAY_OF_YEAR) || mStartRangeDate.get(Calendar.YEAR) != startRangeDate.get(Calendar.YEAR)) { mStartRangeDate = startRangeDate; if (mRangeStartDate.get(Calendar.DAY_OF_YEAR) != startRangeDate.get(Calendar.DAY_OF_YEAR) || mRangeStartDate.get(Calendar.YEAR) != startRangeDate.get(Calendar.YEAR)) { mRangeStartDate.setTimeInMillis(startRangeDate.getTimeInMillis()); mRangeStartDate.setTimeZone(startRangeDate.getTimeZone()); doSetupAdapter = true; } if (mEndRangeDate.get(Calendar.DAY_OF_YEAR) != endRangeDate.get(Calendar.DAY_OF_YEAR) || mEndRangeDate.get(Calendar.YEAR) != endRangeDate.get(Calendar.YEAR)) { mEndRangeDate = endRangeDate; if (mRangeEndDate.get(Calendar.DAY_OF_YEAR) != endRangeDate.get(Calendar.DAY_OF_YEAR) || mRangeEndDate.get(Calendar.YEAR) != endRangeDate.get(Calendar.YEAR)) { mRangeEndDate.setTimeInMillis(endRangeDate.getTimeInMillis()); mRangeEndDate.setTimeZone(endRangeDate.getTimeZone()); doSetupAdapter = true; } Loading @@ -398,7 +400,7 @@ public class DayPicker extends FrameLayout { * @return The selected day. */ public Calendar getSelectedDay() { return mAdapter.mSelectedDay; return (Calendar) mAdapter.mSelectedDay.clone(); } /** Loading Loading @@ -524,6 +526,11 @@ public class DayPicker extends FrameLayout { * @param setSelected Whether to set the given time as selected * @param forceScroll Whether to recenter even if the time is already * visible. * * @throws IllegalArgumentException of the provided date is before the * range start of after the range end. * * @see #setRange(Calendar, Calendar) */ public void goTo(int year, int month, int dayOfMonth, boolean animate, boolean setSelected, boolean forceScroll) { Loading @@ -545,13 +552,16 @@ public class DayPicker extends FrameLayout { * @param setSelected Whether to set the given time as selected. * @param forceScroll Whether to recenter even if the time is already * visible. * * @throws IllegalArgumentException of the provided date is before the * range start of after the range end. * * @see #setRange(Calendar, Calendar) */ public void goTo(Calendar date, boolean animate, boolean setSelected, boolean forceScroll) { long timeInMillis = date.getTimeInMillis(); if (timeInMillis < mStartRangeDate.getTimeInMillis() || timeInMillis > mEndRangeDate.getTimeInMillis()) { throw new IllegalArgumentException("Time not between " + mStartRangeDate.getTime() + " and " + mEndRangeDate.getTime()); if (date.before(mRangeStartDate) || date.after(mRangeEndDate)) { throw new IllegalArgumentException("Time not between " + mRangeStartDate.getTime() + " and " + mRangeEndDate.getTime()); } // Find the first and last entirely visible weeks int firstFullyVisiblePosition = mListView.getFirstVisiblePosition(); Loading Loading @@ -698,16 +708,16 @@ public class DayPicker extends FrameLayout { * @hide */ protected int getWeeksDelta(Calendar toDate) { if (toDate.before(mStartRangeDate)) { throw new IllegalArgumentException("fromDate: " + mStartRangeDate.getTime() if (toDate.before(mRangeStartDate)) { throw new IllegalArgumentException("fromDate: " + mRangeStartDate.getTime() + " does not precede toDate: " + toDate.getTime()); } int fromDateDayOfWeek = mStartRangeDate.get(Calendar.DAY_OF_WEEK); int fromDateDayOfWeek = mRangeStartDate.get(Calendar.DAY_OF_WEEK); long diff = (fromDateDayOfWeek - toDate.getFirstDayOfWeek()) * MILLIS_IN_DAY; if (diff < 0) { diff = diff + MILLIS_IN_WEEK; } long refDay = mStartRangeDate.getTimeInMillis() - diff; long refDay = mRangeStartDate.getTimeInMillis() - diff; return (int) ((toDate.getTimeInMillis() - refDay) / MILLIS_IN_WEEK); } Loading Loading @@ -864,7 +874,7 @@ public class DayPicker extends FrameLayout { protected void init() { mGestureDetector = new GestureDetector(mContext, new CalendarGestureListener()); mSelectedWeek = getWeeksDelta(mSelectedDay); mTotalWeekCount = getWeeksDelta(mEndRangeDate); mTotalWeekCount = getWeeksDelta(mRangeEndDate); } /** Loading
core/java/android/widget/NumberPicker.java +23 −5 Original line number Diff line number Diff line Loading @@ -843,6 +843,10 @@ public class NumberPicker extends LinearLayout { * @see #setWrapSelectorWheel(boolean) */ public void setRange(int start, int end, String[] displayedValues, boolean wrapSelectorWheel) { if (start == mStart && end == mEnd) { return; } if (start < 0 || end < 0) { throw new IllegalArgumentException("start and end must be > 0"); } Loading @@ -863,8 +867,7 @@ public class NumberPicker extends LinearLayout { mInputText.setRawInputType(InputType.TYPE_CLASS_NUMBER); } // make sure cached string representations are dropped mSelectorIndexToStringCache.clear(); resetSelectorIndices(); } /** Loading @@ -876,6 +879,9 @@ public class NumberPicker extends LinearLayout { * of the number picker. */ public void setCurrent(int current) { if (mCurrent == current) { return; } if (current < mStart || current > mEnd) { throw new IllegalArgumentException("current should be >= start and <= end"); } Loading Loading @@ -1010,6 +1016,18 @@ public class NumberPicker extends LinearLayout { } } /** * Resets the selector indices and clear the cached * string representation of these indices. */ private void resetSelectorIndices() { mSelectorIndexToStringCache.clear(); int[] selectorIdices = getSelectorIndices(); for (int i = 0; i < selectorIdices.length; i++) { selectorIdices[i] = Integer.MIN_VALUE; } } /** * Sets the current value of this NumberPicker, and sets mPrevious to the * previous value. If current is greater than mEnd less than mStart, the Loading Loading @@ -1177,9 +1195,9 @@ public class NumberPicker extends LinearLayout { */ private int getWrappedSelectorIndex(int selectorIndex) { if (selectorIndex > mEnd) { return (Math.abs(selectorIndex) - mEnd); return mStart + selectorIndex - mEnd - 1; } else if (selectorIndex < mStart) { return (mEnd - Math.abs(selectorIndex)); return mEnd + selectorIndex - mStart + 1; } return selectorIndex; } Loading