GithubHelp home page GithubHelp logo

datalink747 / horizontalcalendar Goto Github PK

View Code? Open in Web Editor NEW

This project forked from muraee/horizontal-calendar

0.0 1.0 0.0 945 KB

A material horizontal calendar view for Android based on RecyclerView

License: Other

Java 100.00%

horizontalcalendar's Introduction

Horizontal Calendar

Download License

A material horizontal calendar view for Android based on RecyclerView.

demo

Installation

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

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

##Prerequisites The minimum API level supported by this library is API 9 (GINGERBREAD).

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, define your start and end dates to set the range of the calendar:

/** 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);

Then setup HorizontalCalendarView using its Builder and pass the id:

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

To listen to date change events you need to set a listener:

horizontalCalendar.setCalendarListener(new HorizontalCalendarListener() {
            @Override
            public void onDateSelected(Date date, int position) {
                //do something
            }
        });

You can also listen to scroll and long press events by overriding each prespective method within HorizontalCalendarListener:

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;
            }
        });

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"
            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)
                .dayFormat("EEE")	  // WeekDay text format
                .dayNumberFormat("dd")  // Date format
                .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).
                .build();

Features

  • You can select a specific Date programmatically with the option whether to play the animation or not, with:
horizontalCalendar.selectDate(Date date, boolean immediate); // set immediate to false to ignore animation.
	// or simply
horizontalCalendar.goToday(boolean immediate);
  • Check if two dates' days are equal:
horizontalCalendar.isDatesDaysEquals(Date date1, Date date2);
  • Check if a date is contained in the Calendar:
horizontalCalendar.contains(Date date);

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.

horizontalcalendar's People

Contributors

muraee avatar

Watchers

Soussi  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.