VRCalendarView

Additional

Language
Java
Version
1.0.3 (Jan 11, 2018)
Created
Jan 5, 2018
Updated
Sep 14, 2018 (Retired)
Owner
VRG Soft (VRGsoftUA)
Contributors
Pavlo Nikitin (pawlo2102)
Anton Yatsenko (GetRealRenz)
2
Activity
Badge
Generate
Download
Source code

Advertisement

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