Kotlin to Java Code Conversion: Drawing Header Row and Events in WeekView
private void drawHeaderRowAndEvents(Canvas canvas) {
widthPerDay = (width - mHeaderColumnWidth - (columnGap * (realNumberOfVisibleDays - 1))) / realNumberOfVisibleDays;
calculateHeaderHeight();
if (mAreDimensionsInvalid) {
mEffectiveMinHourHeight = Math.max(minHourHeight, ((height - headerHeight - weekDaysHeaderRowTotalPadding - spaceBelowAllDayEvents) / (mMaxTime - mMinTime)));
mAreDimensionsInvalid = false;
if (mScrollToDay != null)
goToDate(mScrollToDay);
mAreDimensionsInvalid = false;
if (mScrollToHour >= 0)
goToHour(mScrollToHour);
mScrollToDay = null;
mScrollToHour = -1.0;
mAreDimensionsInvalid = false;
}
if (mIsFirstDraw) {
mIsFirstDraw = false;
if (realNumberOfVisibleDays >= 7 && mHomeDate.get(Calendar.DAY_OF_WEEK) != firstDayOfWeek && isShowFirstDayOfWeekFirst) {
int difference = mHomeDate.get(Calendar.DAY_OF_WEEK) - firstDayOfWeek;
mCurrentOrigin.x += (widthPerDay + columnGap) * difference;
}
setLimitTime(mMinTime, mMaxTime);
}
if (mNewHourHeight > 0) {
if (mNewHourHeight < mEffectiveMinHourHeight)
mNewHourHeight = mEffectiveMinHourHeight;
else if (mNewHourHeight > maxHourHeight)
mNewHourHeight = maxHourHeight;
hourHeight = mNewHourHeight;
mNewHourHeight = -1;
}
mCurrentOrigin.y = Math.min(0, Math.max(mCurrentOrigin.y,
height - (hourHeight * (mMaxTime - mMinTime)) - headerHeight - weekDaysHeaderRowTotalPadding - spaceBelowAllDayEvents - timeTextHeight / 2));
int leftDaysWithGaps = leftDaysWithGaps();
int startFromPixel = xStartPixel();
int startPixel = startFromPixel;
int lineCount = ((height - headerHeight - weekDaysHeaderRowTotalPadding - spaceBelowAllDayEvents) / hourHeight) + 1;
lineCount *= (realNumberOfVisibleDays + 1);
float[] hourLines = new float[lineCount * 4];
if (eventRects != null) {
for (EventRect eventRect : eventRects) {
eventRect.rectF = null;
}
}
canvas.save();
canvas.clipRect(mHeaderColumnWidth, headerHeight + weekDaysHeaderRowTotalPadding + spaceBelowAllDayEvents + timeTextHeight / 2, width, height);
Calendar oldFirstVisibleDay = firstVisibleDay;
firstVisibleDay = (Calendar) mHomeDate.clone();
firstVisibleDay.add(Calendar.DATE, -Math.round(mCurrentOrigin.x / (widthPerDay + columnGap)));
if (oldFirstVisibleDay == null || !WeekViewUtil.isSameDay(firstVisibleDay, oldFirstVisibleDay)) {
scrollListener.onFirstVisibleDayChanged(firstVisibleDay, oldFirstVisibleDay);
}
if (autoLimitTime) {
ArrayList<Calendar> days = new ArrayList<>();
for (int dayNumber = leftDaysWithGaps + 1; dayNumber <= leftDaysWithGaps + realNumberOfVisibleDays; dayNumber++) {
Calendar day = (Calendar) mHomeDate.clone();
day.add(Calendar.DATE, dayNumber - 1
This code snippet represents the Java conversion of the provided Kotlin function. It illustrates how to translate Kotlin's concise syntax and features into equivalent Java code, ensuring readability and maintainability. The core logic and functionality are preserved in the Java version, adhering to Java's syntax and conventions.
This conversion showcases the flexibility and interchangeability of Kotlin and Java in Android development, allowing developers to leverage their strengths and preferences while achieving the desired results.
Please note that this is a partial conversion of the Kotlin code. The entire code is not provided due to its substantial length. However, the provided section illustrates the process of converting Kotlin to Java, making it easier to understand the principles involved in such conversions.
原文地址: https://www.cveoy.top/t/topic/ftss 著作权归作者所有。请勿转载和采集!