Skip to content

Commit 27d70f9

Browse files
author
Jesse Hoobergs
committed
Fixed HeaderHeight for real
1 parent a389048 commit 27d70f9

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

library/src/main/java/com/alamkanak/weekview/WeekView.java

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -494,29 +494,8 @@ protected void onDraw(Canvas canvas) {
494494
drawTimeColumnAndAxes(canvas);
495495
}
496496

497-
private void drawTimeColumnAndAxes(Canvas canvas) {
498-
// Draw the background color for the header column.
499-
canvas.drawRect(0, mHeaderHeight + mHeaderRowPadding * 2, mHeaderColumnWidth, getHeight(), mHeaderColumnBackgroundPaint);
500-
501-
// Clip to paint in left column only.
502-
canvas.clipRect(0, mHeaderHeight + mHeaderRowPadding * 2, mHeaderColumnWidth, getHeight(), Region.Op.REPLACE);
503-
504-
for (int i = 0; i < 24; i++) {
505-
float top = mHeaderHeight + mHeaderRowPadding * 2 + mCurrentOrigin.y + mHourHeight * i + mHeaderMarginBottom;
506-
507-
// Draw the text if its y position is not outside of the visible area. The pivot point of the text is the point at the bottom-right corner.
508-
String time = getDateTimeInterpreter().interpretTime(i);
509-
if (time == null)
510-
throw new IllegalStateException("A DateTimeInterpreter must not return null time");
511-
if (top < getHeight()) canvas.drawText(time, mTimeTextWidth + mHeaderColumnPadding, top + mTimeTextHeight, mTimeTextPaint);
512-
}
513-
}
514-
515-
private void drawHeaderRowAndEvents(Canvas canvas) {
516-
// Calculate the available width for each day.
517-
mHeaderColumnWidth = mTimeTextWidth + mHeaderColumnPadding *2;
518-
mWidthPerDay = getWidth() - mHeaderColumnWidth - mColumnGap * (mNumberOfVisibleDays - 1);
519-
mWidthPerDay = mWidthPerDay/mNumberOfVisibleDays;
497+
private void calculateHeaderHeight(){
498+
//Make sure the header is the right size (depends on AllDay events)
520499
boolean containsAllDayEvent = false;
521500
if (mEventRects != null && mEventRects.size() > 0) {
522501
for (int dayNumber = 0;
@@ -536,17 +515,39 @@ private void drawHeaderRowAndEvents(Canvas canvas) {
536515
}
537516
}
538517
}
539-
float newHeaderHeight;
540518
if(containsAllDayEvent) {
541-
newHeaderHeight = mHeaderTextHeight + (mAllDayEventHeight + mHeaderMarginBottom);
519+
mHeaderHeight = mHeaderTextHeight + (mAllDayEventHeight + mHeaderMarginBottom);
542520
}
543521
else{
544-
newHeaderHeight = mHeaderTextHeight;
522+
mHeaderHeight = mHeaderTextHeight;
545523
}
546-
if(newHeaderHeight!=mHeaderHeight){
547-
mHeaderHeight = newHeaderHeight;
548-
postInvalidate();
524+
}
525+
526+
private void drawTimeColumnAndAxes(Canvas canvas) {
527+
// Draw the background color for the header column.
528+
canvas.drawRect(0, mHeaderHeight + mHeaderRowPadding * 2, mHeaderColumnWidth, getHeight(), mHeaderColumnBackgroundPaint);
529+
530+
// Clip to paint in left column only.
531+
canvas.clipRect(0, mHeaderHeight + mHeaderRowPadding * 2, mHeaderColumnWidth, getHeight(), Region.Op.REPLACE);
532+
533+
for (int i = 0; i < 24; i++) {
534+
float top = mHeaderHeight + mHeaderRowPadding * 2 + mCurrentOrigin.y + mHourHeight * i + mHeaderMarginBottom;
535+
536+
// Draw the text if its y position is not outside of the visible area. The pivot point of the text is the point at the bottom-right corner.
537+
String time = getDateTimeInterpreter().interpretTime(i);
538+
if (time == null)
539+
throw new IllegalStateException("A DateTimeInterpreter must not return null time");
540+
if (top < getHeight()) canvas.drawText(time, mTimeTextWidth + mHeaderColumnPadding, top + mTimeTextHeight, mTimeTextPaint);
549541
}
542+
}
543+
544+
private void drawHeaderRowAndEvents(Canvas canvas) {
545+
// Calculate the available width for each day.
546+
mHeaderColumnWidth = mTimeTextWidth + mHeaderColumnPadding *2;
547+
mWidthPerDay = getWidth() - mHeaderColumnWidth - mColumnGap * (mNumberOfVisibleDays - 1);
548+
mWidthPerDay = mWidthPerDay/mNumberOfVisibleDays;
549+
550+
calculateHeaderHeight(); //Make sure the header is the right size (depends on AllDay events)
550551

551552
Calendar today = today();
552553

@@ -1003,6 +1004,7 @@ else if (periodToFetch == mFetchedPeriod+1){
10031004
sortAndCacheEvents(previousPeriodEvents);
10041005
sortAndCacheEvents(currentPeriodEvents);
10051006
sortAndCacheEvents(nextPeriodEvents);
1007+
calculateHeaderHeight();
10061008

10071009
mPreviousPeriodEvents = previousPeriodEvents;
10081010
mCurrentPeriodEvents = currentPeriodEvents;

0 commit comments

Comments
 (0)