Skip to content

Commit 574fe9e

Browse files
committed
Some clean ups
1 parent 3088b39 commit 574fe9e

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ private void drawHeaderRowAndEvents(Canvas canvas) {
373373
}
374374
}
375375

376+
// Iterate through each day.
376377
for (int dayNumber = leftDaysWithGaps + 1;
377378
dayNumber <= leftDaysWithGaps + mNumberOfVisibleDays + 1;
378379
dayNumber++) {
@@ -405,11 +406,14 @@ private void drawHeaderRowAndEvents(Canvas canvas) {
405406
i++;
406407
}
407408
}
409+
410+
// Draw the lines for hours.
408411
canvas.drawLines(hourLines, mHourSeparatorPaint);
409412

410413
// Draw the events.
411414
drawEvents(day, startPixel, canvas);
412415

416+
// In the next iteration, start from the next day.
413417
startPixel += mWidthPerDay + mColumnGap;
414418
}
415419

@@ -440,8 +444,6 @@ private void drawHeaderRowAndEvents(Canvas canvas) {
440444
*/
441445
private void drawEvents(Calendar date, float startFromPixel, Canvas canvas) {
442446
if (mEventRects != null && mEventRects.size() > 0) {
443-
444-
445447
for (int i = 0; i < mEventRects.size(); i++) {
446448
if (isSameDay(mEventRects.get(i).event.getStartTime(), date)) {
447449

@@ -460,6 +462,7 @@ private void drawEvents(Calendar date, float startFromPixel, Canvas canvas) {
460462
float right = startFromPixel + mWidthPerDay;
461463
if (left < mHeaderColumnWidth) left = mHeaderColumnWidth;
462464

465+
// Draw the event and the event name on top of it.
463466
RectF eventRectF = new RectF(left, top, right, bottom);
464467
if (bottom > mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight/2 && left < right &&
465468
eventRectF.right > mHeaderColumnWidth &&
@@ -469,7 +472,6 @@ eventRectF.top < getHeight() &&
469472
left < right
470473
) {
471474
mEventRects.get(i).rectF = eventRectF;
472-
473475
mEventBackgroundPaint.setColor(mEventRects.get(i).event.getColor() == 0 ? mDefaultEventColor : mEventRects.get(i).event.getColor());
474476
canvas.drawRect(mEventRects.get(i).rectF, mEventBackgroundPaint);
475477
drawText(mEventRects.get(i).event.getName(), mEventRects.get(i).rectF, canvas, originalTop, startFromPixel);
@@ -515,7 +517,6 @@ else if (lineHeight >= availableHeight) {
515517
mTextLayout.draw(canvas);
516518
canvas.restore();
517519

518-
519520
}
520521

521522

@@ -541,7 +542,6 @@ public EventRect(WeekViewEvent event, RectF rectF) {
541542
*/
542543
private void getMoreEvents(Calendar day) {
543544

544-
545545
// Delete all events if its not current month +- 1.
546546
deleteFarMonths(day);
547547

@@ -605,7 +605,6 @@ private void deleteFarMonths(Calendar currentDay) {
605605

606606
Calendar nextMonth = (Calendar) currentDay.clone();
607607
nextMonth.add(Calendar.MONTH, 1);
608-
int max = nextMonth.getActualMaximum(Calendar.DAY_OF_MONTH);
609608
nextMonth.set(Calendar.DAY_OF_MONTH, nextMonth.getActualMaximum(Calendar.DAY_OF_MONTH));
610609
nextMonth.set(Calendar.HOUR_OF_DAY, 12);
611610
nextMonth.set(Calendar.MINUTE, 59);

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,19 @@ public List<WeekViewEvent> onMonthChange(int newYear, int newMonth) {
121121
event.setColor(getResources().getColor(R.color.event_color_01));
122122
events.add(event);
123123

124+
startTime = Calendar.getInstance();
125+
startTime.set(Calendar.HOUR_OF_DAY, 3);
126+
startTime.set(Calendar.MINUTE, 30);
127+
startTime.set(Calendar.MONTH, newMonth-1);
128+
startTime.set(Calendar.YEAR, newYear);
129+
endTime = (Calendar) startTime.clone();
130+
endTime.set(Calendar.HOUR, 4);
131+
endTime.set(Calendar.MINUTE, 30);
132+
endTime.set(Calendar.MONTH, newMonth-1);
133+
event = new WeekViewEvent(10, getEventTitle(startTime), startTime, endTime);
134+
event.setColor(getResources().getColor(R.color.event_color_02));
135+
events.add(event);
136+
124137
startTime = Calendar.getInstance();
125138
startTime.set(Calendar.HOUR_OF_DAY, 05);
126139
startTime.set(Calendar.MINUTE, 0);

0 commit comments

Comments
 (0)