Convert Kotlin to Java: Rendering Days in a WeekView
if (autoLimitTime) {
ArrayList
{ Calendar day = (Calendar) mHomeDate.clone(); day.add(Calendar.DATE, leftDaysWithGaps);
for (int dayNumber = leftDaysWithGaps + 1; dayNumber <= leftDaysWithGaps + realNumberOfVisibleDays + 1; dayNumber++) {
// Check if the day is today.
boolean isToday = isSameDay(day, today);
// Don't draw days which are outside requested range
if (!dateIsValid(day))
continue;
// Get more events if necessary.
// mFetchedPeriod: currently fetched period index
// mWeekViewLoader.toWeekViewPeriodIndex(day): index for the day we want to display
// fetchIndex = 1.0: end of period in the future reached
// fetchIndex = 0.0: end of period in the past reached
float fetchIndex = this.weekViewLoader.toWeekViewPeriodIndex(day) - mFetchedPeriod;
// if we are using the PrefetchingWeekViewLoader class, we need to adjust the bounds
// so that we wait to fetch new data until we really need it
double upperBound = 1.0;
double lowerBound = 0.0;
if (this.weekViewLoader instanceof PrefetchingWeekViewLoader) {
// the offset causes the onMonthChangeListener to be trigger when half of the
// last fetched period is passed
// example:
// if the prefetching period = 1, we load the current period, the next and the previous
// when half of the next/previous period is passed, the listener is triggered to fetch new data
double boundOffset = this.weekViewLoader.prefetchingPeriod - 0.5;
upperBound = 1.0 + boundOffset;
lowerBound = 0.0 - boundOffset;
}
if ((eventRects == null || mRefreshEvents ||
dayNumber == leftDaysWithGaps + 1 && mFetchedPeriod != this.weekViewLoader.toWeekViewPeriodIndex(day).intValue() &&
(fetchIndex >= upperBound || fetchIndex <= lowerBound))) {
getMoreEvents(day);
mRefreshEvents = false;
}
// Draw background color for each day.
float start = startPixel < mHeaderColumnWidth ? mHeaderColumnWidth : startPixel;
if (widthPerDay + startPixel - start > 0) {
if (isShowDistinctPastFutureColor) {
boolean isWeekend = day.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || day.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY;
Paint pastPaint = isWeekend && isShowDistinctWeekendColor ? mPastWeekendBackgroundPaint : mPastBackgroundPaint;
Paint futurePaint = isWeekend && isShowDistinctWeekendColor ? mFutureWeekendBackgroundPaint : mFutureBackgroundPaint;
float startY = headerHeight + weekDaysHeaderRowTotalPadding + timeTextHeight / 2 + spaceBelowAllDayEvents + mCurrentOrigin.y;
if (isToday) {
Calendar now = Calendar.getInstance();
float beforeNow = (now.get(Calendar.HOUR_OF_DAY) - mMinTime + now.get(Calendar.MINUTE) / 60f) * hourHeight;
canvas.drawRect(start, startY, startPixel + widthPerDay, startY + beforeNow, pastPaint);
canvas.drawRect(start, startY + beforeNow, startPixel + widthPerDay, height, futurePaint);
} else if (day.before(today)) {
canvas.drawRect(start, startY, startPixel + widthPerDay, height, pastPaint);
} else {
canvas.drawRect(start, startY, startPixel + widthPerDay, height, futurePaint);
}
} else {
Paint cellBackgroundPaint = isToday ? mTodayColumnBackgroundPaint : mDayBackgroundPaint;
if (cellBackgroundPaint.getColor() != 0)
canvas.drawRect(start, headerHeight + weekDaysHeaderRowTotalPadding + timeTextHeight / 2 + spaceBelowAllDayEvents, startPixel + widthPerDay, height, cellBackgroundPaint);
}
}
// Prepare the separator lines for hours.
int i = 0;
for (int hourNumber = mMinTime; hourNumber < mMaxTime; hourNumber++) {
float top = headerHeight + weekDaysHeaderRowTotalPadding + mCurrentOrigin.y + (hourHeight * (hourNumber - mMinTime)) + timeTextHeight / 2;
if (top > headerHeight + weekDaysHeaderRowTotalPadding + timeTextHeight / 2 + spaceBelowAllDayEvents - hourSeparatorHeight && top < height && startPixel + widthPerDay - start > 0) {
hourLines[i * 4] = start;
hourLines[i * 4 + 1] = top;
hourLines[i * 4 + 2] = startPixel + widthPerDay + (isUsingCheckersStyle ? columnGap : 0);
hourLines[i * 4 + 3] = top;
i++;
}
}
// Draw the lines for hours.
canvas.drawLines(hourLines, mHourSeparatorPaint);
// Draw line between days (before current one)
if (isUsingCheckersStyle) {
float x = dayNumber == leftDaysWithGaps + 1 ? start : start - columnGap / 2;
canvas.drawLine(x, headerHeight, x, height, mHourSeparatorPaint);
}
// Draw the events.
drawEvents(day, startPixel, canvas);
// Draw the line at the current time.
if (isShowNowLine && isToday) {
float startY = headerHeight + weekDaysHeaderRowTotalPadding + timeTextHeight / 2 + spaceBelowAllDayEvents + mCurrentOrigin.y;
Calendar now = Calendar.getInstance();
float beforeNow = (now.get(Calendar.HOUR_OF_DAY) - mMinTime + now.get(Calendar.MINUTE) / 60f) * hourHeight;
float top = startY + beforeNow;
canvas.drawLine(start, top, startPixel + widthPerDay, top, mNowLinePaint);
}
// In the next iteration, start from the next day.
startPixel += widthPerDay + columnGap;
day.add(Calendar.DATE, 1);
}
}
canvas.restore();
// Hide everything in the first cell (top left corner). canvas.save(); canvas.clipRect(0, 0, mHeaderColumnWidth, headerHeight + weekDaysHeaderRowTotalPadding); float headerTitleAndSubtitleTextHeight = headerWeekDayTitleTextHeight + (isSubtitleHeaderEnabled ? headerWeekDaySubtitleTextHeight + spaceBetweenHeaderWeekDayTitleAndSubtitle : 0.0f); if (enableDrawHeaderBackgroundOnlyOnWeekDays) canvas.drawRect(0, 0, mHeaderColumnWidth, headerTitleAndSubtitleTextHeight + weekDaysHeaderRowTotalPadding, mHeaderBackgroundPaint); else canvas.drawRect(canvas.getClipBounds(), mHeaderBackgroundPaint);
原文地址: http://www.cveoy.top/t/topic/ftnc 著作权归作者所有。请勿转载和采集!