Skip to content

Commit b465e79

Browse files
author
marunjar
committed
support semi transparent header colours
clip canvas to prevent events and texts from beeing drawn behind the header so we can use transparent colours
1 parent a55ae00 commit b465e79

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.graphics.PointF;
99
import android.graphics.Rect;
1010
import android.graphics.RectF;
11+
import android.graphics.Region;
1112
import android.graphics.Typeface;
1213
import android.support.annotation.Nullable;
1314
import android.support.v4.view.GestureDetectorCompat;
@@ -438,23 +439,23 @@ private void initTextTimeWidth() {
438439
protected void onDraw(Canvas canvas) {
439440
super.onDraw(canvas);
440441

442+
// Hide everything in the first cell (top left corner).
443+
canvas.drawRect(0, 0, mTimeTextWidth + mHeaderColumnPadding * 2, mHeaderTextHeight + mHeaderRowPadding * 2, mHeaderBackgroundPaint);
444+
441445
// Draw the header row.
442446
drawHeaderRowAndEvents(canvas);
443447

444448
// Draw the time column and all the axes/separators.
445449
drawTimeColumnAndAxes(canvas);
446-
447-
// Hide everything in the first cell (top left corner).
448-
canvas.drawRect(0, 0, mTimeTextWidth + mHeaderColumnPadding * 2, mHeaderTextHeight + mHeaderRowPadding * 2, mHeaderBackgroundPaint);
449-
450-
// Hide anything that is in the bottom margin of the header row.
451-
canvas.drawRect(mHeaderColumnWidth, mHeaderTextHeight + mHeaderRowPadding * 2, getWidth(), mHeaderRowPadding * 2 + mHeaderTextHeight + mHeaderMarginBottom + mTimeTextHeight/2, mHeaderColumnBackgroundPaint);
452450
}
453451

454452
private void drawTimeColumnAndAxes(Canvas canvas) {
455453
// Draw the background color for the header column.
456454
canvas.drawRect(0, mHeaderTextHeight + mHeaderRowPadding * 2, mHeaderColumnWidth, getHeight(), mHeaderColumnBackgroundPaint);
457455

456+
// Clip to paint in left column only
457+
canvas.clipRect(0, mHeaderTextHeight + mHeaderRowPadding * 2, mHeaderColumnWidth, getHeight(), Region.Op.REPLACE);
458+
458459
for (int i = 0; i < 24; i++) {
459460
float top = mHeaderTextHeight + mHeaderRowPadding * 2 + mCurrentOrigin.y + mHourHeight * i + mHeaderMarginBottom;
460461

@@ -544,6 +545,9 @@ else if (mNewHourHeight > mMaxHourHeight)
544545
}
545546
}
546547

548+
// Clip to paint events only
549+
canvas.clipRect(mHeaderColumnWidth, mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight/2, getWidth(), getHeight(), Region.Op.REPLACE);
550+
547551
// Iterate through each day.
548552
Calendar oldFirstVisibleDay = mFirstVisibleDay;
549553
mFirstVisibleDay = (Calendar) today.clone();
@@ -629,6 +633,10 @@ else if (day.before(today)) {
629633
startPixel += mWidthPerDay + mColumnGap;
630634
}
631635

636+
637+
// Clip to paint header row only
638+
canvas.clipRect(mHeaderColumnWidth, 0, getWidth(), mHeaderTextHeight + mHeaderRowPadding * 2, Region.Op.REPLACE);
639+
632640
// Draw the header background.
633641
canvas.drawRect(0, 0, getWidth(), mHeaderTextHeight + mHeaderRowPadding * 2, mHeaderBackgroundPaint);
634642

0 commit comments

Comments
 (0)