Skip to content

Commit 09f9bde

Browse files
author
Jens Claes
committed
Merge branch 'pr-275' into develop
2 parents 0af2288 + 27d70f9 commit 09f9bde

File tree

2 files changed

+34
-26
lines changed

2 files changed

+34
-26
lines changed

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

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -496,37 +496,15 @@ protected void onDraw(Canvas canvas) {
496496
drawTimeColumnAndAxes(canvas);
497497
}
498498

499-
private void drawTimeColumnAndAxes(Canvas canvas) {
500-
// Draw the background color for the header column.
501-
canvas.drawRect(0, mHeaderHeight + mHeaderRowPadding * 2, mHeaderColumnWidth, getHeight(), mHeaderColumnBackgroundPaint);
502-
503-
// Clip to paint in left column only.
504-
canvas.clipRect(0, mHeaderHeight + mHeaderRowPadding * 2, mHeaderColumnWidth, getHeight(), Region.Op.REPLACE);
505-
506-
for (int i = 0; i < 24; i++) {
507-
float top = mHeaderHeight + mHeaderRowPadding * 2 + mCurrentOrigin.y + mHourHeight * i + mHeaderMarginBottom;
508-
509-
// 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.
510-
String time = getDateTimeInterpreter().interpretTime(i);
511-
if (time == null)
512-
throw new IllegalStateException("A DateTimeInterpreter must not return null time");
513-
if (top < getHeight()) canvas.drawText(time, mTimeTextWidth + mHeaderColumnPadding, top + mTimeTextHeight, mTimeTextPaint);
514-
}
515-
}
516-
517-
private void drawHeaderRowAndEvents(Canvas canvas) {
518-
// Calculate the available width for each day.
519-
mHeaderColumnWidth = mTimeTextWidth + mHeaderColumnPadding *2;
520-
mWidthPerDay = getWidth() - mHeaderColumnWidth - mColumnGap * (mNumberOfVisibleDays - 1);
521-
mWidthPerDay = mWidthPerDay/mNumberOfVisibleDays;
499+
private void calculateHeaderHeight(){
500+
//Make sure the header is the right size (depends on AllDay events)
522501
boolean containsAllDayEvent = false;
523502
if (mEventRects != null && mEventRects.size() > 0) {
524503
for (int dayNumber = 0;
525504
dayNumber < mNumberOfVisibleDays;
526505
dayNumber++) {
527506
Calendar day = (Calendar) getFirstVisibleDay().clone();
528507
day.add(Calendar.DATE, dayNumber);
529-
int amountOfAllDayEvents=0;
530508
for (int i = 0; i < mEventRects.size(); i++) {
531509

532510
if (isSameDay(mEventRects.get(i).event.getStartTime(), day) && mEventRects.get(i).event.isAllDay()) {
@@ -545,6 +523,34 @@ private void drawHeaderRowAndEvents(Canvas canvas) {
545523
else{
546524
mHeaderHeight = mHeaderTextHeight;
547525
}
526+
}
527+
528+
private void drawTimeColumnAndAxes(Canvas canvas) {
529+
// Draw the background color for the header column.
530+
canvas.drawRect(0, mHeaderHeight + mHeaderRowPadding * 2, mHeaderColumnWidth, getHeight(), mHeaderColumnBackgroundPaint);
531+
532+
// Clip to paint in left column only.
533+
canvas.clipRect(0, mHeaderHeight + mHeaderRowPadding * 2, mHeaderColumnWidth, getHeight(), Region.Op.REPLACE);
534+
535+
for (int i = 0; i < 24; i++) {
536+
float top = mHeaderHeight + mHeaderRowPadding * 2 + mCurrentOrigin.y + mHourHeight * i + mHeaderMarginBottom;
537+
538+
// 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.
539+
String time = getDateTimeInterpreter().interpretTime(i);
540+
if (time == null)
541+
throw new IllegalStateException("A DateTimeInterpreter must not return null time");
542+
if (top < getHeight()) canvas.drawText(time, mTimeTextWidth + mHeaderColumnPadding, top + mTimeTextHeight, mTimeTextPaint);
543+
}
544+
}
545+
546+
private void drawHeaderRowAndEvents(Canvas canvas) {
547+
// Calculate the available width for each day.
548+
mHeaderColumnWidth = mTimeTextWidth + mHeaderColumnPadding *2;
549+
mWidthPerDay = getWidth() - mHeaderColumnWidth - mColumnGap * (mNumberOfVisibleDays - 1);
550+
mWidthPerDay = mWidthPerDay/mNumberOfVisibleDays;
551+
552+
calculateHeaderHeight(); //Make sure the header is the right size (depends on AllDay events)
553+
548554
Calendar today = today();
549555

550556
if (mAreDimensionsInvalid) {
@@ -1000,6 +1006,7 @@ else if (periodToFetch == mFetchedPeriod+1){
10001006
sortAndCacheEvents(previousPeriodEvents);
10011007
sortAndCacheEvents(currentPeriodEvents);
10021008
sortAndCacheEvents(nextPeriodEvents);
1009+
calculateHeaderHeight();
10031010

10041011
mPreviousPeriodEvents = previousPeriodEvents;
10051012
mCurrentPeriodEvents = currentPeriodEvents;
@@ -1124,16 +1131,18 @@ private void computePositionOfEvents(List<EventRect> eventRects) {
11241131
List<List<EventRect>> collisionGroups = new ArrayList<List<EventRect>>();
11251132
for (EventRect eventRect : eventRects) {
11261133
boolean isPlaced = false;
1134+
11271135
outerLoop:
11281136
for (List<EventRect> collisionGroup : collisionGroups) {
11291137
for (EventRect groupEvent : collisionGroup) {
1130-
if (isEventsCollide(groupEvent.event, eventRect.event)) {
1138+
if (isEventsCollide(groupEvent.event, eventRect.event) && groupEvent.event.isAllDay() == eventRect.event.isAllDay()) {
11311139
collisionGroup.add(eventRect);
11321140
isPlaced = true;
11331141
break outerLoop;
11341142
}
11351143
}
11361144
}
1145+
11371146
if (!isPlaced) {
11381147
List<EventRect> newGroup = new ArrayList<EventRect>();
11391148
newGroup.add(eventRect);

sample/src/main/java/com/alamkanak/weekview/sample/BasicActivity.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ public List<? extends WeekViewEvent> onMonthChange(int newYear, int newMonth) {
118118

119119
//AllDay event
120120
startTime = Calendar.getInstance();
121-
startTime.set(Calendar.DAY_OF_MONTH, 6);
122121
startTime.set(Calendar.HOUR_OF_DAY, 0);
123122
startTime.set(Calendar.MINUTE, 0);
124123
startTime.set(Calendar.MONTH, newMonth-1);

0 commit comments

Comments
 (0)