Convert Figma logo to code with AI

muraee logoHorizontal-Calendar

A material horizontal calendar view for Android based on RecyclerView

1,208
229
1,208
72

Top Related Projects

A highly customizable calendar view and compose library for Android and Kotlin Multiplatform.

A Material design back port of Android's CalendarView

An android library which provides a compact calendar view much like the one used in google calenders.

A better calendar for Android

Standalone Android widget for picking a single date from a calendar view.

Android Week View is an android library to display calendars (week view or day view) within the app. It supports custom styling.

Quick Overview

Horizontal-Calendar is an Android library that provides a customizable horizontal calendar view. It allows users to scroll through dates horizontally and select specific dates, making it ideal for applications that require date selection in a compact, user-friendly format.

Pros

  • Easy to integrate into existing Android projects
  • Customizable appearance and behavior
  • Supports both single and range date selection
  • Smooth horizontal scrolling with intuitive date navigation

Cons

  • Limited documentation and usage examples
  • Not actively maintained (last update was over 3 years ago)
  • May require additional work to integrate with modern Android development practices
  • Lacks support for advanced calendar features like event marking or multi-month view

Code Examples

  1. Adding the Horizontal Calendar to your layout:
<devs.mulham.horizontalcalendar.HorizontalCalendarView
    android:id="@+id/calendarView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:textColorSelected="#FFFF"/>
  1. Initializing the Horizontal Calendar in your Activity or Fragment:
val startDate = Calendar.getInstance()
startDate.add(Calendar.MONTH, -1)
val endDate = Calendar.getInstance()
endDate.add(Calendar.MONTH, 1)

val horizontalCalendar = HorizontalCalendar.Builder(this, R.id.calendarView)
    .range(startDate, endDate)
    .datesNumberOnScreen(5)
    .build()
  1. Setting up a date selection listener:
horizontalCalendar.calendarListener = object : HorizontalCalendarListener() {
    override fun onDateSelected(date: Calendar, position: Int) {
        // Handle date selection
        Toast.makeText(this@MainActivity, "Selected Date: ${date.time}", Toast.LENGTH_SHORT).show()
    }
}

Getting Started

  1. Add the JitPack repository to your project's build.gradle file:
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  1. Add the dependency to your app's build.gradle file:
dependencies {
    implementation 'com.github.Mulham-Raee:Horizontal-Calendar:1.3.4'
}
  1. Sync your project with Gradle files and start using the Horizontal Calendar in your layouts and code as shown in the code examples above.

Competitor Comparisons

A highly customizable calendar view and compose library for Android and Kotlin Multiplatform.

Pros of Calendar

  • More comprehensive and feature-rich, offering various calendar types (month, week, day)
  • Better documentation and examples, making it easier for developers to implement
  • Active development and maintenance, with regular updates and bug fixes

Cons of Calendar

  • Steeper learning curve due to its extensive features and customization options
  • Potentially larger file size and memory footprint, which may impact app performance

Code Comparison

Horizontal-Calendar:

val startDate = Calendar.getInstance()
val endDate = Calendar.getInstance()
endDate.add(Calendar.MONTH, 1)

val horizontalCalendar = HorizontalCalendar.Builder(this, R.id.calendarView)
    .startDate(startDate.time)
    .endDate(endDate.time)
    .build()

Calendar:

class DayViewContainer(view: View) : ViewContainer(view) {
    val textView = view.findViewById<TextView>(R.id.calendarDayText)
}

calendarView.dayBinder = object : DayBinder<DayViewContainer> {
    override fun create(view: View) = DayViewContainer(view)
    override fun bind(container: DayViewContainer, day: CalendarDay) {
        container.textView.text = day.date.dayOfMonth.toString()
    }
}

Summary

Calendar offers more features and customization options compared to Horizontal-Calendar, making it suitable for complex calendar implementations. However, this comes at the cost of a steeper learning curve and potentially higher resource usage. Horizontal-Calendar is simpler and more focused on horizontal scrolling calendars, which may be preferable for specific use cases or simpler implementations.

A Material design back port of Android's CalendarView

Pros of material-calendarview

  • More comprehensive calendar functionality, including month and year views
  • Highly customizable appearance with Material Design support
  • Active development and community support

Cons of material-calendarview

  • Larger library size and potentially higher resource usage
  • Steeper learning curve due to more complex API

Code Comparison

Horizontal-Calendar:

HorizontalCalendar horizontalCalendar = new HorizontalCalendar.Builder(this, R.id.calendarView)
    .startDate(startDate)
    .endDate(endDate)
    .datesNumberOnScreen(5)
    .build();

material-calendarview:

MaterialCalendarView calendarView = findViewById(R.id.calendarView);
calendarView.setSelectionMode(MaterialCalendarView.SELECTION_MODE_SINGLE);
calendarView.setOnDateChangedListener((widget, date, selected) -> {
    // Handle date selection
});

Summary

Horizontal-Calendar focuses on providing a simple, horizontal calendar view, while material-calendarview offers a more feature-rich and customizable calendar experience. Horizontal-Calendar is easier to implement for basic use cases, but material-calendarview provides greater flexibility and functionality for more complex applications. The choice between the two depends on the specific requirements of your project and the desired level of customization.

An android library which provides a compact calendar view much like the one used in google calenders.

Pros of CompactCalendarView

  • More customizable appearance with options for event indicators, first day of week, and text size
  • Supports both horizontal and vertical scrolling modes
  • Includes built-in event handling and management

Cons of CompactCalendarView

  • Less focused on horizontal-only layout, which may not be ideal for some use cases
  • Potentially more complex to implement due to additional features and options
  • May have a steeper learning curve for developers new to calendar implementations

Code Comparison

CompactCalendarView:

CompactCalendarView compactCalendarView = (CompactCalendarView) findViewById(R.id.compactcalendar_view);
compactCalendarView.setUseThreeLetterAbbreviation(true);
compactCalendarView.setFirstDayOfWeek(Calendar.MONDAY);
compactCalendarView.setIsRtl(false);
compactCalendarView.displayOtherMonthDays(false);

Horizontal-Calendar:

HorizontalCalendar horizontalCalendar = new HorizontalCalendar.Builder(this, R.id.calendarView)
    .startDate(startDate)
    .endDate(endDate)
    .datesNumberOnScreen(5)
    .dayNameFormat("EEE")
    .dayNumberFormat("dd")
    .monthFormat("MMM")
    .showDayName(true)
    .showMonthName(true)
    .build();

Both libraries offer easy-to-use calendar implementations, but CompactCalendarView provides more flexibility and features at the cost of potentially increased complexity. Horizontal-Calendar focuses on a simpler, horizontal-only layout, which may be preferable for specific use cases.

A better calendar for Android

Pros of Caldroid

  • More comprehensive calendar functionality, including month view and customizable date cells
  • Better documentation and examples provided in the repository
  • Actively maintained with recent updates and bug fixes

Cons of Caldroid

  • Larger codebase and potentially more complex implementation
  • May have a steeper learning curve for basic calendar needs
  • Requires more setup and configuration for simple use cases

Code Comparison

Horizontal-Calendar:

horizontalCalendar = new HorizontalCalendar.Builder(this, R.id.calendarView)
    .startDate(startDate)
    .endDate(endDate)
    .datesNumberOnScreen(5)
    .build();

Caldroid:

CaldroidFragment caldroidFragment = new CaldroidFragment();
Bundle args = new Bundle();
Calendar cal = Calendar.getInstance();
args.putInt(CaldroidFragment.MONTH, cal.get(Calendar.MONTH) + 1);
args.putInt(CaldroidFragment.YEAR, cal.get(Calendar.YEAR));
caldroidFragment.setArguments(args);

Horizontal-Calendar focuses on a simple, horizontal date picker, while Caldroid offers a more feature-rich calendar experience with vertical month views. Horizontal-Calendar is easier to implement for basic date selection, whereas Caldroid provides more customization options and advanced functionality at the cost of increased complexity.

Standalone Android widget for picking a single date from a calendar view.

Pros of android-times-square

  • More comprehensive date selection functionality, including multi-date and range selection
  • Better documentation and examples for implementation
  • Larger community and more frequent updates

Cons of android-times-square

  • Less flexible in terms of UI customization
  • Heavier implementation, which may impact app performance
  • Limited to vertical scrolling, unlike Horizontal-Calendar's horizontal layout

Code Comparison

Horizontal-Calendar:

val startDate = Calendar.getInstance()
val endDate = Calendar.getInstance()
endDate.add(Calendar.MONTH, 1)

val horizontalCalendar = HorizontalCalendar.Builder(this, R.id.calendarView)
    .startDate(startDate.time)
    .endDate(endDate.time)
    .build()

android-times-square:

val calendar = CalendarPickerView(context, attrs, defStyle)
val nextYear = Calendar.getInstance()
nextYear.add(Calendar.YEAR, 1)

calendar.init(Date(), Date(), nextYear.time)
    .withSelectedDate(Date())

Both libraries offer easy initialization, but android-times-square provides more built-in options for date range selection and customization. Horizontal-Calendar focuses on a simpler, horizontally-scrolling implementation, which may be preferable for certain UI designs.

Android Week View is an android library to display calendars (week view or day view) within the app. It supports custom styling.

Pros of Android-Week-View

  • More comprehensive week view functionality with customizable events
  • Supports horizontal and vertical scrolling
  • Offers zooming capabilities for detailed time slot views

Cons of Android-Week-View

  • More complex implementation due to advanced features
  • Larger library size, potentially impacting app performance
  • Steeper learning curve for developers

Code Comparison

Horizontal-Calendar:

val startDate = Calendar.getInstance()
val endDate = Calendar.getInstance()
endDate.add(Calendar.MONTH, 1)

val horizontalCalendar = HorizontalCalendar.Builder(this, R.id.calendarView)
    .range(startDate, endDate)
    .datesNumberOnScreen(5)
    .build()

Android-Week-View:

val weekView = findViewById<WeekView>(R.id.weekView)
weekView.numberOfVisibleDays = 7
weekView.setOnEventClickListener { event, eventRect ->
    // Handle event click
}
weekView.monThFriOnly = true

Summary

Horizontal-Calendar focuses on providing a simple, horizontal calendar view, while Android-Week-View offers a more feature-rich week view with event management capabilities. Horizontal-Calendar is easier to implement and lighter in weight, making it suitable for basic date selection needs. Android-Week-View is better suited for applications requiring detailed scheduling and event visualization, albeit with a more complex setup process.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Horizontal Calendar

Download License

A material horizontal calendar view for Android based on RecyclerView.

showcase

Installation

The library is hosted on jcenter, add this to your build.gradle:

repositories {
      jcenter()
    }
    
dependencies {
      compile 'devs.mulham.horizontalcalendar:horizontalcalendar:1.3.4'
    }

Prerequisites

The minimum API level supported by this library is API 14 (ICE_CREAM_SANDWICH).

Usage

  • Add 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>
  • In your Activity or Fragment, define your start and end dates to set the range of the calendar:
/* starts before 1 month from now */
Calendar startDate = Calendar.getInstance();
startDate.add(Calendar.MONTH, -1);

/* ends after 1 month from now */
Calendar endDate = Calendar.getInstance();
endDate.add(Calendar.MONTH, 1);
  • Then setup HorizontalCalendar in your Activity through its Builder:
HorizontalCalendar horizontalCalendar = new HorizontalCalendar.Builder(this, R.id.calendarView)
                .range(startDate, endDate)
                .datesNumberOnScreen(5)
                .build();
  • Or if you are using a Fragment:
HorizontalCalendar horizontalCalendar = new HorizontalCalendar.Builder(rootView, R.id.calendarView)
	...................
  • To listen to date change events you need to set a listener:
horizontalCalendar.setCalendarListener(new HorizontalCalendarListener() {
            @Override
            public void onDateSelected(Calendar date, int position) {
                //do something
            }
        });
  • You can also listen to scroll and long press events by overriding each perspective method within HorizontalCalendarListener:
horizontalCalendar.setCalendarListener(new HorizontalCalendarListener() {
            @Override
            public void onDateSelected(Calendar date, int position) {

            }

            @Override
            public void onCalendarScroll(HorizontalCalendarView calendarView, 
            int dx, int dy) {
                
            }

            @Override
            public boolean onDateLongClicked(Calendar date, int position) {
                return true;
            }
        });

Customization

  • 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"
            app:textColorNormal="#bababa"
            app:textColorSelected="#FFFF"
            app:selectorColor="#c62828"  //default to colorAccent
            app:selectedDateBackground="@drawable/myDrawable"/>
  • Or you can do it programmatically in your Activity or Fragment using HorizontalCalendar.Builder:
HorizontalCalendar horizontalCalendar = new HorizontalCalendar.Builder(this, R.id.calendarView)
                .range(Calendar startDate, Calendar endDate)
                .datesNumberOnScreen(int number)   // Number of Dates cells shown on screen (default to 5).
                .configure()    // starts configuration.
                    .formatTopText(String dateFormat)       // default to "MMM".
                    .formatMiddleText(String dateFormat)    // default to "dd".
                    .formatBottomText(String dateFormat)    // default to "EEE".
                    .showTopText(boolean show)              // show or hide TopText (default to true).
                    .showBottomText(boolean show)           // show or hide BottomText (default to true).
                    .textColor(int normalColor, int selectedColor)    // default to (Color.LTGRAY, Color.WHITE).
                    .selectedDateBackground(Drawable background)      // set selected date cell background.
                    .selectorColor(int color)               // set selection indicator bar's color (default to colorAccent).
                .end()          // ends configuration.
                .defaultSelectedDate(Calendar date)    // Date to be selected at start (default to current day `Calendar.getInstance()`).
                .build();

More Customizations

builder.configure()
           .textSize(float topTextSize, float middleTextSize, float bottomTextSize)
           .sizeTopText(float size)
           .sizeMiddleText(float size)
           .sizeBottomText(float size)
           .colorTextTop(int normalColor, int selectedColor)
           .colorTextMiddle(int normalColor, int selectedColor)
           .colorTextBottom(int normalColor, int selectedColor)
       .end()

Months Mode

HorizontalCalendar can display only Months instead of Dates by adding mode(HorizontalCalendar.Mode.MONTHS) to the builder, for example:

horizontalCalendar = new HorizontalCalendar.Builder(this, R.id.calendarView)
                .range(Calendar startDate, Calendar endDate)
                .datesNumberOnScreen(int number)
                .mode(HorizontalCalendar.Mode.MONTHS)
                .configure()
                    .formatMiddleText("MMM")
                    .formatBottomText("yyyy")
                    .showTopText(false)
                    .showBottomText(true)
                    .textColor(Color.LTGRAY, Color.WHITE)
                .end()
                .defaultSelectedDate(defaultSelectedDate)

Events

A list of Events can be provided for each Date which will be represented as circle indicators under the Date with:

builder.addEvents(new CalendarEventsPredicate() {

                    @Override
                    public List<CalendarEvent> events(Calendar date) {
                        // test the date and return a list of CalendarEvent to assosiate with this Date.
                    }
                })

Reconfiguration

HorizontalCalendar configurations can be changed after initialization:

  • Change calendar dates range:
horizontalCalendar.setRange(Calendar startDate, Calendar endDate);
  • Change default(not selected) items style:
horizontalCalendar.getDefaultStyle()
        .setColorTopText(int color)
        .setColorMiddleText(int color)
        .setColorBottomText(int color)
        .setBackground(Drawable background);      
  • Change selected item style:
horizontalCalendar.getSelectedItemStyle()
        .setColorTopText(int color)
        ..............
  • Change formats, text sizes and selector color:
horizontalCalendar.getConfig()
        .setSelectorColor(int color)
        .setFormatTopText(String format)
        .setSizeTopText(float size)
        ..............

Important

Make sure to call horizontalCalendar.refresh(); when you finish your changes

Features

  • Disable specific dates with HorizontalCalendarPredicate, a unique style for disabled dates can be specified as well with CalendarItemStyle:
builder.disableDates(new HorizontalCalendarPredicate() {
                           @Override
                           public boolean test(Calendar date) {
                               return false;    // return true if this date should be disabled, false otherwise.
                           }
       
                           @Override
                           public CalendarItemStyle style() {
                               return null;     // create and return a new Style for disabled dates, or null if no styling needed.
                           }
                       })
  • Select a specific Date programmatically with the option whether to play the animation or not:
horizontalCalendar.selectDate(Calendar date, boolean immediate); // set immediate to false to ignore animation.
	// or simply
horizontalCalendar.goToday(boolean immediate);
  • Check if a date is contained in the Calendar:
horizontalCalendar.contains(Calendar date);
  • Check if two dates are equal (year, month, day of month):
Utils.isSameDate(Calendar date1, Calendar date2);
  • Get number of days between two dates:
Utils.daysBetween(Calendar startInclusive, Calendar endExclusive);

Contributing

Contributions are welcome, feel free to submit a pull request.

License

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.