Android library for the horizontal calendar like IOS calendar.
- single selection
- multiple selection
- long press selection
- control selection of particular items using selection manager
- check if the item is selected
- set selection
- and more...
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.muhmmadnabil:RowCalendar:1.0.0'
}
<dependency>
<groupId>com.github.muhmmadnabil</groupId>
<artifactId>RowCalendar</artifactId>
<version>1.0.0</version>
</dependency>
- create layout files, which will be defining how you calendar will look like
- basic item - selected and deselected
- if you need some special items, which will be displayed accroding to your logic you can add them
- special item - selected and deselected
<com.muhmmad.rowcalendar.calendar.RowCalendar
android:id="@+id/row_calendar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:longPress="true" />
val calendarViewManager = object :
CalendarViewManager {
override fun setCalendarResource(isToday: Boolean, isSelected: Boolean): Int {
return if (isToday) R.layout.today_calendar_item
else if (isSelected) R.layout.selected_calendar_item
else R.layout.calendar_item
}
override fun bindData(
holder: CalendarAdapter.ViewHolder,
date: Date,
position: Int,
isSelected: Boolean
) {
holder.itemView.findViewById<TextView>(R.id.tv_date_calendar_item).text =
DateHelper.getDay(date)
holder.itemView.findViewById<TextView>(R.id.tv_day_calendar_item).text =
DateHelper.getDayLetter(date)
}
}
rowCalendar.init(calendarViewManager)
rowCalendar.onClickListener {
Toast.makeText(root.context, "click", Toast.LENGTH_SHORT).show()
}
rowCalendar.onLongPressed {
Toast.makeText(root.context, "LongPress", Toast.LENGTH_SHORT).show()
}
}
includeCurrentDate
- include the current date with custom layout
multiSelection
- enable multiSelection
longPress
- enable longPress
getNextMonth()
- make the date on the calendar is the next month
getPreviousMonth()
- make the date on the calendar is the previous month
onClickListener()
- Handle onClickListener
onLongPressed
- Handle onLongPress
setCalendarResource()
- set the layouts of the calendar
bindData()
- Bind the data of the items in calendar
You can use DateUtils class when you want get some values from date.
getDayName(date: Date)
- returns day name, for example Friday, Thursday, Monday, etc...
getDay3LettersName(date: Date)
- returns day abbreviation, for example Fri, Thu, Mon, etc...
getDayLetter(date: Date)
- returns day abbreviation, for example F, T, M, S, etc...
getMonthNumber(date: Date)
- returns month number, for example 1, 3, 12, 9, etc...
getMonthName(date: Date)
- returns month name, for example December, September, January, etc...
- the best way to submit a patch is to send me a pull request
- to report a specific problem or feature request, open a new issue on Github