/persian-calendar-view

Persian calendar view for android - تقویم فارسی / شمسی اندروید

Primary LanguageJavaGNU General Public License v3.0GPL-3.0

PersianCalendarView - تقویم فارسی اندروید

Android Arsenal

CircleCI

Persian calendar view for android based on ebraminio's DroidPersianCalendar open-source project.

demo

Usage

First add jitpack to your projects build.gradle file

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
   	}
}

Then add the dependency in modules build.gradle file

dependencies {
    compile 'com.github.roojin:persian-calendar-view:1.2.1'
}

now just simply add PersianCalendarView to your layouts

<ir.mirrajabi.persiancalendar.PersianCalendarView
    android:id="@+id/persian_calendar"
    android:layout_width="match_parent"
    android:layout_height="290sp"
    app:pcv_colorBackground="#292929"
    app:pcv_colorDayName="#bab6b6"
    app:pcv_colorHoliday="#ffd506"
    app:pcv_colorHolidaySelected="#f1f2f3"
    app:pcv_colorNormalDaySelected="#d9d9d9"
    app:pcv_colorNormalDay="#f3f4f5"
    app:pcv_eventUnderlineColor="#02f0f0"/>

Sample App is provided to demonstrate the basic scenario.

You can also interact with the sample app in this Page

Styling

Attributes

Attribute Type Description
pcv_typefacePath string Path to custom font in assets folder
pcv_headersTypefacePath string Path to custom font for header in assets folder
pcv_colorBackground color Calendar's background color
pcv_colorHoliday color Text color of holidays
pcv_colorHolidaySelected color Text color of holidays when selected
pcv_colorNormalDay color Text color of normal days
pcv_colorNormalDaySelected color Text color of normal days when selected
pcv_colorDayName color Text color of day name headers
pcv_eventUnderlineColor color Underline color of days with events
pcv_todayBackground reference Background resource used to highlight today
pcv_selectedDayBackground reference Background resource used to highlight selected day
pcv_fontSize dimension Day digits font size
pcv_HeadersFontSize dimension Day name headers font size

Functions

Most of the functionalities are inside the handler class. you can get it like this

  PersianCalendarView calendarView  = (PersianCalendarView) findViewById(R.id.persian_calendar);
  PersianCalendarHandler calendarHandler = persianCalendarView.getCalendar();
                PersianDate today = calendar.getToday();

Events

The library includes official events but you can also add your own events to it

Adding local events

// Add an event called "Custom event" to this day
calendarHandler.addLocalEvent(new CalendarEvent(calendar.getToday(), "Custom event", false));
// Add an event called "Custom event 2" to 12 days later
calendarHandler.addLocalEvent(new CalendarEvent(today.clone().rollDay(12,true), "Custom event 2", true));
// Add an event called "Custom event 3" to 1399/1/10 later
calendarHandler.addLocalEvent(new CalendarEvent(new PersianDate(1399,1,10), "Custom event 2", true));

Getting events for specific day

PersianDate today = calendar.getToday();
calendarHandler.getAllEventsForDay(today);
calendarHandler.getLocalEvents();
calendarHandler.getLocalEventsForDay(today);
calendarHandler.getOfficialEventsForDay(today);

Listeners

currently you can set Click, LongClick and MonthChange listeners on PersianCalendarView

void setOnDayClickedListener(OnDayClickedListener listener)
void setOnDayLongClickedListener(OnDayLongClickedListener listener)
void setOnMonthChangedListener(OnMonthChangedListener listener)

Other functions of PersianCalendarView

void update()
void goToDate(PersianDate date)
void goToToday()
void goToNextMonth()
void goToPreviousMonth()
void goToMonthFromNow(int offset)
PersianCalendarHandler getCalendar()

Useful methods of PersianCalendarHandler

PersianDate getToday()
// These ones Convert english digits to persian
String formatNumber(int number) 
String formatNumber(String number)
// Converts classes inherited from AbstractDate class to date string
String dateToString(AbstractDate date)
String dayTitleSummary
String dayTitleSummary(PersianDate persianDate)
String getMonthName(AbstractDate date)
String getWeekDayName(AbstractDate date)
List<CalendarEvent> getOfficialEventsForDay(PersianDate day)
List<CalendarEvent> getAllEventsForDay(PersianDate day)
List<CalendarEvent> getLocalEvents()
List<CalendarEvent> getLocalEventsForDay(PersianDate day)
String getEventsTitle(PersianDate day, boolean holiday)
// These ones also have getters
PersianCalendarHandler setMonthNames(String[] monthNames)
PersianCalendarHandler setWeekDaysNames(String[] weekDaysNames)
PersianCalendarHandler setTypeface(Typeface typeface)
PersianCalendarHandler setColorBackground(int colorBackground) 
PersianCalendarHandler setColorDayName(int colorDayName)
PersianCalendarHandler setColorHoliday(int colorHoliday)
PersianCalendarHandler setColorHolidaySelected(int colorHolidaySelected)
PersianCalendarHandler setColorNormalDay(int colorNormalDay)
PersianCalendarHandler setColorNormalDaySelected(int colorNormalDaySelected)
PersianCalendarHandler setColorEventUnderline(int colorEventUnderline)
PersianCalendarHandler setDaysFontSize(int daysFontSize)
PersianCalendarHandler setHeadersFontSize(int headersFontSize)
PersianCalendarHandler setTodayBackground(int todayBackground)
PersianCalendarHandler setSelectedDayBackground(int selectedDayBackground)
PersianCalendarHandler setHighlightOfficialEvents(boolean highlightOfficialEvents)
PersianCalendarHandler setHighlightLocalEvents(boolean highlightLocalEvents)

Todo

  • Make it even more flexible and customizable
  • Clean it up

Contributions

Any contributions are welcome. just fork it and submit your changes to your fork and then create a pull request

Thanks

Special thanks to ebrahimino for his open-source project which this library is based on

Links

Roojin co

Roojin co (Github page)

Mirrajabi.ir