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

Disabled day cell with custom background color #24

Closed
wyzard opened this issue Mar 16, 2019 · 4 comments
Closed

Disabled day cell with custom background color #24

wyzard opened this issue Mar 16, 2019 · 4 comments

Comments

@wyzard
Copy link

wyzard commented Mar 16, 2019

Thank you for this awesome library again. :)

Is there any way to set the 'disabled days' cell's background color conditionally?
Example: one of them 'reserved' (red), another one is 'processing' (orange) stb..

Thank you.

@rAseri
Copy link
Contributor

rAseri commented Mar 16, 2019

Hi and thank you!

Out of the box you can define your custom background color for disabled days using resources. Unfortunately conditional background color for disabled days is not supported.

But, as a workaround, you could try to define your custom RecyclerView.ItemDecoration class to decorate some specific days that you want. In the library there is a helper AbsDateItemDecoration class that may help you to add some custom decorations for the specific days. Create your item decorator that extends the AbsDateItemDecoration class. In the decorateDateView method you could implement your own custom decoration logic for the specific days.

Let me know if it helps you.

@wyzard
Copy link
Author

wyzard commented Mar 16, 2019

Thank you for your answer. I found the addCustomItemDecoration method, but I had difficulties to preserve the original appearance (font size, text position etc. is perfect for me, the only thing that I want to change is the background color).
Anyhow it seems to be good for me, thanks for your help.

@wyzard wyzard closed this as completed Mar 16, 2019
@wyzard
Copy link
Author

wyzard commented Mar 16, 2019

Sorry, it doesn't work for me. I can 'change' the background color of the cell, but I can't draw the day of month text on it.
Do you have a working example maybe? This is my draft so far:

`
private class CustomItemDecoration extends AbsDateItemDecoration {

    @Override
    public void decorateDateView(@NotNull Canvas canvas, @NotNull CalendarDate calendarDate, @NotNull Rect rect) {
        DisplayMetrics displayMetrics = ReservationActivity.this.getResources().getDisplayMetrics();
        int strokeWidth = Math.round(1f * (displayMetrics.xdpi / DisplayMetrics.DENSITY_DEFAULT));

        Paint paint = new Paint();
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
        paint.setColor(Color.LTGRAY);
        paint.setStrokeWidth(strokeWidth);

        TextPaint paint2 = new TextPaint(Paint.ANTI_ALIAS_FLAG);
        paint2.setColor(Color.RED);

        if (calendarDate.getDayOfMonth() == 14) {
            canvas.drawRect(rect.left + strokeWidth, rect.top + strokeWidth, rect.right - strokeWidth, rect.bottom - strokeWidth , paint);
            //canvas.drawText(String.valueOf(calendarDate.getDayOfMonth()), rect.width() / 2, rect.height() / 2, paint2);
            canvas.drawText("Test", rect.width() / 2f, rect.height() / 2f, paint2);
        }
    }
}

`

@wyzard wyzard reopened this Mar 16, 2019
@wyzard
Copy link
Author

wyzard commented Mar 17, 2019

Ok, my fault. It was a positioning problem. :)

@wyzard wyzard closed this as completed Mar 17, 2019
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

No branches or pull requests

2 participants