This library uses Android X depencies and is written in Kotlin.
Add a dependency to your build.gradle file:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.michael-winkler:EventCalendar:1.6.0'
}
import com.nmd.eventCalendar.EventCalendarView
You can create a new EventCalendarView
inside your XML-Layout like this:
<com.nmd.eventCalendar.EventCalendarView
android:id="@+id/eventCalendarView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:ecv_count_background_text_color="@android:color/white"
app:ecv_count_background_tint_color="@android:color/holo_blue_light"
app:ecv_count_visible="true"
app:ecv_current_day_background_tint_color="@android:color/holo_red_dark"
app:ecv_current_day_text_color="@android:color/white"
app:ecv_disallow_intercept="false"
app:ecv_edge_to_edge_enabled="true"
app:ecv_event_item_automatic_text_color="true"
app:ecv_event_item_text_color="@android:color/black"
app:ecv_event_item_dark_text_color="@android:color/black"
app:ecv_header_visible="true"
app:ecv_calendar_week_visible="true"/>
Or if you just want the current calendar week you can use this one:
<com.nmd.eventCalendar.EventCalendarSingleWeekView
android:id="@+id/eventCalendarView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:ecv_count_background_text_color="@android:color/white"
app:ecv_count_background_tint_color="@android:color/holo_blue_light"
app:ecv_count_visible="true"
app:ecv_current_day_background_tint_color="@android:color/holo_red_dark"
app:ecv_current_day_text_color="@android:color/white"
app:ecv_event_item_automatic_text_color="true"
app:ecv_event_item_text_color="@android:color/black"
app:ecv_event_item_dark_text_color="@android:color/black"
app:ecv_header_visible="true"
app:ecv_calendar_week_visible="true"/>
Here you can see all custom app
parameters which you can use:
https://github.com/michael-winkler/EventCalendar/blob/main/library/src/main/res/values/attr.xml
The EventCalendarSingleWeekView
can use all app:evc
too except ecv_disallow_intercept
and ecv_edge_to_edge_enabled
.
Also the EventCalendarSingleWeekView
displays only Events
where the date is in range of the current calendar week.
You don't need anything to do by yourself. The library will filter automatically the events for the
week view by itself.
Now in your class you can get a reference to it like this:
binding.eventCalendarView.addOnDayClickListener(object :
EventCalendarDayClickListener {
override fun onClick(day: Day) {
// val eventList = binding.eventCalendarView.events.filter { it.date == day.date }
// You can use this to get the events for the selected day
Log.i("ECV", "TEST 1: " + day.date)
}
})
The EventCalendarDayClickListener
listener works also for the EventCalendarSingleWeekView
.
The Day
object structure is following:
data class Day(
/**
* eg: 31
*/
val value: String,
/**
* eg: true | false
*/
val isCurrentMonth: Boolean,
/**
* eg: true | false
*/
var isCurrentDay: Boolean,
/**
* eg: 31.12.2024
*/
var date: String,
)
You can also watch to calendar scroll changes.
binding.eventCalendarView.addOnCalendarScrollListener(object : EventCalendarScrollListener {
override fun onScrolled(month: Int, year: Int) {
Log.i("ECV", "Scrolled to: $month $year")
}
})
If you scroll for example to january 2023, the month
value will be 1
and the year 2023
.
It is really to easy to add events to the calendar. Here is an example code:
binding.eventCalendarView.events = arrayListOf(
Event(date = "15.04.2023", name = "Vacation", backgroundHexColor = "#4badeb"),
Event(date = "16.04.2023", name = "Home office", backgroundHexColor = "#e012ad"),
Event(date = "17.04.2023", name = "Meeting", backgroundHexColor = "#e07912"),
Event(date = "18.04.2023", name = "Vacation", backgroundHexColor = "#4badeb", data = "Let's go!")
)
The date format have to be in format "dd.MM.yyyy".
The Event
object structure is following:
@Parcelize
data class Event(
val date: String,
val name: String,
val backgroundHexColor: String,
val data: @RawValue Any? = null,
) : Parcelable
The event text color is automatically determined. If the background color is dark, the text color is white. Otherwise, the text color is gray.
You can change this behaviour with app:ecv_event_item_automatic_text_color="false"
. And then with app:ecv_event_item_text_color="@android:color/black"
you can set the event item text color.
Each function has also a javadoc documentation.
The EventCalendarView
does also support edge to edge.
app:ecv_edge_to_edge_enabled="true"
You can enable or disable the edge to edge handling inside your xml configuration.
The default value is false
.
If you want to change the tint of the forward and back arrows or the text color of the month/weekdays/calendar week, you can simply override the style in "values/themes".
<style name="ECV_TEXT_ICON_COLOR">
<item name="android:textColor">#FF5733</item> <!-- Text color -->
<item name="tint">#FF5733</item> <!-- Icon tint -->
</style>
https://github.com/michael-winkler/EventCalendar/releases/download/1.6.0/app-release.apk
Copyright Author @NMD [Next Mobile Development - Michael Winkler]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
If you like this library feel free to "star" it:
This library has been successfully tested with:
Android Studio Ladybug | 2024.2.1 Patch 2