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.nichbar:MonthView:0.2'
}
dependencies {
implementation("com.github.nichbar:MonthView:0.2")
}
<dependency>
<groupId>com.github.nichbar</groupId>
<artifactId>MonthView</artifactId>
<version>0.2</version>
</dependency>
libraryDependencies += "com.github.nichbar" % "MonthView" % "0.2"
:dependencies [[com.github.nichbar/MonthView "0.2"]]
MonthView is a lightweight month view draw in canvas.
<img src="images/monthView.png" width="480">You may customize your highlighted day with your own style.
MonthView does only provide a single month view, but you can wrap it with your own container to achieve your need.
Add this in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Then add the dependency:
dependencies {
compile 'com.github.nichbar:MonthView:0.2'
}
You may simply code like this:
<work.nich.view.MonthView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Then a default MonthView based on device's current month will show as a preview.
Or you may generate a MonthView instance like a normal View:
MonthView monthView = New MonthView(this);
MonthView use Calendar object to hold the month's basic detail like year and month.
If you wanna change MonthView to display other month, you can pass your specific Calendar to MonthView via setCalendar()
.
monthView.setCalendar(Calendar.getInstance());
There are two modes in MonthView. One is DISPLAY_ONLY
, the other is SELECT
.
You need to manually set the mode you want by:
monthView.setMode(MonthView.Mode.DISPLAY_ONLY);
// or monthView.setMode(MonthView.Mode.SELECT);
In DISPLAY_ONLY
mode, you can only set a OnDayClickedListener
and do whatever you what in onDayClicked()
callback.
monthView.setOnDayClickListener(new MonthView.OnDayClickedListener() {
@Override
public void onDayClicked(int day) {
// Do whatever you want.
}
});
In SELECT
mode, MonthView will take control of touch event. If a unselected day in this month were touched then it will be highlighted in SOLID_CIRCLE
style as default and mark as selected. In contrast, when a selected day were touched, selected tag will removed and display as another ordinary day.
You can set a OnDaySelectedListener
to listen to select and deselect action callback.
mMonthView.setOnDaySelectListener(new MonthView.OnDaySelectedListener() {
@Override
public void onDayJustSelected(int day) {
}
@Override
public void onDayJustDeselected(int day) {
}
});