Giter Site home page Giter Site logo

vrcalendarview's Introduction

VRCalendarView

Usage

For a working implementation, Have a look at the Sample Project - app

  1. Include the library as local library project.
allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

dependencies {

    compile 'com.github.VRGsoftUA:VRCalendarView:1.0.3'

}
  1. Include the VRCalendarView widget in your layout.

       <com.vrgsoft.calendar.VRCalendarView
             android:id="@+id/calendar"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             app:vr_background_color="@color/colorDark"
             app:vr_calendar_day_text_size="15sp"
             app:vr_chosen_day_background_color="@color/colorGreen"
             app:vr_chosen_day_background_drawable="@drawable/background"
             app:vr_current_day_text_color="@android:color/darker_gray"
             app:vr_current_month_other_days_background_drawable="@drawable/background"
             app:vr_current_month_other_days_text_color="@color/colorAccent"
             app:vr_current_month_text_color="@android:color/darker_gray"
             app:vr_next_button="@drawable/ic_next"
             app:vr_other_month_text_color="@color/colorPrimary"
             app:vr_previous_button="@drawable/ic_previous"
             app:vr_title_text_color="@color/colorGreen"
             app:vr_week_days_color="@android:color/darker_gray" />
  2. You can do same with java

        vrCalendarView.getSettings()
			      .setOtherMonthTextStyle(VRCalendarView.BOLD)
                              .setCurrentMonthBackgroundColor(Color.CYAN)
                              .updateCalendar();

or

       vrCalendarView.getSettings()
                      .setOnCalendarClickListener(this)
                      .setOnCalendarLongClickListener(this)
                      .setVRCalendarMonthCallback(this);
  1. You can update all days by calling VRCalendarView.getSettings().updateCalendar();

     vrCalendarView.getSettings()
     			.setOtherMonthTextStyle(VRCalendarView.BOLD)
     			.setCurrentMonthBackgroundColor(Color.CYAN)
     			.updateCalendar();

    if VRCalendarView.getSettings().updateCalendar() is called and you want to save some custom day List getCustomizeDayView(Calendar calendar) method should be overridden getCustomizeDayView(Calendar calendar) is return all days you need to make custom. With parameter calendar you can get the year and the month to return customised days from specific month

        @Override
        public List<VrCalendarDay> getCustomizeDayView(Calendar calendar) {
            List<VrCalendarDay> vrCalendarDays = new ArrayList<>();
            VrCalendarDay today = new VrCalendarDay();
            today.setDate(new Date());
    
            VrCalendarDaySettings todaySettings = new VrCalendarDaySettings();
            todaySettings.setDayTextColor(Color.CYAN);
            today.setVrCalendarDaySettings(todaySettings);
            today.setVRCalendarCustomViewCallback(new VRCalendarCustomViewCallback() {
                @Override
                public View getNewCustomiseView() {
                    ImageView imageView = new ImageView(MainActivity.this);
                    imageView.setImageResource(R.drawable.ic_stat_name);
                    return imageView;
                }
            });
    
            vrCalendarDays.add(today);
    
            VrCalendarDay tomorrow = new VrCalendarDay();
            Date d = new Date(1513435110633L); // December 16, 2017
            tomorrow.setDate(d);
            VrCalendarDaySettings vrtomorCalendarDaySettings = new VrCalendarDaySettings();
            vrtomorCalendarDaySettings.setDayTextStyle(VRCalendarView.BOLD);
            vrtomorCalendarDaySettings.setDayBackgroundColor(ContextCompat.getColor(this, R.color.colorAccent));
            vrtomorCalendarDaySettings.setDayTextColor(ContextCompat.getColor(this, R.color.colorYellow));
            tomorrow.setVrCalendarDaySettings(vrtomorCalendarDaySettings);
    
            vrCalendarDays.add(tomorrow);
    
            return vrCalendarDays;
        }

    You can set set whatever view you want and customise it like you want if standard customisation does not fit

    Attention!!!

    View getNewCustomiseView() should always return new View. other wise it doesn't work properly

    today.setVRCalendarCustomViewCallback(new VRCalendarCustomViewCallback() {
                @Override
                public View getNewCustomiseView() {
                    ImageView imageView = new ImageView(MainActivity.this);
                    imageView.setImageResource(R.drawable.ic_stat_name);
                    return imageView;
                }
            });

    but if you need to update specific day it is better to call

        vrCalendarView.getSettings().updateCalendarDay(VrCalendarDay today, boolean hasToSelect);

    where VrCalendarDay has settings to customise specific day - hasToSelect should be false than and hasToSelect is boolean that sets specific customisation not from VrCalendarDay settings but from default settings that has attribute "chosen". Like below

    app:vr_chosen_day_background_color="@color/colorGreen"
    app:vr_chosen_day_background_drawable="@drawable/background"

    to update specific day you have to set VRCalendarDay.setDate(Date date); - it is required

      VrCalendarDay today = new VrCalendarDay();
            today.setVRCalendarCustomViewCallback(new VRCalendarCustomViewCallback() {
                @Override
                public View getNewCustomiseView() {
                    ImageView imageView = new ImageView(MainActivity.this);
                    imageView.setImageResource(R.drawable.ic_stat_name);
                    return imageView;
                }
            });
            today.setDate(day.getDate());

    Move to date with

    VrCalendarView.moveToDate(Date date);

  2. There is onClick listener and onLongClick

      public interface OnCalendarLongClickListener {
          void onCalendarDayLongClick(VrCalendarDay day);
      }

    and

    public interface OnCalendarClickListener {
        void onCalendarDayClick(VrCalendarDay day);
    }

that returns VrCalendarDay you click on

Customisation

 You can add fields via xml or VrCalendarView or VrCalendarView.getSettings().

Supported fields:

Method Type
vr_current_day_text_color color
vr_current_month_text_color color
vr_other_month_text_color color
vr_current_month_other_days_text_color color
vr_chosen_day_text_color color
vr_current_day_background_color color
vr_current_month_background_color color
vr_other_month_background_color color
vr_current_month_other_days_background_color color
vr_chosen_day_background_color color
vr_current_day_background_drawable integer
vr_current_month_background_drawable integer
vr_other_month_background_drawable" integer
vr_current_month_other_days_background_drawable integer
vr_chosen_day_background_drawable integer
vr_calendar_day_text_size dimension
vr_calendar_title_text_size dimension
vr_next_button integer
vr_previous_button integer
vr_title_text_color color
vr_background_color color
vr_week_days_color color
vr_current_day_text_style normal,bold,italic
vr_current_month_text_style normal,bold,italic
vr_other_month_text_style normal,bold,italic
vr_current_month_other_days_text_style normal,bold,italic
vr_chosen_day_text_style normal,bold,italic

Contributing

  • Contributions are always welcome
  • If you want a feature and can code, feel free to fork and add the change yourself and make a pull request

vrcalendarview's People

Contributors

pawlo2102 avatar getrealrenz avatar

Stargazers

Jaydip Radadiya avatar

Watchers

James Cloos avatar Jaydip Radadiya 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.