A beautiful material calendar with endless scroll, range selection and a lot more!

Overview

Maven Central

alt text

CrunchyCalendar

A light, powerful and easy to use Calendar Widget with a number out of the box features:

  • Infinite vertical scrolling in both directions;
  • Setting date boundaries to restrict scrolling inside of a specific time period;
  • Single / multiple / range dates selection;
  • Pre-selecting dates;
  • Color customization;
  • Displaying color indicators;
  • Setting own custom ItemDecoration;
  • Presented as a View subclass which can be displayed everywhere: in Activity, Fragment or Dialog, or can be integrated into another custom View.

alt text

Dependency

This library is available on Maven Central (Previously on jCenter).

Gradle

implementation 'ru.cleverpumpkin:crunchycalendar:2.2.0'

Maven

<dependency>
  <groupId>ru.cleverpumpkin</groupId>
  <artifactId>crunchycalendar</artifactId>
  <version>2.2.0</version>
  <type>pom</type>
</dependency>

Usage

Here's a basic example of Calendar usage.

First of all, you should declare CalendarView in your layout XML file.

  <ru.cleverpumpkin.calendar.CalendarView 
        android:id="@+id/calendar_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

Perform Calendar setup in your Activity or Fragment class.

val calendarView = view.findViewById(R.id.calendar_view)
val calendar = Calendar.getInstance()

// Initial date
calendar.set(2018, Calendar.JUNE, 1)
val initialDate = CalendarDate(calendar.time)

// Minimum available date
calendar.set(2018, Calendar.MAY, 15)
val minDate = CalendarDate(calendar.time)

// Maximum available date
calendar.set(2018, Calendar.JULY, 15)
val maxDate = CalendarDate(calendar.time)

// List of preselected dates that will be initially selected
val preselectedDates: List<CalendarDate> = getPreselectedDates()

// The first day of week
val firstDayOfWeek = java.util.Calendar.MONDAY

// Set up calendar with all available parameters
calendarView.setupCalendar(
    initialDate = initialDate, 
    minDate = minDate,
    maxDate = maxDate,
    selectionMode = SelectionMode.NONE,
    selectedDates = preselectedDates,
    firstDayOfWeek = firstDayOfWeek,
    showYearSelectionView = true
)
                

Note: all parameters in setupCalendar() method are optional and have default values.

To handle date click / long click with custom action, you can do this:

// Set date click callback 
calendarView.onDateClickListener = { date ->

    // Do something ... 
    // for example get list of selected dates
    val selectedDates = calendarView.selectedDates 
}

// Set date long click callback 
calendarView.onDateLongClickListener = { date ->

    // Do something ... 
}

Saving and Restoring state

Calendar takes care of saving and restoring its internal state (selected dates, selection mode, etc.), so there's no need to save it manually and call CalendarView.setupCalendar() method every time, when Activity or Fragment is recreated.

If a Calendar was set up with CalendarView.setupCalendar() method before restoring state, previous saved state will be ignored.

Dates Selection

Calendar supports several selection modes: single, multiple and range.

Note: You can restrict selection of some dates by implementing your own filtration logic:

// Here we make weekends unavailable for selection
calendarView.dateSelectionFilter = { date ->
    date.dayOfWeek != Calendar.SATURDAY && date.dayOfWeek != Calendar.SUNDAY
}

Single date selection

Only one date can be selected at a time.

// Set up calendar with SelectionMode.SINGLE
calendarView.setupCalendar(selectionMode = SelectionMode.SINGLE)

...

// Get selected date or null
val selectedDate: CalendarDate? = calendarView.selectedDate

// Get list with single selected date or empty list
val selectedDates: List<CalendarDate> = calendarView.selectedDates

Multiple dates selection

A number of dates can be selected. Pressing an already selected date will unselect it.

// Set up calendar with SelectionMode.MULTIPLE
calendarView.setupCalendar(selectionMode = SelectionMode.MULTIPLE)

...

// Get all selected dates in order they were added or empty list
val selectedDates: List<CalendarDate> = calendarView.selectedDates

Range date selection

Allows you to select a date range. Previous selected range is cleared when you select another one.

// Set up calendar with SelectionMode.RANGE
calendarView.setupCalendar(selectionMode = SelectionMode.RANGE)

... 

// Get all selected dates in range (includes start and end date) or empty list
val selectedDates: List<CalendarDate> = calendarView.selectedDates

Color Indicators

The Calendar is able to display simple color indicators (dots) on the date cell.

Color indicator represents as simple interface, which you can implement in your classes.

interface DateIndicator {
    val date: CalendarDate // indicator date
    val color: Int // indicator color
}

Here's an example of setting indicators to display on the Calendar.

// Set up calendar
calendarView.setupCalendar()


val indicators: List<DateIndicator> = getDatesIndicators()

// Set List of indicators that will be displayed on the calendar 
calendarView.datesIndicators = indicators

To get all indicators for specific date, you can do this:

// Set date click callback 
calendarView.onDateClickListener = { date ->

    // Get all indicators for the date
    val indicatorsForDate = calendarView.getDateIndicators(date)
    
    // do something ... 
}

View Customization

Calendar appearance open for customization.

Styling using XML

Calendar appearance can be customized with XML attributes. Here's an example of applying custom style to change Calendar appearance.

Define your custom style for the Calendar.

<style name="CalendarViewCustomStyle">
    <item name="android:background">@android:color/white</item>
    <item name="calendar_date_background">@drawable/custom_date_bg_selector</item>
    <item name="calendar_date_text_color">@color/custom_date_text_selector</item>
    <item name="calendar_day_bar_background">@color/custom_calendar_days_bar_background</item>
    <item name="calendar_day_bar_text_color">@color/custom_calendar_days_bar_text_color</item>
    <item name="calendar_day_bar_weekend_text_color">@color/custom_calendar_days_bar_text_color</item>
    <item name="calendar_grid_color">@color/custom_calendar_grid_color</item>
    <item name="calendar_grid_on_selected_dates">false</item>
    <item name="calendar_month_text_color">@color/custom_calendar_month_text_color</item>
    <item name="calendar_year_selection_arrows_color">
        @color/custom_calendar_year_selection_arrows_color
    </item>
    <item name="calendar_year_selection_background">
        @color/custom_calendar_year_selection_background
    </item>
    <item name="calendar_year_selection_text_color">
        @color/custom_calendar_year_selection_text_color
    </item>
</style>

Apply your custom style.

<ru.cleverpumpkin.calendar.CalendarView
    android:id="@+id/calendar_view"
    style="@style/CalendarViewCustomStyle"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

To define custom styles for all Calendars in your app at once you can do this:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

    <!-- ...snip... -->
    
    <item name="calendarViewStyle">@style/CalendarViewCustomStyle</item>
    
    <!-- ...etc... -->
</style>

Styling using code

You can also set styles and colors programmatically:

 with(calendarView) {
     setDrawGridOnSelectedDates(drawGrid = true)
     setGridColorRes(R.color.custom_calendar_grid_color)
     setYearSelectionBarBackgroundColorRes(R.color.custom_calendar_year_selection_background)
     setYearSelectionBarArrowsColorRes(R.color.custom_calendar_year_selection_arrows_color)
     setYearSelectionBarTextColorRes(R.color.custom_calendar_year_selection_text_color)
     setDaysBarBackgroundColorRes(R.color.custom_calendar_days_bar_background)
     setDaysBarTextColorRes(R.color.custom_calendar_days_bar_text_color)
     setDaysBarWeekendTextColorRes(R.color.custom_calendar_days_bar_text_color)
     setMonthTextColorRes(R.color.custom_calendar_month_text_color)
     setDateCellBackgroundRes(R.drawable.custom_date_bg_selector)
     setDateCellTextColorRes(R.color.custom_date_text_selector)
}

If you need to add some custom drawing logic for Calendar, you can implement standard RecyclerView.ItemDecoration and add it for Calendar using addCustomItemDecoration() method.

// Set up calendar
calendarView.setupCalendar()

// Some custom decoration logic 
val customItemDecoration = CustomItemDecoration()

// Add custom item decoration for calendar
calendarView.addCustomItemDecoration(customItemDecoration)

There is an abstract helper class AbsDateItemDecoration that you can extend to implement custom drawing logic for specific dates cells.

Sample app

The Sample app is available for download from Google Play.

Sketch file

Wouldn’t it be a real pain for your designer to ignore Calendar View in your apps mockups? Or for them to try and explain to you, which colors you should use by adding them to Jira task in plain text?

That is lame. That’s why we’ve added a .sketch-file to this repository here. Have fun!

License


MIT License

Copyright (c) 2018 CleverPumpkin Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Maintainers

alt text

CrunchyCalendar is maintained and developed by CleverPumpkin.

Comments
  • Not scrolling to current day.

    Not scrolling to current day.

    Hi. In setupCalendar() if initialDate and minDate are too far apart then it won't scroll to initialDate. For example. Set calendar with minDate as 1st of January of this year and initialDate as today (August 1st) then when loaded it won't scroll to today. moveToDate() also won't scroll to that date.

    Now, if we initialize calendar with minDate set as March and initialDate as August then when loaded we will see August on the screen.

    I guess it has something to do with how many items recyclerView loads because after we scroll to today it all works fine.

    opened by pixelsbyweb 8
  • create event in calendar

    create event in calendar

    Hello, From server i got some date and i want to show this date as a event and mark it. I want to use java but i can't find a helpful sample to add event into the calendar. I am stack on this. say i have a array of date i want to show this date into the calendar with a mark

    Thanks in advance

    opened by pavelsust 7
  • Disabled day cell with custom background color

    Disabled day cell with custom background color

    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.

    opened by wyzard 4
  • Can I add a selection programmatically?

    Can I add a selection programmatically?

    Hello,

    I would like to select all the week (Monday to sunday) when a user clicks on a day.

    I'm trying to select all days with onDateClickListener and setupCalendar but it's not work.

    Do you have any idea? :/

    opened by bellierjonathan 4
  • New logo/icon proposal

    New logo/icon proposal

    Good day sir. I am a graphic designer and i am interested in designing a logo for your good project. I will be doing it as a gift for free. I just need your permission first before I begin my design. Hoping for your positive feedback. Thanks

    opened by mansya 3
  • Theming

    Theming

    First of all, thanks for the library :)

    Please, add more possibilities for theming:

    1. Make properties public, to allow theming from code, not xml only
    2. Do not ignore defStyleAttr from the constructor, right now it just goes to the super classes, but is ignored in the "obtainStyledAttributes" in init block
    opened by antonshkurenko 3
  • Logo Design: CrunchyCalendar

    Logo Design: CrunchyCalendar

    Hello!

    I examined your project and I saw that Crunchy Calendar has no logo design yet. I'm a graphic designer and I like to support open source projects. I would like to design a logo for your project if you interested, I will be happy to work with you! :)

    Best Regards

    Baran Pirinçal

    Graphic Designer

    opened by baranpirincal 3
  • Date Range Selection and dateSelectionFilter

    Date Range Selection and dateSelectionFilter

    Hi,

    Thanks for the great library.

    Is it possible to disallow users to select date ranges if one or more of the days in the selected range is not selectable?

    So, let's say, I'm setting my dateSelectionFilter to not allow selecting date 17/06/2019. In that case, user should not be able to select a range like between 15/06/2019 and 19/06/2019 or a wider range because that one not selectable day is in the range.

    I checked and couldn't find a solution for it. Is it possible to do that at the moment or do we need an update?

    I can still manually achieve this by after user makes a range selection, I can loop through the selected days and check them one-by-one, but just wondered if the CalendarView have this feature already.

    opened by polatolu 2
  • How to display a single month?

    How to display a single month?

    Is there a way to display a single month, such as image

    ?

    I want to create an events-like calendar, and I want the user to browse month by month, as I'll display information below the calendar.

    Is this possible / planned with Crunchy?

    opened by LeoColman 2
  • Adding events after loading JSON data

    Adding events after loading JSON data

    First of all, I really love this calendar. I have tried a lot of calendars in the past few days but this was by far the best and easiest to implement.

    I am currently having an issue with reloading the event indicators after loading JSON from the google Calendar API. The calendar runs the generateCalendarDateIndicators() function before the data is there however when I run it manually after I have the data, no new dots appear. I am currently running the code inside of its own activity instead of a fragment.

    I am imagining that I need to have the calendar refresh the UI once I have the JSON data. I have tried a few different ideas for refreshing the UI but they all lead to refreshing the entire page which puts me in a big circle.

    Any thoughts or suggestions would be well appreciated.

    opened by 3-14159jam 2
  • Performance drawbacks

    Performance drawbacks

    Try to implement calendar on nested RecyclerViews (outer RV+LinearLayoutManager hold month items & every month has its own inner RV+GridLayoutManager with its days) and compare performance of both implementation. Your variant with single RV+GridLayoutManager is much slower

    opened by smbduknow 2
  • Make example of getPreselectedDates() and getDatesIndicators() in main page

    Make example of getPreselectedDates() and getDatesIndicators() in main page

    I think it would be convenient to make an example on how these functions could be implemented.

    Indeed, I'm having problems to do a test getDatesIndicators() function, though I'm trying to do it in java code as seen here: https://stackoverflow.com/questions/63298266/how-to-implement-kotlin-interface-in-java.

    Thanks for the attention.

    opened by moylir 1
  • Impossible to customize some colors

    Impossible to customize some colors

    Hello! Why impossible to customize colors: "calendar_date_selected_background" and probably "calendar_date_today_text_color" Hardcoded light blue color not suitable for some color themes. I don’t understand how to change it.

    opened by MegaDedh 2
Releases(v2.2.0)
  • v2.2.0(Apr 15, 2021)

  • v2.1.0(Jul 21, 2020)

  • v2.0.1(Aug 9, 2019)

  • v2.0.0(May 14, 2019)

    1. Add public methods for calendar appearance customisation.
    2. Add the ability to determine whether a date is a weekend or not.
    3. Internal upgrades and improvements.
    Source code(tar.gz)
    Source code(zip)
  • v2.0.0-beta1(Apr 7, 2019)

    1. Migrate from the legacy Support Libraries to the new AndroidX packages.
    2. Add new public method (CalendarView.updateSelectedDates) for selected dates updating.
    3. Rename SelectionMode.NON to the SelectionMode.NONE.
    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Aug 31, 2018)

    1. Add the ability to set the firstDayOfWeek in the setupCalendar() method.
    2. Add the ability to set a onDateLongClickListener for the Calendar dates.
    3. Add the ability to set a dateSelectionFilter that indicates whether a date available for selection or not.
    4. Add an optional year selection control that allows to quickly navigate between years.
    5. Add a calendarViewStyle attribute as a default value for defStyleAttr in the CalendarView constructor. So now it is possible to define common style for all Calendars in the application Theme file.
    6. Change visibility level to internal of some library classes and interfaces.
    7. Some internal cleanup and refactoring.
    Source code(tar.gz)
    Source code(zip)
    sample.apk(2.18 MB)
Owner
CleverPumpkin
CleverPumpkin
Calef - CalEF (Calendar Entry Formatter) : Select an entry in Android-Kalender and send/share the entry's content as human readable text.

CalEF (Calendar Entry Formatter) Select an entry in Android-Kalender and send/share the entry's content as human readable text. Usually calendar entri

k3b 6 Aug 17, 2022
Android Library to create Lottie animation view dialog easily with a lot of customization

LottieDialog Android Library to create Lottie animation view dialog easily with a lot of customization Why you should use Lottie Dialog You have no li

Amr Hesham 39 Oct 7, 2022
🦄 Best beautiful java blog, worth a try

Tale Blog Tale's English meaning for the Story, I believe that every person who insists on writing a blog is a story; Chinese you call it Collapse doe

Tale Blog System 4.8k Dec 30, 2022
A beautiful Clock Widget for your Desktop! (tested on Windows)

ClockWidget A beautiful Clock Widget for your Desktop! (tested on Windows) This is a clock widget that I programmed in the first year of Computer Scie

Hasan Tuna 7 Dec 15, 2022
Jornada Big Tech: I will have 3 months to study and prepare myself for the Big Tech interviews. Repository containing all my study material.

Jornada Big Tech (Big Tech Journey) Jornada Big Tech: I will have 3 months to study and prepare myself for the Big Tech interviews. Repository contain

Camila Maia 87 Dec 8, 2022
Modular and customizable Material Design UI components for Android

Material Components for Android Material Components for Android (MDC-Android) help developers execute Material Design. Developed by a core team of eng

Material Components 14.4k Jan 3, 2023
🎒 💻 Material for Computer Club Classes

MNNIT Computer Coding Club This repository contains the codes, support links and other relevant materials for every class under Computer Coding Club,

MNNIT Computer Club 409 Dec 18, 2022
🕹️ Material das aulas de Criação de Aplicações e Sistemas 🕹️

Criação de Aplicações e Sistemas Projetos | Tecnologias | Screenshots | Licença CAS ☕ Projetos desenvolvidos durante as aulas do segundo trimestre de

UniAmérica Descomplica - ADS 18 Nov 20, 2022
a simple News App styled by Material Design

Material News Material Design 风格的 Android 新闻 App 1 代码结构 /app/src/main/ 1.1 Java代码部分 ./java/com/java/shanjingbo/ activity/:程序入口 Activity adapter/:Recyc

null 3 Sep 13, 2021
An Android library for member secretGFX group, This can be used to growing your apps and get more install via a simple banner view & native view and interstitial dialog.

GFX-AdPromote An Android library for member secretGFX group, This can be used to growing your apps and get more install via a simple banner view & nat

SAID MOTYA 10 Dec 25, 2022
NeverScapeAlone! Instantly match with other players and take the hassle out of finding partners for bosses, minigames, skills, pking, and more!

NeverScapeAlone An Old School RuneScape Matchmaking Plugin on RuneLite! Tired of having to scour friend's chats, discords, and forums to find friends

null 14 Sep 2, 2022
SecureDB is an extension for Ai2 Appinventor and its distros which stores the data in the form of key and value just like TinyDB but in a more secure manner.

SecureDB SecureDB is an extension for Ai2 Appinventor and its distros which stores data for your app in a secure format locally on user's device. Expl

Akshat Developer 3 Sep 24, 2022
Spring Data Redis extensions for better search, documents models, and more

Object Mapping (and more) for Redis! Redis OM Spring extends Spring Data Redis to take full advantage of the power of Redis. Project Stage Snapshot Is

Redis 303 Dec 29, 2022
Stetho is a debug bridge for Android applications, enabling the powerful Chrome Developer Tools and much more.

Stetho Stetho is a sophisticated debug bridge for Android applications. When enabled, developers have access to the Chrome Developer Tools feature nat

Meta 12.6k Jan 3, 2023
A fast, lightweight and more productive microservices framework

A fast, lightweight and cloud-native microservices framework. Stack Overflow | Google Group | Gitter Chat | Subreddit | Youtube Channel | Documentatio

null 3.5k Jan 5, 2023
A sideproject to learn more about object-oriented programming, design patterns and Java meanwhile studying an OOP-course.

MyBank Description A console application that simulates a bank with very simple functions. Potential story could be an employee using this application

null 2 Mar 23, 2022
A small companion library to Mixin, designed to help you write your Mixins in a more expressive and compatible way.

MixinExtras A small companion library to Mixin, designed to help you write your Mixins in a more expressive and compatible way. More information about

null 97 Jan 7, 2023
You can draw and many more things in this program

Scribble Table of contents Introduction Screenshots Prerequisite Introduction You can draw/erase in different width. Chose color of your choice. Set b

Japsare Ayushi 1 Jan 27, 2022
Customize your device even more by having two separate sets of wallpapers for light and dark mode.

DualWallpaper You can help me out with translations here. Customize your device even more by having two separate sets of wallpapers for light and dark

Yann 18 Dec 25, 2022