Customizable calendar with animations and ability to select a day, a week, a month or a custom range

Overview

📅 RangeCalendarView




A customizable, easy-to-use calendar with range selection

Screenshots

Getting started

This library is available on Maven Central, add the following dependency:

implementation 'io.github.pelmenstar1:rangeCalendar:0.9.2'

Define RangeCalendarView in your XML layout:

<io.github.pelmenstar1.RangeCalendarView 
        android:id="@+id/picker"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

Get notified when the date or range are selected:
(In example, the methods return true to mark that selection is valid. More about it)

calendar.onSelectionListener = object : RangeCalendarView.OnSelectionListener {
    override fun onSelectionCleared() {
    }

    override fun onDaySelected(year: Int, month: Int, day: Int): Boolean {
        return true
    }

    override fun onWeekSelected(
        weekIndex: Int,
        startYear: Int,
        startMonth: Int,
        startDay: Int,
        endYear: Int,
        endMonth: Int,
        endDay: Int
    ): Boolean {
        return true
    }

    override fun onMonthSelected(year: Int, month: Int): Boolean {
        return true
    }

    override fun onCustomRangeSelected(
        startYear: Int,
        startMonth: Int,
        startDay: Int,
        endYear: Int,
        endMonth: Int,
        endDay: Int
    ): Boolean {
        return true
    }
}

Demo

Try it yourself

Selection view

It's a view that will be shown when user selects date or range.
Visual example:

To keep information on that view relevant, use getOnSelectionListener()/setOnSelectionListener()

  • getSelectionView()/setSelectionView() to assign or get the view.
  • getSelectionViewTransitionDuration()/setSelectionViewTransitionDuration() to assign or get duration (in milliseconds) of selection view show/hide animation
  • getSelectionViewTransitionInterpolator()/setSelectionViewTransitionInterpolator() to assign or get time interpolator of selection show/hide animation
  • getSelectionViewLayoutParams()/getSelectionViewLayoutParams() to assign or get layout params for the view
  • hasSelectionViewClearButton()/setHasSelectionViewClearButton() to get or set whether on selection (if selection view is not null) 'next month' button wiil become 'clear selection' button.

Minimum and maximum dates

  • getMinDateEpoch()/setMinDateEpoch() to get or set minimum date represented in epoch days (Amount of days since 1 January 1970)
  • getMaxDateEpoch()/setMaxDateEpoch() to get or set maximum date represented in epoch days (Amount of days since 1 January 1970)
  • getMinDate()/setMinDate() to get or set minimum date represented as LocalDate. Note that, it can be used from API 26+
  • getMaxDate()/setMaxDate() to get or set maximum date represented as LocalDate. Note that, it can be used from API 26+
  • getMinDate(Calendar)/getMaxDate(Calendar) to get minimum/maximum date. The date will be set to the given Calendar
  • setMinDate(Calendar)/setMaxDate(Calendar) to set minimum/maximum date represented as Calendar.
  • setMinDate(year, month, dayOfMonth)/setMaxDate(year, month, dayOfMonth) to set minimum/maximum date by raw values.
    • year should be in range of [1970; 32767]
    • month is 1-based (in range of [1; 12])
    • year is 1-based (in range of [1; days in month])

Listener

Use getOnSelectionListener()/setOnSelectionListener() to get or set the listener. In all methods, month and day of month are 1-based.

  • onSelectionCleared() fires when selection is cleared.
  • onDaySelected(year, month, day) fires when day is selected.
  • onWeekSelected(weekIndex, startYear, startMonth, startDay, endYear, endMonth, endDay) fires when week is selected.
    • weekIndex - index of selected week, 0-based
  • onMonthSelected(year, month) fires when month is selected.
  • onCustomRangeSelected(startYear, startMonth, startDay, endYear, endMonth, endDay) fires when custom range is selected

The methods (except onSelectionCleared()) should return boolean that indicate whether the selection is valid or not.

Animations

They are enabled by default (currently they cannot be disabled).

  • getCommonAnimationDuration()/setCommonAnimationDuration() to get or set duration (in milliseconds) of common animations
  • getCommonAnimationInterpolator()/setCommonAnimationInterpolator() to get or set time interpolator of common animations. By default, it's linear.
  • getHoverAnimationDuration()/setHoverAnimationDuration() to get or set duration (in milliseconds) of hover animation
  • getHoverAnimationInterpolator()/setHoverAnimationInterpolator() to get or set time interpolator of hover animation. By default, it's linear.

Changing page of calendar

  • moveToPreviousMonth(withAnimation=true) to slide to previous month (if it's possible) with animation or not (it's controlled by withAnimation flag)
  • moveToNextMonth(withAnimation=true) to slide to next month (if it's possible) with animation or not (it's controlled by withAnimation flag)
  • setYearAndMonth(year, month, withAnimation=true) to slide to given year & month with animation or not (it's controlled by withAnimation flag). If given page is out of enabled range, selected page will remain the same

Managing selection through the code

  • selectDay(epochDay)/selectDay(LocalDate)/selectDay(Calendar) to select a day. If the day is out of enabled range, it won't be selected and listeners won't be fired.
  • selectWeek(year, month, weekIndex) to select a week.
    • year should be in range of [1970; 32767]
    • month is 1-based
    • weekIndex is 0-based
  • selectMonth(year, month) to select a month.
    • year should be in range of [1970; 32767]
    • month is 1-based
  • selectCustom(startEpochDays, endEpochDays)/selectCustom(Calendar startDate, Calendar endDate)/selectCustom(LocalDate startDate, LocalDate endDate) to select custom range defined by epoch days/LocalDate/Calendar. The range should fit in single month, otherwise the exception will be thrown.
  • clearSelection() to clear selection.

Movement

  • Double-touch to select a week
  • Long-press to start selecting a custom range.
  • Click on month information view (on top center) to select month

Other

  • allowedSelectionTypes() returns special object that manages allowed types of selection. Example:

    calendar.allowedSelectionTypes().month(false).customRange(true)

    By code above, we disabled month and custom range selection. If selection type become disabled, it'll be automatically cleared.

    • cell(boolean) sets whether cell can be selected
    • week(boolean) sets whether week can be selected
    • month(boolean) sets whether month can be selected
    • customRange(boolean) sets whether custom range can be selected

    By default all types of selection are allowed.

  • getVibrateOnSelectingCustomRange()/setVibrateOnSelectingCustomRange() to get or set whether the device should vibrate on start of selecting custom range.

  • getClickOnCellSelectionBehavior()/setClickOnCellSelectionBehavior() to get or set behaviour when user (note, not from code) clicks on already selected cell. Use constants from ClickOnCellSelectionBehavior:

    • NONE - nothing happens
    • CLEAR - selection clears

Style

Attribute Description
rangeCalendar_selectionColor Color of background of selection shape
rangeCalendar_dayNumberTextSize Text size of text in cells (day number)
rangeCalendar_inMonthDayNumberColor Color of day number which is in selected month range
rangeCalendar_outMonthDayNumberColor Color of day number which is out of selected month range
rangeCalendar_disabledMonthDayNumberColor Color of day number which is out of enabled range
rangeCalendar_todayColor Color of day number which represents today
rangeCalendar_weekdayColor Color of weekday row (Mo, Tue, Wed...)
rangeCalendar_weekdayTextSize Text size of weekday row (Mo, Tue, Wed...)
rangeCalendar_hoverColor Color of background of hover shape
rangeCalendar_hoverOnSelectionColor Color of background of hover shape that is in selection
rangeCalendar_cellSize Size of cell
rangeCalendar_cellSize Size of cell
rangeCalendar_weekdayType Type of weekday.
Format of weekdays is very dependent on locale. In examples, English locale is used.
  • shortName (WeekdayType.SHORT) - weekdays will look like Mo, Tue, Wed.
  • narrowName (WeekdayType.NARROW) - weekdays will look like M, T, W,.
rangeCalendar_roundRectRadiusRatio Round rect radius of selected is determined by this fraction multiplied by cell size. By default, it's 0.5

License

MIT License

Copyright (c) 2022 Khmaruk Oleg

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.
You might also like...

Render After Effects animations natively on Android and iOS, Web, and React Native

Render After Effects animations natively on Android and iOS, Web, and React Native

Lottie for Android, iOS, React Native, Web, and Windows Lottie is a mobile library for Android and iOS that parses Adobe After Effects animations expo

Jan 3, 2023

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

Jan 3, 2023

A little of Java content every day for a hundred days.

100 Days of Java Table of Contents Day 1 - Generating a random number within a specific range. Day 2 - Formatting a LocalDateTime object. Day 3 - Sche

Dec 27, 2022

Stoibot is a JAVA based bot to tweet every day a quote from a stoic author

Stoibot is a JAVA based bot to tweet every day a quote from a stoic author. The target of the bot is create a simple mysql and java based system to test some libraries and the mysql driver.

Feb 21, 2022

Photo live wallpaper with auto dark mode and power-efficient animations

Photo live wallpaper with auto dark mode and power-efficient animations

Pallax Android: Photo Live Wallpaper Pallax Android is an Android app that lets you convert your current static home screen background into a stunning

Dec 17, 2022

Completely customizable lightshows for everyone

Completely customizable lightshows for everyone

Please view the new WIKI for set-up instructions! Music visualiser plugin for vanilla minecraft which uses beat saber beatmaps (including chroma suppo

Dec 28, 2022

Better performance with lottie animations using RLottie in react-native

Better performance with lottie animations using RLottie in react-native

🌈 react-native-rlottie Features ▶️ Uses rlottie to run lottie animations 🌠 rlottie creates rasterized bitmaps for each frame of the animation (inste

Dec 7, 2022

Plugin for Spigot, PaperMC, BungeeCord and Velocity to create custom MOTDs, playercount message and playercount hover with priorities and conditions.

AdvancedServerList AdvancedServerList is a server and proxy plugin that allows you to create custom MOTDs and more in your server list with priority a

Dec 14, 2022

Simple springboot API for addressBook. Supports all REST controllers and have custom error handling for every specific case, also supports redis caching.

Simple springboot API for addressBook. Supports all REST controllers and have custom error handling for every specific case, also supports redis caching.

AddressBook-SpringBoot-API Simple Springboot API for addressBook with redis cache. Supports all REST controllers and have custom error handling for ev

Jan 21, 2022
Comments
  • Class referenced in the layout file, com.github.pelmenstar1.RangeCalendarView, was not found in the project or the libraries

    Class referenced in the layout file, com.github.pelmenstar1.RangeCalendarView, was not found in the project or the libraries

    Hi, I'm trying this library but getting error while adding the calendar in XML. I'm also getting this message after sync Please remove usages ofjcenter()Maven repository from your build scripts and migrate your build to other Maven repositories. This repository is deprecated and it will be shut down in the future. See http://developer.android.com/r/tools/jcenter-end-of-service for more information. Currently detected usages in: root project 'RangeCalendarTest', project ':app'

    opened by shahzad1 2
  • Decoration support

    Decoration support

    • [x] Initial support
    • [x] Animations
    • [x] API to add (remove) multiple decorations to (from) one cell, remove all decorations from one cell. Add animations for all that.
    • [x] API add decorations at certain position in the cell
    • [x] Circle decoration
    • [x] Text decoration
    opened by pelmenstar1 0
  • Refactor and simplify

    Refactor and simplify

    • Make code more scalable and simple.
    • Add comments
    • Use more inline classes
    • Fix visibility of some util functions
    • Move some files that contains util functions to utils package
    opened by pelmenstar1 0
  • Future goals

    Future goals

    • [ ] Allow cell to have different width and height
    • [ ] Introduce non-consecutive ranges
    • [ ] Allow to change text alignment in a cell.
    • [ ] Connectable transitions (low priority)
    opened by pelmenstar1 0
Releases(0.9.3)
Owner
Oleg Khmaruk
Oleg Khmaruk
Find out what the sign is from a specific day and month

WhatMySign Find out what the sign is from a specific day and month Preview How to use To run it is simple, first download the file of the program by c

null 1 Feb 3, 2022
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
This app based on Java to make the life of firefighters easier by implementing features which they need in their day-to-day life

Fire Rescue App This app based on Java to make the life of firefighters easier by implementing features which they need in their day-to-day life. Scre

Senith Umesha 2 Jul 24, 2022
Always High is a College help app catered towards helping college students in managing their day-to-day hassle!

Always High Always High is a College help app cattered towards helping the college students in managing their day-to-day hassle! Problem : In the onli

Tirth Joshi 1 Mar 16, 2022
DSMovie is a full stack web and mobile application built during Spring React Week, an event organized by DevSuperior

projeto-DSMovie Sobre o projeto DSMovie é uma aplicação full stack web e mobile construída durante a Semana Spring React, evento organizado pela DevSu

Matheus Maia Alvarez 7 Apr 18, 2022
Sportheca Mobile DEV Week - Simulador de Partidas 🎲

Sportheca Mobile DEV Week - Simulador de Partidas ?? Projeto desenvolvido no bootcamp Sportheca da DIO. Desenvolvimento Mobile Nativo Para Android Obj

Lucas Magalhães 8 Aug 5, 2022
Projeto criado no Santander Dev Week 2022 + DIO com o intuito de desenvolver uma camada de APIs (backend) que será utilizada pelo frontend.

Santader Dev Week + DIO 2022 - APIs Backend da aplicação de movimentação financeira Este repositório contém o backend da aplicação que foi desenvolvid

Pedro Antunes Negrão 2 Sep 7, 2022
Users can create and sign up for giveaways which, upon expiring, will select a random winner from the pool of entries

PROJECT NAME Readaway Project Description Users can create and sign up for giveaways which, upon expiring, will select a random winner from the pool o

null 2 Apr 4, 2022
Shows Image you select on Top of every Window by holding the button you choose

ImageOnTop What it does? Shows Image you select on Top of every Window by holding the button you choose. How to use it? Press a keyboard key you want

null 1 Jan 23, 2022
A plugin that adds Qualities to Items, along with the ability for the user to create their own.

ItemQualities ItemQualities is a Minecraft Plugin for 1.18+ Servers that adds a special functionality to Damagable items. Inspired by the Quality Tool

Abraxas 7 Jul 1, 2022