Android Custom Calendar with events
Some links for android cutom calendarviews
Roboto Calendar View
Android Roboto Calendar View provides an easy and customizable calendar view using the awesome library Calligraphy for fonts
Sample
A sample application is available inside of the library
Compatibility
This library is compatible from API 14.
Usage
Take a look of the sample Activity.
You can override any style and customize your calendar.
Gradle
RobotoCalendarView uses the awesome tool [Jitpack] (https://jitpack.io/#marcohc/robotocalendarview)
This library uses the awesome tool
Add the repository to your general build.gradle:
repositories {
maven {
url "https://jitpack.io"
}
}
And then add the library in your specific project build.gradle:
compile 'com.github.marcohc:robotocalendarview:<release>'
Simple Calendar
A simple calendar with events and a customizable widget.
An offline calendar without any other calendar integration. You can easily create recurring events and setup reminders, it can also display week numbers.
Contains a resizable 4x4 widget where you can customize the color of the text, as well as the alpha and the color of the background.
Contains no ads or unnecessary permissions. It is fully open-source, provides customizable colors.
The Storage permission is needed only for exporting or importing events from .ics files.
The Contacts permission is used only at importing contact birthdays and anniversaries.
This app is just one piece of a bigger series of apps. You can find the rest of them at http://www.simplemobiletools.com
Material-Calendar-View
Material-Calendar-View is a simple and customizable calendar widget for Android based on Material Design. The widget has two funcionalities: a date picker to select dates (available as an XML widget and a dialog) and a classic calendar. The date picker can work either as a single day picker, many days picker or range picker.
We described a simple usage of the component in this article.
Features
- Material Design
- Single date picker
- Many dates picker
- Range picker
- Events icons
- Fully colors customization
How to migrate from previous version to 1.4.0?
We have renamed setOnPreviousButtonClickListener() and setOnForwardButtonClickListener() so please refer to Previous and forward buttons listeners.
How to use?
Make sure you are using the newest com.android.support:appcompat-v7.
Make sure you have defined the jcenter() repository in project’s build.gradle file:
allprojects {
repositories {
jcenter()
}
}
Add the dependency to module’s build.gradle file:
dependencies {
compile 'com.applandeo:material-calendar-view:1.4.0'
}
To your XML layout file add:
<com.applandeo.materialcalendarview.CalendarView
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Adding events with icons:
List<EventDay> events = new ArrayList<>();Calendar calendar = Calendar.getInstance();
events.add(new EventDay(calendar, R.drawable.sample_icon));CalendarView calendarView = (CalendarView) findViewById(R.id.calendarView);
calendarView.setEvents(events);
Clicks handling:
calendarView.setOnDayClickListener(new OnDayClickListener() {
@Override
public void onDayClick(EventDay eventDay) {
Calendar clickedDayCalendar = eventDay.getCalendar();
}
});
Getting a selected days in the picker mode:
If you want to get all selected days, especially if you use multi date or range picker you should use the following code:
List<Calendar> selectedDates = calendarView.getSelectedDates();
…or if you want to get the first selected day, for example in case of using single date picker, you can use:
Calendar selectedDate = calendarView.getFirstSelectedDate();
Setting a current date:
Calendar calendar = Calendar.getInstance();
calendar.set(2019, 7, 5);
calendarView.setDate(calendar);
Setting minumum and maximum dates:
Calendar min = Calendar.getInstance();
Calendar max = Calendar.getInstance();calendarView.setMinimumDate(min);
calendarView.setMaximumDate(max);
Setting disabled dates:
List<Calendar> calendars = new ArrayList<>();
calendarView.setDisabledDays(calendars);
Previous and forward page change listeners:
calendarView.setOnPreviousPageChangeListener(new OnCalendarPageChangeListener() {
@Override
public void onChange() {
...
}
});calendarView.setOnForwardPageChangeListener(new OnCalendarPageChangeListener() {
@Override
public void onChange() {
...
}
});
Customization
If you want to use calendar in the picker mode, you have to use the following tags:
app:type="one_day_picker"
app:type="many_days_picker"
app:type="range_picker"
Colors customization:
- Header color:
app:headerColor="[color]"
- Header label color:
app:headerLabelColor="[color]"
- Previous button image resource:
app:previousButtonSrc="[drawable]"
- Forward button image resource:
app:forwardButtonSrc="[drawable]"
- Abbreviations bar color:
app:abbreviationsBarColor="[color]"
- Abbreviations labels color:
app:abbreviationsLabelsColor="[color]"
- Calendar pages color:
app:pagesColor="[color]"
- Selection color in picker mode:
app:selectionColor="[color]"
- Selection label color in picker mode:
app:selectionLabelColor="[color]"
- Days labels color:
app:daysLabelsColor="[color]"
- Color of visible days labels from previous and next month page:
app:anotherMonthsDaysLabelsColor="[color]"
- Disabled days labels color:
app:disabledDaysLabelsColor="[color]"
- Today label color:
app:todayLabelColor="[color]"
Translations:
To translate months names, abbreviations of days, “TODAY”, “OK” and “CANCEL” buttons, just add below tags to your strings.xml
file:
<string name="material_calendar_monday">M</string>
<string name="material_calendar_tuesday">T</string>
<string name="material_calendar_wednesday">W</string>
<string name="material_calendar_thursday">T</string>
<string name="material_calendar_friday">F</string>
<string name="material_calendar_saturday">S</string>
<string name="material_calendar_sunday">S</string><array name="material_calendar_months_array">
<item>January</item>
<item>February</item>
<item>March</item>
<item>April</item>
<item>May</item>
<item>June</item>
<item>July</item>
<item>August</item>
<item>September</item>
<item>October</item>
<item>November</item>
<item>December</item>
</array><string name="material_calendar_today_button">Today</string>
<string name="material_calendar_positive_button">OK</string>
<string name="material_calendar_negative_button">Cancel</string>
Date Picker Dialog
DatePickerBuilder builder = new DatePickerBuilder(this, listener)
.pickerType(CalendarView.ONE_DAY_PICKER);DatePicker datePicker = builder.build();
datePicker.show();
To use another picker type replace CalendarView.ONE_DAY_PICKER
with CalendarView.MANY_DAYS_PICKER
or CalendarView.RANGE_PICKER
.
Getting date handling:
private OnSelectDateListener listener = new OnSelectDateListener() {
@Override
public void onSelect(List<Calendar> calendars) {
...
}
};
Customization:
new DatePickerBuilder(this, listener)
.date(Calendar.getInstance()) // Initial date as Calendar object
.minimumDate(Calendar.getInstance()) // Minimum available date
.maximumDate(Calendar.getInstance()) // Maximum available date
.disabledDays(List<Calendar>) /// List of disabled days
.headerColor(R.color.color) // Color of the dialog header
.headerLabelColor(R.color.color) // Color of the header label
.previousButtonSrc(R.drawable.drawable) // Custom drawable of the previous arrow
.forwardButtonSrc(R.drawable.drawable) // Custom drawable of the forward arrow
.previousPageChangeListener(new OnCalendarPageChangeListener(){}) // Listener called when scroll to the previous page
.forwardPageChangeListener(new OnCalendarPageChangeListener(){}) // Listener called when scroll to the next page
.abbreviationsBarColor(R.color.color) // Color of bar with day symbols
.abbreviationsLabelsColor(R.color.color) // Color of symbol labels
.pagesColor(R.color.sampleLighter) // Color of the calendar background
.selectionColor(R.color.color) // Color of the selection circle
.selectionLabelColor(R.color.color) // Color of the label in the circle
.daysLabelsColor(R.color.color) // Color of days numbers
.anotherMonthsDaysLabelsColor(R.color.color) // Color of visible days numbers from previous and next month page
.disabledDaysLabelsColor(R.color.color) // Color of disabled days numbers
.todayLabelColor(R.color.color) // Color of the today number
.dialogButtonsColor(R.color.color); // Color of "Cancel" and "OK" buttons
Changelog
Version 1.4.0:
- More color customization (abbreviations, calendar pages, labels colors)
- Changed onNavigationButtonClickListeners to onCalendarPageChangeListeners
- Added page change listeners to dialog pickers
- Added onDayClickListener to pickers (not dialog pickers)
- Added ability to insert list of disabled days
Material Calendar View
A Material design back port of Android’s CalendarView. The goal is to have a Material look and feel, rather than 100% parity with the platform’s implementation.
Installation
Step 1. Add the JitPack repository to your build file
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.prolificinteractive:material-calendarview:${version}'
}
Usage
- Add
MaterialCalendarView
into your layouts or view hierarchy. - Set a
OnDateSelectedListener
or callMaterialCalendarView.getSelectedDates()
when you need it.
Example:
<com.prolificinteractive.materialcalendarview.MaterialCalendarView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:mcv_showOtherDates="all"
app:mcv_selectionColor="#00F"
/>
Documentation
Make sure to check all the documentation available here.
Customization
One of the aims of this library is to be customizable. The many options include:
- Define the view’s width and height in terms of tile size
- Single or Multiple date selection, or disabling selection entirely
- Showing dates from other months or those out of range
- Setting the first day of the week
- Show only a range of dates
- Customize the top bar
- Custom labels for the header, weekdays, or individual days
Events, Highlighting, Custom Selectors, and More!
All of this and more can be done via the decorator api. Please check out the decorator documentation.
Recent Changes
Major Change in 1.5.0
We recently updated to the latest gradle and decided to move over our libraries to the hosting service Jitpack. Please refer to the installation section for more details.
Major Change in 1.4.0
- Breaking Change:
setFirstDayOfWeek
,setMin/MaxDate
, andsetCalendarDisplayMode
are moved to aState
object. This was necessary because it was unclear that these were not simple setters--individually, they were side effecting and triggered full adapter/date range recalculations. Typical usage of the view involves setting all these invariants up front duringonCreate
and it was unknown to the user that setting all 4 of these would create a lot of waste. Not to mention certain things were side effecting--some would reset the current day or selected date. As a result, the same 4 methods called in a different order could result in a different state, which is bad. - For most cases you will simply need to replace setting those invariants with:
- mcv.state().edit() .setFirstDayOfWeek(Calendar.WEDNESDAY) .setMinimumDate(CalendarDay.from(2016, 4, 3)) .setMaximumDate(CalendarDay.from(2016, 5, 12)) .setCalendarDisplayMode(CalendarMode.WEEKS) .commit();
mcv.state().edit()
will retain previously set values;mcv.newState()
will create a new state using default values. Callingcommit
will trigger the rebuild of adapters and date ranges. It is recommended these state changes occur as the first modification to MCV (before configuring anything else like current date or selected date); we make no guarantee those modifications will be retained when the state is modified.- See CUSTOMIZATION_BUILDER for usage details.
- New:
setSelectionMode(SELECTION_MODE_RANGE)
was added to allow 2 dates to be selected and have the entire range of dates selected. Much thanks to papageorgiouk for his work on this feature.
Custom Android Calendar
#Usage
Maven repo
maven {
url "https://dl.bintray.com/riontech/maven"
}
Add the dependency to your build.gradle.
dependencies {
compile 'com.riontech:calendar:1.0'
}
Add the indicator to your layout.
<com.riontech.calendar.CustomCalendar
android:id="@+id/customCalendar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:endMonth="07"
app:endYear="2016"
app:startMonth="01"
app:startYear="2016" />
Create object of CustomCalendar in your activity
private CustomCalendar customCalendar;
In your acitivty onCreate initialize the object and set eventDate with count. And add it to customCalendar object by using addAnEvent method.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
customCalendar = (CustomCalendar) findViewById(R.id.customCalendar); String[] arr = {"2016-06-10", "2016-06-11", "2016-06-15", "2016-06-16", "2016-06-25"};
for (int i = 0; i < 5; i++) {
int eventCount = 3;
customCalendar.addAnEvent(arr[i], eventCount, getEventDataList(eventCount));
}
}
TODOs
- Add Event with Plus button
- Adding Reminders for Event, Birthday, etc
- Awesome UI-UX
CustomizableCalendar
This library allows you to create a completely customizable calendar.
You can use CustomizableCalendar
to create your calendar, customizing UI and behaviour.
Features
- Custom header (should be implemented by the user);
- Custom sub view (month name by default);
- Custom weekly days view;
- Custom date view;
- Possibility to implement selection on day click;
- Possibility to implement weekly day calculation;
- Receive updates of Calendar (with AUCalendar);
- Every change to AUCalendar is notified and automatically refreshes UI;
Limitations
- Only portrait orientation is supported
Gradle
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}dependencies {
compile 'com.github.MOLO17:CustomizableCalendar:v0.1.4'
}
Dependencies
- RecyclerView
- Joda-Time
- RxJava2
- ButterKnife used on version <= 0.1.3
- Retrolambda used on version <= 0.1.3
Usage
Add to your layout
XML
Add CustomizableCalendar to your layout
<com.molo17.customizablecalendar.library.components.CustomizableCalendar
android:id="@+id/customizable_calendar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Java
First of all you should create a class that implements ViewInteractor
interface (you can find the explanation in the How to customize > Java
section).
After that go in the Activity/Fragment where you added the CustomizableCalendar
View; here you should specify the first month and the last month, to do this, create a Calendar
(located in com.molo17.customizablecalendar.library.model
) object.
An example of CustomizableCalendar
init is the following:
...@BindView(R.id.customizable_calendar)
CustomizableCalendar customizableCalendar;private CompositeDisposable subscriptions;...@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this); DateTime today = new DateTime(); // setting up first and last month that must be showed in the calendar
DateTime firstMonth = today.withDayOfMonth(1);
DateTime lastMonth = today.plusMonths(3).withDayOfMonth(1); // create the Calendar obj and setting it up with some configs like:
// - first selected day
// - last selected day
// - multiple selection final Calendar calendar = new Calendar(firstMonth, lastMonth);
calendar.setFirstSelectedDay(today.plusDays(4)); // if you don't want the multiple selection mode just skip the 2 lines below
calendar.setLastSelectedDay(today.plusDays(6));
calendar.setMultipleSelection(true); // create a ViewInteractor obj needed to interact with the CustomizableCalendar
final YourViewInteractorClass calendarViewInteractor = new YourViewInteractorClass(); // create an AUCalendar object (a Calendar wrapper that operates as a singleton and provides all the updates)
AUCalendar auCalendar = AUCalendar.getInstance(calendar); // this is needed to receives all Calendar updates (using RxJava 2)
subscriptions.add(
auCalendar.observeChangesOnCalendar().subscribe(new Consumer<AUCalendar.ChangeSet>() {
@Override
public void accept(AUCalendar.ChangeSet changeSet) throws Exception {
// with ChangeSet you can be aware of which Calendar fields are changed
// you can use changeSet.isFieldChanged(...) passing the name of the field;
// name of the fields can be retrieved using CalendarFields interface;
// AUCalendar is already updated because it's a singleton,
// so for retrieving the updated data you can just use AUCalendar getters
}
})
); // injecting the ViewInteractor to the CustomizableCalendar View
customizableCalendar.injectViewInteractor(calendarViewInteractor)
}@Override
protected void onDestroy() {
super.onDestroy();
subscriptions.clear();
}...
How to customize
XML
If you want to customize the components you should create a separeted layout and add the reference to the customizable_calendar
View with the tag app:layout="@layout/your_layout"
An example of a custom layout is the following:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginEnd="30dp"
android:layout_marginStart="30dp"
android:orientation="vertical"> <com.molo17.customizablecalendar.library.components.HeaderView
android:id="@android:id/primary"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> <com.molo17.customizablecalendar.library.components.SubView
android:id="@android:id/text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp" /> <com.molo17.customizablecalendar.library.components.WeekDaysView
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp" /> <com.molo17.customizablecalendar.library.components.CalendarRecyclerView
android:id="@android:id/content"
android:layout_width="match_parent"
android:layout_height="@dimen/customizable_calendar_height"
android:layout_marginTop="15dp" /></LinearLayout>
NOTE that ids must not be different from the ones above, so:
@android:id/primary
for HeaderView;@android:id/text1
for WeekDaysView;@android:id/text2
for SubView;@android:id/content
for CalendarRecyclerView;
HeaderView
First (red) rectangle of the screenshot above.
It’s a RelativeLayout
, you should create your own layout.
WeekDaysView
Third (light blue) rectangle of the screenshot above.
It’s a RecyclerView
, the ViewHolder item is already implemented.
You can create your own ViewHolder layout using a RelativeLayout
with a TextView
that has @android:id/summary
as id.
SubView
Second (green) rectangle of the screenshot above.
It’s a RelativeLayout
, implemented by default with the name of the month centered.
If you want to create your own layout make sure to have a TextView
with id @android:id/summary
.
CalendarRecyclerView
Fourth (blue) rectangle of the screenshot above.
It’s a RelativeLayout
, implemented by default with a LinearLayout
(with a GridLayout
inside) for the month and a RelativeLayout
for the day.
If you want to create your own month layout you can specify app:month_layout="@layout/your_layout"
for the month and app:cell_layout="@layout/your_layout"
for the day.
Make sure to use @android:id/widget_frame
as id for the GridView
and @android:id/background
, @android:id/startSelectingText
, @android:id/stopSelectingText
, @android:id/title
respectively for single selection background, first day selection background (in multiple selection mode), last day selection background (in multiple selection mode) and the TextView
where the day is displayed.
Java
All code customization can be applied using the ViewInteractor
.
Here are listed all of the methods with a small description:
void onCustomizableCalendarBindView(View view)
Here you can customize theCustomizableCalendar
View.
This method is called aftercustomizableCalendar.injectViewInteractor(...)
.void onHeaderBindView(ViewGroup view)
Here you can customize theHeaderView
View, inflating your layout etc...
This method is called afterheaderView.injectViewInteractor(...)
.void onWeekDaysBindView(View view)
Here you can customize theWeekDays
View.
This method is called afterweekDays.injectViewInteractor(...)
.void onWeekDayBindView(WeekDaysViewAdapter.WeekDayVH holder, String weekDay)
Here you can customize theWeekDayVH
ViewHolder.
This method is called afteronBindViewHolder
ofWeekDaysViewAdapter
.void onSubViewBindView(View view, String month)
Here you can customize theSubView
View.
This method is called afteronMonthChanged
.void onCalendarBindView(View view)
Here you can customize theCalendarRecyclerView
View.
This method is called aftercalendarRecyclerView.injectViewInteractor(...)
.void onMonthBindView(View view)
Here you can customize theMonthGridView
View.
This method is called afteronCreateViewHolder
ofCalendarViewAdapter
.View onMonthCellBindView(View view, CalendarItem currentItem)
Here you can customize theGridViewCell
View.
This method is called in thegetView
ofMonthAdapter
, you must return the customized view.boolean hasImplementedMonthCellBinding()
Here you should returntrue
if you have implemented the above method (onMonthCellBindView
).
This method is called in thegetView
method ofMonthAdapter
.List<CalendarItem> calculateDays(int year, int month, int firstDayOfMonth, int lastDayOfMonth)
Here you can calculate the days of the month (if you want for example to includeSaturday
andSunday
)
This method is called in thegetView
ofMonthAdapter
.boolean hasImplementedDayCalculation()
Here you should returntrue
if you have implemented the above method (calculateDays
).
This method is called in therefreshDays
method ofMonthAdapter
.int setSelected(boolean multipleSelection, DateTime dateSelected)
Here you can calculate the selection of the day.
This method is called in thesetSelected
method ofMonthAdapter
.
You must return 0, 1 or -1 respectively forfirst selection
,last selection
andno selection
.boolean hasImplementedSelection()
Here you should returntrue
if you have implemented the above method (setSelected
).
This method is called in thesetSelected
method ofMonthAdapter
.String formatWeekDayName(String nameOfDay);
Here you can format the name of the week day.
This method is called afterinjectViewInteractor
method ofWeekDaysView
.
You should return the formatted name of the week day.boolean hasImplementedWeekDayNameFormat()
Here you should returntrue
if you have implemented the above method (formatWeekDayName
).
This method is called afterinjectViewInteractor
method ofWeekDaysView
.View getMonthGridView(View rootView)
Here you can create your customizedMonthGridView
.
You should return aMonthGridView
.
This method is called in theonCreateViewHolder
method ofCalendarViewAdapter
.