Android-Week-View icon indicating copy to clipboard operation
Android-Week-View copied to clipboard

Add the possibility to add an icon to an event

Open vermotr opened this issue 9 years ago • 7 comments

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 avatar Jan 24 '16 22:01 vermotr

@vermotr Can you please remove all the formatting updates?

entropitor avatar Jan 26 '16 18:01 entropitor

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

entropitor avatar Jan 26 '16 18:01 entropitor

@caske33 I have updated my PR ;-)

vermotr avatar Jan 30 '16 15:01 vermotr

:+1:

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

marunjar avatar Feb 02 '16 19:02 marunjar

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.

challme28 avatar May 19 '16 19:05 challme28

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

isairuiz avatar Mar 09 '20 19:03 isairuiz

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

sandeepyohans avatar Aug 02 '22 14:08 sandeepyohans