Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.kmenager:Android-Week-View:1.3.7'
}
dependencies {
implementation("com.github.kmenager:Android-Week-View:1.3.7")
}
<dependency>
<groupId>com.github.kmenager</groupId>
<artifactId>Android-Week-View</artifactId>
<version>1.3.7</version>
</dependency>
libraryDependencies += "com.github.kmenager" % "Android-Week-View" % "1.3.7"
:dependencies [[com.github.kmenager/Android-Week-View "1.3.7"]]
Android Week View is an android library to display calendars (week view or day view) within the app. It supports custom styling.
Import the library into your project.
Grab via maven
<dependency>
<groupId>com.github.alamkanak</groupId>
<artifactId>android-week-view</artifactId>
<version>1.2.6</version>
<type>aar</type>
</dependency>
Grab via gradle
compile 'com.github.alamkanak:android-week-view:1.2.6'
Add WeekView in your xml layout.
<com.alamkanak.weekview.WeekView
android:id="@+id/weekView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:eventTextColor="@android:color/white"
app:textSize="12sp"
app:hourHeight="60dp"
app:headerColumnPadding="8dp"
app:headerColumnTextColor="#8f000000"
app:headerRowPadding="12dp"
app:columnGap="8dp"
app:noOfVisibleDays="3"
app:headerRowBackgroundColor="#ffefefef"
app:dayBackgroundColor="#05000000"
app:todayBackgroundColor="#1848adff"
app:headerColumnBackground="#ffffffff"/>
Write the following code in your java file.
// Get a reference for the week view in the layout.
mWeekView = (WeekView) findViewById(R.id.weekView);
// Set an action when any event is clicked.
mWeekView.setOnEventClickListener(mEventClickListener);
// The week view has infinite scrolling horizontally. We have to provide the events of a
// month every time the month changes on the week view.
mWeekView.setMonthChangeListener(mMonthChangeListener);
// Set long press listener for events.
mWeekView.setEventLongPressListener(mEventLongPressListener);
Implement WeekView.MonthChangeListener
, WeekView.EventClickListener
, WeekView.EventLongPressListener
according to your need.
Provide the events for the WeekView
in WeekView.MonthChangeListener.onMonthChange()
callback. Please remember that the calendar pre-loads events of three consecutive months to enable lag-free scrolling.
MonthLoader.MonthChangeListener mMonthChangeListener = new MonthLoader.MonthChangeListener() {
@Override
public List<WeekViewEvent> onMonthChange(int newYear, int newMonth) {
// Populate the week view with some events.
List<WeekViewEvent> events = getEvents(newYear, newMonth);
return events;
}
};
You can customize the look of the WeekView
in xml. Use the following attributes in xml. All these attributes also have getters and setters to enable you to change the style dynamically.
allDayEventHeight
columnGap
dayBackgroundColor
dayNameLength
eventMarginVertical
eventPadding
eventTextColor
eventTextSize
firstDayOfWeek
headerColumnBackground
headerColumnPadding
headerColumnTextColor
headerRowBackgroundColor
headerRowPadding
hourHeight
hourSeparatorColor
hourSeparatorHeight
noOfVisibleDays
overlappingEventGap
textSize
todayBackgroundColor
todayHeaderTextColor
showDistinctPastFutureColor
futureBackgroundColor
pastBackgroundColor
showDistinctWeekendColor
futureWeekendBackgroundColor
pastWeekendBackgroundColor
showNowLine
nowLineColor
nowLineThickness
scrollDuration
Add header separator
headerRowSeparator
display a row separator in header row (dimensions). Default position is at bottomheaderRowSeparatorColor
set the color of the header row separator in header row (color).headerRowSeparatorColorGravity
set the position of the header row border (bottom or top). Default position is at bottomAdd day separator color
daySeparatorColor
set the color of the day separator (color)daySeparatorWidth
set the width of the day separator color (dimensions)Custom event display
showBorderEvent
set if we should draw border inside an event (boolean).borderEventColor
set the color of the draw border inside an event (color).borderEventThickness
set the thickness of the draw border inside an event (dimensions).borderEventPosition
set the position of the draw border inside an event (bottom, top, left or right).Enable/Disable zoom
enableZoom
enable or disable zoom (boolean). Default is trueEnable/Disable horizontal scroll (useful to show only one week
disableScrollHorizontal
enable or disable horizontal scroll (boolean). Default is falseUse the following interfaces according to your need.
mWeekView.setWeekViewLoader()
to provide events to the calendarmWeekView.setMonthChangeListener()
to provide events to the calendar by monthsmWeekView.setOnEventClickListener()
to get a callback when an event is clickedmWeekView.setEventLongPressListener()
to get a callback when an event is long pressedmWeekView.setEmptyViewClickListener()
to get a callback when any empty space is clickedmWeekView.setEmptyViewLongPressListener()
to get a callback when any empty space is long pressedmWeekView.setDateTimeInterpreter()
to set your own labels for the calendar header row and header columnmWeekView.setScrollListener()
to get an event every time the first visible day has changedThere is also a sample app to get you started.
Version 1.3.0
Version 1.2.6
Version 1.2.5
WeekViewEvent
Version 1.2.4
WeekView.MonthChangeListener
, make sure to change it into MonthLoader.MonthChangeListener
Version 1.2.3
goToHour
and goToDate
methods has been fixedgetFirstVisibleHour
method to get the first visible hour in the week viewVersion 1.2.1
Version 1.1.7
Version 1.1.6
Version 1.1.5
Version 1.1.4
Version 1.1.3
Version 1.1.2
Version 1.1.1
Version 1.1.0
Copyright 2014 Raquib-ul-Alam
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.