An android library which provides a compact calendar view much like the one used in google calenders.

Overview

CompactCalendarView Build Status

CompactCalendarView is a simple calendar view which provides scrolling between months. It's based on Java's Date and Calendar classes. It provides a simple api to query for dates and listeners for specific events. For example, when the calendar has scrolled to a new month or a day has been selected. Still under active development.

Contributing

Please raise an issue of the requirement so that a discussion can take before any code is written, even if you intend to raise a pull request. Please see setup for testing.

Testing

CompactCalendarView makes use of screenshot-tests-for-android (https://github.com/facebook/screenshot-tests-for-android). This is for UI testing. Since screenshot-tests-for-android takes screenshots, we need a way to ensure images can be reproduced consistently. To do this, a specific emulator is used to run tests. Unfortunately, an older emulator is used for now. New pull requests which change functionality some how should aim to create new screenshot tests or unit tests if possible. To run this locally, run the below commands:

Pre-requisite (Also refer to .travis.yml):

  • Python
  • Python pillow installed
  • Install android-19 (can be done through android sdk manager or command line).

Android 19 emulator is used because it seems to be a fast enough on travis-ci and because x86 emulators are not supported on travis-ci. Newer android version is possible but build times will increase.

Install the abi and accept:

$ $ANDROID_HOME/tools/bin/sdkmanager 'system-images;android-22;default;armeabi-v7a'

Create the emulator:

$ echo no | $ANDROID_HOME/tools/bin/avdmanager create avd --force -n testCompactCalendarEmulator -k "system-images;android-22;default;armeabi-v7a"

Create sd card (creating in current dir): Any problems with sdcard are best solved by deleting and trying again

$ mksdcard -l sdcard 100M sdcard

Run emulator (with out audio and window):

$ $ANDROID_HOME/emulator/emulator -avd testCompactCalendarEmulator -no-audio -no-window -sdcard sdcard &

Run emulator and watch(with audio and window):

$ $ANDROID_HOME/emulator/emulator -avd testCompactCalendarEmulator -sdcard sdcard 

Running the tests to verify that the current tests pass and to check which tests are not producing the same screenshot:

$ ./gradlew verifyMode screenshotTests 

To generate new screenshots if new tests have been added:

$ ./gradlew recordMode screenshotTests 

Run the unit tests like below:

$ ./gradlew test

Android studio emulator

It's possible to test using android studio emulator. However, it must be android 19 and and 480x800 screen resolution. One example is the Nexus S emulator. Just start the emulator and execute the gradle commands to run the tests. Emulator should be found automatically.

Open/Close animations

The library supports opening/closing with or without animations.

ScreenShot

Example usage

It is possible to change the appearance of the view via a few properties. This includes the background color, text color, textsize color of the current day and the color of the first day of the month.

    <com.github.sundeepk.compactcalendarview.CompactCalendarView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/compactcalendar_view"
        android:layout_width="fill_parent"
        android:paddingRight="10dp"
        android:paddingLeft="10dp"
        android:layout_height="250dp"
        app:compactCalendarTargetHeight="250dp"
        app:compactCalendarTextSize="12sp"
        app:compactCalendarBackgroundColor="#ffe95451"
        app:compactCalendarTextColor="#fff"
        app:compactCalendarCurrentSelectedDayBackgroundColor="#E57373"
        app:compactCalendarCurrentDayBackgroundColor="#B71C1C"
        app:compactCalendarMultiEventIndicatorColor="#fff"
        />

Please see Sample app for full example.

    // ... code omitted for brevity         
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final CompactCalendarView compactCalendarView = (CompactCalendarView) findViewById(R.id.compactcalendar_view);
        // Set first day of week to Monday, defaults to Monday so calling setFirstDayOfWeek is not necessary
        // Use constants provided by Java Calendar class
        compactCalendarView.setFirstDayOfWeek(Calendar.MONDAY);
       
        // Add event 1 on Sun, 07 Jun 2015 18:20:51 GMT
        Event ev1 = new Event(Color.GREEN, 1433701251000L, "Some extra data that I want to store.");
        compactCalendar.addEvent(ev1);

        // Added event 2 GMT: Sun, 07 Jun 2015 19:10:51 GMT
        Event ev2 = new Event(Color.GREEN, 1433704251000L);
        compactCalendar.addEvent(ev2);

        // Query for events on Sun, 07 Jun 2015 GMT. 
        // Time is not relevant when querying for events, since events are returned by day. 
        // So you can pass in any arbitary DateTime and you will receive all events for that day.
        List<Event> events = compactCalendar.getEvents(1433701251000L); // can also take a Date object
        
        // events has size 2 with the 2 events inserted previously
        Log.d(TAG, "Events: " + events);

        // define a listener to receive callbacks when certain events happen.
        compactCalendarView.setListener(new CompactCalendarView.CompactCalendarViewListener() {
            @Override
            public void onDayClick(Date dateClicked) {
                List<Event> events = compactCalendarView.getEvents(dateClicked);
                Log.d(TAG, "Day was clicked: " + dateClicked + " with events " + events);
            }

            @Override
            public void onMonthScroll(Date firstDayOfNewMonth) {
                Log.d(TAG, "Month was scrolled to: " + firstDayOfNewMonth);
            }
        });
    }

You can modify indicators using a preset of styles, below is an example, but few other combinations are also possible:

ScreenShot

Note that the calendar makes no attempt to de-duplicate events for the same exact DateTime. This is something that you must handle your self if it is important to your use case.

Locale specific settings

It's possible to set the locale so that weekday column names are automatically set by the calendar.

        CompactCalendarView compactCalendarView = (CompactCalendarView) findViewById(R.id.compactcalendar_view);
        compactCalendarView.setLocale(Locale.CHINESE);
        compactCalendarView.setUseThreeLetterAbbreviation(true);

dependencies {
    compile 'com.github.sundeepk:compact-calendar-view:3.0.0'
}
The MIT License (MIT)

Copyright (c) [2018] [Sundeepk]

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.
Comments
  • Mutliple dots for multiple events on the same day

    Mutliple dots for multiple events on the same day

    Love this library ! Currently using it in my app :)

    Would be great to add the capability of having multiple dots when there's multiple events for a day. See image example image below.

    Thank you !

    enhancement 
    opened by csbenz 72
  • Show Event indicators to currently selected day

    Show Event indicators to currently selected day

    While Adding events to current date, the background color overlaps and the small indicators are not displayed. I tried to change the app:compactCalendarCurrentDayBackgroundColor="#2bb573" to transparent but its not working either. Is there any way to display small indicators on current day?

    enhancement 
    opened by VishnuTB 39
  • How can i change current day to surrounded circle instead of background color

    How can i change current day to surrounded circle instead of background color

    Hi there! Thank you for awesome lib! I need to change current day view to rounded circle with white border instead of bg color. How can i do it.Thanks in advance default

    enhancement 
    opened by nAkhmedov 28
  • Current day not displayed on activity load

    Current day not displayed on activity load

    Hi,

    Sorry by advance, english isn't my natural language and I'm new!

    So, my problem is when I call another activity with your calendar implemented, I need to touch the calendar to display the selected current day. I currently add only the xml and not other (except findViewById programmatically).

    I wanted to display the current day selected when the activity load, it's possible? Did I make a mistake or I forgot something?

    Thanks by advance! AerWyn81

    help wanted 
    opened by AerWyn81 26
  • onMonthScroll scrolling fast damages the year of the parameter firstDayOfMonth

    onMonthScroll scrolling fast damages the year of the parameter firstDayOfMonth

    Hi. I just realized that when you scroll kind of fast between months till another and another year, the date given in the onMonthScroll argument starts to give the wrong year. I scrolled till December 2018 and then went back to December of the last year (2017) and it shows 2020 or any other year not even close.

    If I keep scrolling between months, the year of the Date gets even more wrong.

    I tried my best to explain this and I know its not very common to scroll like that but it is still an issue. Hope you can solve it soon.

    bug 
    opened by carlastabile 13
  • Multiple event indicators not showing up

    Multiple event indicators not showing up

    Hi @SundeepK the library is too awesome. I just added the dependency of the library version 1.9.7 and used calendar view in xml. Created new events and added them to the calendarView. event indicators are maintained same as large_fill and small_fill but the dots do not show up under the dates. Any idea of what needs to be changed?

    help wanted 
    opened by preyesm 12
  • Display days of previous and current months

    Display days of previous and current months

    Hi,

    I've added the possibility on a given month to display the days of the previous and next month as explained in the issue #46

    The code is pretty straightforward. I've added two attributes to keep it optional (one to use the feature and one to set the color of the text) and it's disabled by default to keep retro-compatibility.

    opened by JulienArzul 11
  • horizontal scroll problems in collapsing toolbar

    horizontal scroll problems in collapsing toolbar

    I have the calendar view in a collapsing toolbar. The problema I have, is that horizontal scrolling (to change between months) is not smooth, meaning that it gets interrupted by the vertical scroll of the RecyclerView/CollapsingToolbar. I am not sure where the problema comes from, but probably from this library, because I did not observe this with other calendar views. (If somebody knows how to fix this but has no time, I probably can try to do it. I just do not know where to start.)

    bug 
    opened by mzilian 11
  • How to show current month; event dot appearing on delay

    How to show current month; event dot appearing on delay

    Hello I have two questions:

    First, I would like to display the current month's name inside the calendar. Right now you can scroll between months but there is no idicator of what month you are actually seeing. I looked in the source but could not find any method to retrieve current visible month. Also how do I change the week days' abbreviations in uperrcase? Right now is showing l,m,m,g,v,s,d which are the week days in my locale. I want them to be L,M,M,G,V,S,D in uppercase.

    Screen

    Second, I noticed that if I add a new event the dot under the day number does not appear until i click again the calendar (in any place). This is frustrating since one might not know that he actually added the event.Code I use to add the event:

    new DialogInterface.OnClickListener()
                {
                    public void onClick(DialogInterface dialog, int id)
                    {
                        List<Event> events = compactCalendarView.getEvents(dateClicked.getTime());
                        if(events.size() == 0){
                            Event ev1 = new Event(Color.GREEN
                                    , dateClicked.getTime()
                                    , "completed_true");
                            compactCalendarView.addEvent(ev1, true);
                        }
                    }
                });
    

    Thank you in advance.

    opened by fermatijoe 10
  • remove all events at once in calendar with no events

    remove all events at once in calendar with no events

    is there any way to remove events (dots under date ) all at once rather than using below removeEvent method

    compactCalendarView.removeEvent(new CalendarDayEvent(dateClicked.getTime(), Color.argb(255, 169, 68, 65)), true); adapter.notifyDataSetChanged();

    enhancement 
    opened by kprathap23 10
  • cannot select current day

    cannot select current day

    I cannot select the current day. The DayCircleIndicator are drawn in priority for the currentDay instead of the currentSelectedDay.

    Don't you think the selected day should prevail ?

    enhancement 
    opened by gaultierq 9
  • How to pass Calendar as argument?

    How to pass Calendar as argument?

    Hi! I'm developing an android aplication and I'm using this library to customize a calendar by adding events through different fragments/activities to the same calendar instance, but I can't pass it as an argument as it's not a parceable/serializable object. Is there any way to do it?

    opened by alejandropalaci0 0
  • use Gradle Daemon

    use Gradle Daemon

    Gradle daemon. The Daemon is a long-lived process that help to avoid the cost of JVM startup for every build. Since Gradle 3.0, Gradle daemon is enabled by default. For an older version, you should enable it by setting org.gradle.daemon=true.

    opened by shisheng-1 0
  • How to remove the selected current date background when month is scrolled?

    How to remove the selected current date background when month is scrolled?

    Whenever month is changed, always first day is selected.

    For example, I selected 5th Mar. But after month is scrolled, and back to return Mar, It is selected 1st Mar. Of course 1st Apr is selected for Apr. How to remove this ? And how to keep the selected date?

    opened by fullstact69 0
  • Adding Events to CompactCalendar  from api call

    Adding Events to CompactCalendar from api call

    In my code, I have calenderFragment (where the main compactCalnder is) and a DayActivity. When a day in the calendar is clicked, the DayActivity is started. What I'm trying to do is, when 'submit' button in DayActivity is pressed an event with the day's date should be created and a dot under the day should appear. However, that doesn't happen. It works when I manually create an event using hardcoded dates and call the addEvent method on the calendar. Am I missing something? I'm relatively new to Android

    calenderFragment.java:

            compactCalendar.setListener(new CompactCalendarView.CompactCalendarViewListener() {
    
            @Override
            public void onDayClick(Date dateClicked) {
               
                String fullDateStr = dateFormatForFullDate.format(dateClicked); 
                try {
                    Date fullDate = dateFormatForFullDate.parse(fullDateStr);
                    timeInMillis = fullDate.getTime();
    
                } catch (ParseException e) {
                    e.printStackTrace();
                }
    
                Intent intent = new Intent(getActivity(),DayActivity.class);
             
                intent.putExtra("dateInMills", timeInMillis);  // here I'm just passing the days date in milliseconds to DayActivity
                startActivity(intent);
            }
    

    <...>

    DayActivity.java: <...>

         Intent intent = getIntent();
        long dateInMills = intent.getLongExtra("dateInMills", 0);
        dateTv.setText(date);
    
        doneBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
    
            //                Event ev = new Event(Color.parseColor("#613DC1"), dateInMills, "Cried");
           //                compactCalendar.addEvent(ev);
          //                this part doesn't work
    
             //   Toast.makeText(getApplicationContext(), "date: " + dateInMills, Toast.LENGTH_SHORT).show();
                //  date passed is correct
            }
    
    opened by RamintaMisiunaite 0
Owner
SundeepK
SundeepK
📅 Minimal Calendar - This calendar library is built with jetpack compose. Easy, simple, and minimal.

?? Minimal Calendar This calendar library is built with jetpack compose. Easy, simple, and minimal. Latest version The stable version of the library i

Minjae Kim 16 Sep 14, 2022
Standalone Android widget for picking a single date from a calendar view.

TimesSquare for Android Standalone Android widget for picking a single date from a calendar view. Usage Include CalendarPickerView in your layout XML.

Square 4.4k Dec 20, 2022
Android Week View is an android library to display calendars (week view or day view) within the app. It supports custom styling.

Android Week View Android Week View is an android library to display calendars (week view or day view) within the app. It supports custom styling. Fea

Raquib-ul Alam (Kanak) 3.4k Jan 3, 2023
CustomizableCalendar is a library that allows you to create your calendar, customizing UI and behaviour

CustomizableCalendar This library allows you to create a completely customizable calendar. You can use CustomizableCalendar to create your calendar, c

MOLO17 216 Dec 6, 2022
Kmpcalendar - A calendar library and views written for kotlin multiplatform

KMPCalendarView Minimal Kotlin Multiplatform project with SwiftUI, Jetpack Compo

Anmol Verma 2 Oct 7, 2022
A Jetpack Compose library for handling calendar component rendering.

Compose Calendar Compose Calendar is a composable handling all complexity of rendering calendar component and date selection. Due to flexibility provi

Bogusz Pawłowski 181 Dec 22, 2022
A better calendar for Android

Caldroid Caldroid is a fragment that display calendar with dates in a month. Caldroid can be used as embedded fragment, or as dialog fragment. User ca

Roomorama 1.4k Nov 29, 2022
Android open source calendar

Etar Calendar Etar (from Arabic: إِيتَار) is an open source material designed calendar made for everyone! Why? Well, I wanted a simple, material desig

null 1.5k Jan 4, 2023
📅 CosmoCalendar is a fully customizable calendar with a wide variety of features and displaying modes.

CosmoCalendar Made by Applikey Solutions Usage Customization Common Selection Current day Navigation buttons Weekend days Connected days Disabled days

Applikey Solutions 1.6k Dec 22, 2022
Demo app for a horizontal schedule(event) calendar

This is a demo project that showcases a horizontally laid out calendar that shows events in a timeline fashion. It is not a library, just a reference implementation for curious developers.

Halil Ozercan 188 Dec 26, 2022
A simple calendar with events, customizable widgets and no ads.

Simple Calendar A simple calendar with events and a customizable widget. A simple calendar with optional CalDAV synchronization. You can easily create

Simple Mobile Tools 3k Jan 4, 2023
Solutions for Muetzilla's Advent Calendar

Solutions for Muetzilla's Advent Calendar Link To the Advents Calendar Content Solutions for Muetzilla's Advent Calendar Content Problem 1 Problem 2 P

Marc Andri Fuchs 1 Mar 23, 2022
Calendar - A component for compose desktop

日历 一个用于compose-desktop的日历组件。 截图 feature DayPicker的动画 月份选择器错误提示 点击非本月的时间会跳到上个月 to

wwalkingg 1 Feb 7, 2022
A simple library which gives you custom design CalendarView with dialog functionality and event handlers.

CalendarView A simple library which gives you custom design CalendarView with dialog functionality and event handlers. 1: CalendarView Demo Screen 1.1

Shahzad Afridi (Opriday) 49 Oct 28, 2022
A material-styled android view that provisions picking of a date, time & recurrence option, all from a single user-interface.

SublimePicker A customizable view that provisions picking of a date, time & recurrence option, all from a single user-interface. You can also view 'Su

Vikram 2.3k Jan 4, 2023
A custom clock view with a circular slider.

Read this in other languages: English, 中文. ClockSlider A custom clock view with a circular slider. Supported Android Versions Android 4.0 Jelly Bean(A

Chien 5 Nov 13, 2022
Asimov-flagz-kt - Feature flags library based on Togglz library

Asimov Flagz Feature flags library based on Togglz library. Installation Gradle

Nicolas Bottarini 1 Jan 8, 2022
Joda-Time library with Android specialization

Android has built-in date and time handling - why bother with a library? If you've worked with Java's Date and Calendar classes you can probably answer this question yourself, but if not, check out Joda-Time's list of benefits.

Daniel Lew 2.6k Dec 9, 2022
Android NTP time library. Get the true current time impervious to device clock time changes

TrueTime for Android Make sure to check out our counterpart too: TrueTime, an NTP library for Swift. NTP client for Android. Calculate the date and ti

Instacart 1.3k Jan 4, 2023