Android-Week-View
Android-Week-View copied to clipboard
Add the possibility to add an icon to an event
Hi,
I create a PR to add the possibility to display an icon at the bottom of an event.
To associate an icon with an event you can use this method : setIconId()
and to set its color: setIconColor()
. By default, the color of icon is the same than that of header.
You can define the size of icons in your layout with the eventIconSize
attribute.
vermotr
@vermotr Can you please remove all the formatting updates?
Furthermore, I'm wondering if we should allow the developer to choose the position of the icon (from a predefined set).
Btw, can you also update the readme with instructions on how to set an icon? That way future devs can find out (and I can find out how to test your code).
@caske33 I have updated my PR ;-)
:+1:
but there happened is also a lot of code formatting that would break other PR
When there is an event that stars, lets say, 11PM and ends 1AM on the next day the icon won't draw. I know these kind of events don't occur that often but I'd like to have this also. I've seen how event titles are drawn twice but couldn't replicate it for the icon. Thanks for the branch.
Hi, someone know how to use this PR in android app?
Hi @vermotr I want to set the icon at the start (left-top instead of right-bottom). How do I achieve that?
this is my drawEventIcon()
private void drawEventIcon(WeekViewEvent event, RectF rect, Canvas canvas) {
if (rect.right - rect.left - mEventPadding * 2 - mEventIconSize < 0) return;
if (rect.bottom - rect.top - mEventPadding * 2 - mEventIconSize < 0) return;
int iconId = event.getIconId();
if (iconId != 0) {
Drawable drawable = ResourcesCompat.getDrawable(mContext.getResources(), iconId, mContext.getTheme());
if (drawable != null) {
int left = mEventIconSize;
int top = mEventIconSize;
int right = 0;
int bottom = 0;
int color = event.getIconColor() == 0 ? mEventTextColor : event.getIconColor();
drawable.setBounds(left, top, right, bottom);
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
canvas.save();
canvas.translate(rect.left - mEventIconSize - mEventPadding,
rect.top - mEventIconSize - mEventPadding);
drawable.draw(canvas);
canvas.restore();
}
}
}