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.huzaifa0024:Horizontal-Calendar:v1.1.5'
}
dependencies {
implementation("com.github.huzaifa0024:Horizontal-Calendar:v1.1.5")
}
<dependency>
<groupId>com.github.huzaifa0024</groupId>
<artifactId>Horizontal-Calendar</artifactId>
<version>v1.1.5</version>
</dependency>
libraryDependencies += "com.github.huzaifa0024" % "Horizontal-Calendar" % "v1.1.5"
:dependencies [[com.github.huzaifa0024/Horizontal-Calendar "v1.1.5"]]
A material horizontal calendar view for Android based on RecyclerView
.
The library is hosted on jcenter, add this to your build.gradle:
repositories {
jcenter()
}
dependencies {
compile 'devs.mulham.horizontalcalendar:horizontalcalendar:1.1.5'
}
##Prerequisites The minimum API level supported by this library is API 9 (GINGERBREAD).
HorizontalCalendarView
to your layout file, for example:<android.support.design.widget.AppBarLayout
............ >
<devs.mulham.horizontalcalendar.HorizontalCalendarView
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
app:textColorSelected="#FFFF"/>
</android.support.design.widget.AppBarLayout>
/** end after 1 month from now */
Calendar endDate = Calendar.getInstance();
endDate.add(Calendar.MONTH, 1);
/** start before 1 month from now */
Calendar startDate = Calendar.getInstance();
startDate.add(Calendar.MONTH, -1);
HorizontalCalendar
in your Activity through its Builder:HorizontalCalendar horizontalCalendar = new HorizontalCalendar.Builder(this, R.id.calendarView)
.startDate(startDate.getTime())
.endDate(endDate.getTime())
.build();
HorizontalCalendar horizontalCalendar = new HorizontalCalendar.Builder(rootView, R.id.calendarView)
...................
horizontalCalendar.setCalendarListener(new HorizontalCalendarListener() {
@Override
public void onDateSelected(Date date, int position) {
//do something
}
});
horizontalCalendar.setCalendarListener(new HorizontalCalendarListener() {
@Override
public void onDateSelected(Date date, int position) {
}
@Override
public void onCalendarScroll(HorizontalCalendarView calendarView,
int dx, int dy) {
}
@Override
public boolean onDateLongClicked(Date date, int position) {
return true;
}
});
You can customize it directly inside your layout:
<devs.mulham.horizontalcalendar.HorizontalCalendarView
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
app:textColorNormal="#bababa"
app:textColorSelected="#FFFF"
app:selectorColor="#c62828" // default to colorAccent.
app:selectedDateBackground="#00ffffff"/>
Or you can do it programmatically in your Activity using the Builder:
HorizontalCalendar horizontalCalendar = new HorizontalCalendar.Builder(this, R.id.calendarView)
.startDate(startDate.getTime())
.endDate(endDate.getTime())
.datesNumberOnScreen(5) // Number of Dates cells shown on screen (Recommended 5)
.dayNameFormat("EEE") // WeekDay text format
.dayNumberFormat("dd") // Date format
.monthFormat("MMM") // Month format
.showDayName(true) // Show or Hide dayName text
.showMonthName(true) // Show or Hide month text
.textColor(Color.LTGRAY, Color.WHITE) // Text color for none selected Dates, Text color for selected Date.
.selectedDateBackground(Color.TRANSPARENT) // Background color of the selected date cell.
.selectorColor(Color.RED) // Color of the selection indicator bar (default to colorAccent).
.defaultSelectedDate(date) // Date to be seleceted at start (default to Today)
.build();
horizontalCalendar.selectDate(Date date, boolean immediate); // set immediate to false to ignore animation.
// or simply
horizontalCalendar.goToday(boolean immediate);
horizontalCalendar.isDatesDaysEquals(Date date1, Date date2);
horizontalCalendar.contains(Date date);
Contributions are welcome, feel free to submit a pull request.
Copyright 2017 Mulham Raee
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.