Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the possibility to add an icon to an event #266

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

vermotr
Copy link

@vermotr vermotr commented Jan 24, 2016

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

This was referenced Jan 24, 2016
@entropitor
Copy link
Contributor

@vermotr Can you please remove all the formatting updates?

@entropitor
Copy link
Contributor

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).

@vermotr
Copy link
Author

vermotr commented Jan 30, 2016

@caske33 I have updated my PR ;-)

@marunjar
Copy link
Contributor

marunjar commented Feb 2, 2016

👍

but there happened is also a lot of code formatting that would break other PR

@challme28
Copy link

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.

@isairuiz
Copy link

isairuiz commented Mar 9, 2020

Hi, someone know how to use this PR in android app?

@sandeepyohans
Copy link

sandeepyohans commented Aug 2, 2022

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();
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants