Skip to content

Commit c09624d

Browse files
author
marunjar
committed
add option for event corner radius
optional round corners for events, default = 0 can be changed by attr eventCornerRadius in layout file by setter setEventCornerRadius
1 parent 818c559 commit c09624d

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public class WeekView extends View {
125125
private double mScrollToHour = -1;
126126
private ScaleGestureDetector mScaleDetector;
127127
private boolean mIsZooming;
128+
private int mEventCornerRadius = 0;
128129

129130
// Listeners.
130131
private EventClickListener mEventClickListener;
@@ -287,6 +288,7 @@ public WeekView(Context context, AttributeSet attrs, int defStyleAttr) {
287288
mOverlappingEventGap = a.getDimensionPixelSize(R.styleable.WeekView_overlappingEventGap, mOverlappingEventGap);
288289
mEventMarginVertical = a.getDimensionPixelSize(R.styleable.WeekView_eventMarginVertical, mEventMarginVertical);
289290
mXScrollingSpeed = a.getFloat(R.styleable.WeekView_xScrollingSpeed, mXScrollingSpeed);
291+
mEventCornerRadius = a.getDimensionPixelSize(R.styleable.WeekView_eventCornerRadius, mEventCornerRadius);
290292
} finally {
291293
a.recycle();
292294
}
@@ -421,7 +423,7 @@ protected void onDraw(Canvas canvas) {
421423
canvas.drawRect(0, 0, mTimeTextWidth + mHeaderColumnPadding * 2, mHeaderTextHeight + mHeaderRowPadding * 2, mHeaderBackgroundPaint);
422424

423425
// Hide anything that is in the bottom margin of the header row.
424-
canvas.drawRect(mHeaderColumnWidth, mHeaderTextHeight + mHeaderRowPadding * 2, getWidth(), mHeaderRowPadding * 2 + mHeaderTextHeight + mHeaderMarginBottom + mTimeTextHeight/2 - mHourSeparatorHeight / 2, mHeaderColumnBackgroundPaint);
426+
canvas.drawRect(mHeaderColumnWidth, mHeaderTextHeight + mHeaderRowPadding * 2, getWidth(), mHeaderRowPadding * 2 + mHeaderTextHeight + mHeaderMarginBottom + mTimeTextHeight/2, mHeaderColumnBackgroundPaint);
425427
}
426428

427429
private void drawTimeColumnAndAxes(Canvas canvas) {
@@ -667,9 +669,6 @@ private void drawEvents(Calendar date, float startFromPixel, Canvas canvas) {
667669

668670
// Calculate top.
669671
float top = mHourHeight * 24 * mEventRects.get(i).top / 1440 + mCurrentOrigin.y + mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight/2 + mEventMarginVertical;
670-
float originalTop = top;
671-
if (top < mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight/2)
672-
top = mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight/2;
673672

674673
// Calculate bottom.
675674
float bottom = mEventRects.get(i).bottom;
@@ -679,11 +678,9 @@ private void drawEvents(Calendar date, float startFromPixel, Canvas canvas) {
679678
float left = startFromPixel + mEventRects.get(i).left * mWidthPerDay;
680679
if (left < startFromPixel)
681680
left += mOverlappingEventGap;
682-
float originalLeft = left;
683681
float right = left + mEventRects.get(i).width * mWidthPerDay;
684682
if (right < startFromPixel + mWidthPerDay)
685683
right -= mOverlappingEventGap;
686-
if (left < mHeaderColumnWidth) left = mHeaderColumnWidth;
687684

688685
// Draw the event and the event name on top of it.
689686
RectF eventRectF = new RectF(left, top, right, bottom);
@@ -696,8 +693,8 @@ eventRectF.top < getHeight() &&
696693
) {
697694
mEventRects.get(i).rectF = eventRectF;
698695
mEventBackgroundPaint.setColor(mEventRects.get(i).event.getColor() == 0 ? mDefaultEventColor : mEventRects.get(i).event.getColor());
699-
canvas.drawRect(mEventRects.get(i).rectF, mEventBackgroundPaint);
700-
drawEventTitle(mEventRects.get(i).event, mEventRects.get(i).rectF, canvas, originalTop, originalLeft);
696+
canvas.drawRoundRect(mEventRects.get(i).rectF, mEventCornerRadius, mEventCornerRadius, mEventBackgroundPaint);
697+
drawEventTitle(mEventRects.get(i).event, mEventRects.get(i).rectF, canvas, top, left);
701698
}
702699
else
703700
mEventRects.get(i).rectF = null;
@@ -1389,6 +1386,19 @@ public void setOverlappingEventGap(int overlappingEventGap) {
13891386
invalidate();
13901387
}
13911388

1389+
public int getEventCornerRadius() {
1390+
return mEventCornerRadius;
1391+
}
1392+
1393+
/**
1394+
* Set corner radius for event rect.
1395+
*
1396+
* @param eventCornerRadius the radius in px.
1397+
*/
1398+
public void setEventCornerRadius(int eventCornerRadius) {
1399+
mEventCornerRadius = eventCornerRadius;
1400+
}
1401+
13921402
public int getEventMarginVertical() {
13931403
return mEventMarginVertical;
13941404
}

library/src/main/res/values/attrs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@
4343
<attr name="overlappingEventGap" format="dimension"/>
4444
<attr name="eventMarginVertical" format="dimension"/>
4545
<attr name="xScrollingSpeed" format="float"/>
46+
<attr name="eventCornerRadius" format="dimension"/>
4647
</declare-styleable>
4748
</resources>

0 commit comments

Comments
 (0)