Java Code Examples for android.icu.util.Calendar#before()
The following examples show how to use
android.icu.util.Calendar#before() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CalendarViewLegacyDelegate.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public void setMinDate(long minDate) { mTempDate.setTimeInMillis(minDate); if (isSameDate(mTempDate, mMinDate)) { return; } mMinDate.setTimeInMillis(minDate); // make sure the current date is not earlier than // the new min date since the latter is used for // calculating the indices in the adapter thus // avoiding out of bounds error Calendar date = mAdapter.mSelectedDate; if (date.before(mMinDate)) { mAdapter.setSelectedDay(mMinDate); } // reinitialize the adapter since its range depends on min date mAdapter.init(); if (date.before(mMinDate)) { setDate(mTempDate.getTimeInMillis()); } else { // we go to the current date to force the ListView to query its // adapter for the shown views since we have changed the adapter // range and the base from which the later calculates item indices // note that calling setDate will not work since the date is the same goTo(date, false, true, false); } }
Example 2
Source File: CalendarViewLegacyDelegate.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * @return Returns the number of weeks between the current <code>date</code> * and the <code>mMinDate</code>. */ private int getWeeksSinceMinDate(Calendar date) { if (date.before(mMinDate)) { throw new IllegalArgumentException("fromDate: " + mMinDate.getTime() + " does not precede toDate: " + date.getTime()); } long endTimeMillis = date.getTimeInMillis() + date.getTimeZone().getOffset(date.getTimeInMillis()); long startTimeMillis = mMinDate.getTimeInMillis() + mMinDate.getTimeZone().getOffset(mMinDate.getTimeInMillis()); long dayOffsetMillis = (mMinDate.get(Calendar.DAY_OF_WEEK) - mFirstDayOfWeek) * MILLIS_IN_DAY; return (int) ((endTimeMillis - startTimeMillis + dayOffsetMillis) / MILLIS_IN_WEEK); }
Example 3
Source File: CalendarViewLegacyDelegate.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
/** * This moves to the specified time in the view. If the time is not already * in range it will move the list so that the first of the month containing * the time is at the top of the view. If the new time is already in view * the list will not be scrolled unless forceScroll is true. This time may * optionally be highlighted as selected as well. * * @param date The time to move to. * @param animate Whether to scroll to the given time or just redraw at the * new location. * @param setSelected Whether to set the given time as selected. * @param forceScroll Whether to recenter even if the time is already * visible. * * @throws IllegalArgumentException if the provided date is before the * range start or after the range end. */ private void goTo(Calendar date, boolean animate, boolean setSelected, boolean forceScroll) { if (date.before(mMinDate) || date.after(mMaxDate)) { throw new IllegalArgumentException("timeInMillis must be between the values of " + "getMinDate() and getMaxDate()"); } // Find the first and last entirely visible weeks int firstFullyVisiblePosition = mListView.getFirstVisiblePosition(); View firstChild = mListView.getChildAt(0); if (firstChild != null && firstChild.getTop() < 0) { firstFullyVisiblePosition++; } int lastFullyVisiblePosition = firstFullyVisiblePosition + mShownWeekCount - 1; if (firstChild != null && firstChild.getTop() > mBottomBuffer) { lastFullyVisiblePosition--; } if (setSelected) { mAdapter.setSelectedDay(date); } // Get the week we're going to int position = getWeeksSinceMinDate(date); // Check if the selected day is now outside of our visible range // and if so scroll to the month that contains it if (position < firstFullyVisiblePosition || position > lastFullyVisiblePosition || forceScroll) { mFirstDayOfMonth.setTimeInMillis(date.getTimeInMillis()); mFirstDayOfMonth.set(Calendar.DAY_OF_MONTH, 1); setMonthDisplayed(mFirstDayOfMonth); // the earliest time we can scroll to is the min date if (mFirstDayOfMonth.before(mMinDate)) { position = 0; } else { position = getWeeksSinceMinDate(mFirstDayOfMonth); } mPreviousScrollState = AbsListView.OnScrollListener.SCROLL_STATE_FLING; if (animate) { mListView.smoothScrollToPositionFromTop(position, mListScrollTopOffset, GOTO_SCROLL_DURATION); } else { mListView.setSelectionFromTop(position, mListScrollTopOffset); // Perform any after scroll operations that are needed onScrollStateChanged(mListView, AbsListView.OnScrollListener.SCROLL_STATE_IDLE); } } else if (setSelected) { // Otherwise just set the selection setMonthDisplayed(date); } }