PrimeDatePicker

by aminography

aminography / PrimeDatePicker

PrimeDatePicker is a tool which provides picking a single day, multiple days, and a range of days.

256 Stars 26 Forks Last release: 4 months ago (v3.2.0) Apache License 2.0 561 Commits 2 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

PrimeDatePicker
:zap:

Android Arsenal Android Weekly Bintray Codacy Badge API

First,

PrimeDatePicker
is a tool which provides picking a single day, multiple days, and a range of days. Second, you can use its

MonthView
and
CalendarView
as stand-alone views in your projects.
Picking Multiple Days
Example for Civil
Picking a Range of Days
Example for Persian
Picking a Single Day
Example for Hijri
Goto View
Example for Japanese


Core Logic

The ❤️ of this library is provided by PrimeCalendar.


Main Characteristics

  • Endless Scrolling
  • Fully Customizable Views & Theme
  • Regarding Material Design
  • Fluent UI
  • RTL Support
  • Landscape Support
  • Various Calendar Types
  • Various Date Picking Strategies
  • Showing Both Dialog & BottomSheet
  • Fast Goto

:dart: Download SampleApp.apk


Download

PrimeDatePicker
is available on bintray to download using build tools systems. Add the following lines to your

build.gradle
file:
repositories {
    jcenter()
}

dependencies { implementation 'com.aminography:primedatepicker:3.2.0' implementation 'com.aminography:primecalendar:1.3.0' }


Usage

To enjoy

PrimeDatePicker
, create an instance of it using builder pattern, like the following snippets:

Kotlin ```kotlin

val multipleDaysPickCallback = MultipleDaysPickCallback { multipleDays -> // TODO }

val themeFactory = DarkThemeFactory()

val today = CivilCalendar() // Causes a Civil date picker, also today as the starting date

val datePicker = PrimeDatePicker.bottomSheetWith(today) // or dialogWith(today) .pickMultipleDays(multipleDaysPickCallback) // Passing callback is optional, can be set later using setDayPickCallback() .minPossibleDate(minDateCalendar) // Optional .maxPossibleDate(maxDateCalendar) // Optional .disabledDays(disabledDaysList) // Optional .firstDayOfWeek(Calendar.MONDAY) // Optional .applyTheme(themeFactory) // Optional .build()

datePicker.show(supportFragmentManager, "SOME_TAG") ```


Java ```java SingleDayPickCallback singleDayPickCallback = new SingleDayPickCallback() { @Override public void onSingleDayPicked(PrimeCalendar singleDay) { // TODO } };

BaseThemeFactory themeFactory = new LightThemeFactory();

PrimeCalendar today = new JapaneseCalendar(); // Causes a Japanese date picker, also today as the starting date

PrimeDatePicker datePicker = PrimeDatePicker.Companion.dialogWith(today) // or bottomSheetWith(today) .pickSingleDay(singleDayPickCallback) // Passing callback is optional, can be set later using setDayPickCallback() .minPossibleDate(minDateCalendar) // Optional .maxPossibleDate(maxDateCalendar) // Optional .disabledDays(disabledDaysList) // Optional .firstDayOfWeek(Calendar.MONDAY) // Optional .applyTheme(themeFactory) // Optional .build();

datePicker.show(getSupportFragmentManager(), "SOME_TAG"); ```


Configurations Based on Input Calendar

PrimeDatePicker
reads some configurations from the input calendar, so they are reflected to the date picker. For example:
// shows a Persian calendar, but in English language which leads to LTR direction
val calendar = PersianCalendar(Locale.ENGLISH).also {
    it.year = 1398                       // customizes starting year
    it.month = 7                         // customizes starting month
    it.firstDayOfWeek = Calendar.MONDAY  // sets first day of week to Monday
}

val datePicker = PrimeDatePicker.bottomSheetWith(calendar) .pickSingleDay(singleDayPickCallback) ... .build()


Customizing Theme

PrimeDatePicker
is fully customizable and you can fit its view to what you desire. Almost everything is customizable, such as: text size & color, background & element color, padding, font typeface, string formatter, calendar animation & transition parameters, etc.

In this way, a theme factory class is provided which declares theme parameters. A concrete subclass of this class realizes the parameters to be used by views. By default, there are two concrete subclasses:

DarkThemeFactory
and
LightThemeFactory
that you can override their parameters or inherit a class from or make your own theme factory.

Here is an example of how to override theme parameters in

Kotlin
as well as
Java
:

Kotlin ```kotlin val themeFactory = object : LightThemeFactory() {

override val typefacePath: String?
    get() = "fonts/Roboto-Regular.ttf"

override val calendarViewPickedDayInRangeBackgroundColor: Int get() = getColor(R.color.red100)

override val calendarViewPickedDayInRangeLabelTextColor: Int get() = getColor(R.color.gray900)

override val calendarViewWeekLabelFormatter: LabelFormatter get() = { primeCalendar -> when (primeCalendar[Calendar.DAY_OF_WEEK]) { Calendar.SATURDAY, Calendar.SUNDAY -> String.format("%s😍", primeCalendar.weekDayNameShort) else -> String.format("%s😁", primeCalendar.weekDayNameShort) } }

override val calendarViewWeekLabelTextColors: SparseIntArray get() = SparseIntArray(7).apply { val red = getColor(R.color.red300) val green = getColor(R.color.green400) put(Calendar.SATURDAY, red) put(Calendar.SUNDAY, red) put(Calendar.MONDAY, green) put(Calendar.TUESDAY, green) put(Calendar.WEDNESDAY, green) put(Calendar.THURSDAY, green) put(Calendar.FRIDAY, green) }

// Other customizations...

} ```

Result:

Java ```java BaseThemeFactory themeFactory = new LightThemeFactory() {

@NotNull
@Override
public PrimeCalendarView.FlingOrientation getCalendarViewFlingOrientation() {
    return PrimeCalendarView.FlingOrientation.HORIZONTAL;
}

@Override public int getSelectionBarBackgroundColor() { return super.getColor(R.color.green300); }

// Other customizations...

}; ```


Customizing Texts

If you want to change some texts in

PrimeDatePicker
, such as a button text, the current solution is to define some strings in your project's
strings.xml
with equal name defined in the library's
strings.xml
, to override them.



Stand-Alone Views

In addition to use

PrimeDatePicker
as a date picker tool, it is possible to employ stand-alone views in your project. They are
PrimeMonthView
&
PrimeCalendarView
which can be used in layout

xml
files or instantiated programmatically. For example:

xml

xml

Programmatically

kotlin
val monthView = PrimeMonthView(context)


1. XML Attributes

Applying customization has been provided for

PrimeMonthView
and
PrimeCalendarView
by using
xml
attributes as well as setting them programmatically. For example:

xml

xml

Programmatically

kotlin
calendarView.pickedDayBackgroundColor = Color.BLUE


1.1. Common attributes for
PrimeMonthView
&
PrimeCalendarView
:

Attribute Type
• calendarType enum
Specifies the calendar type which is shown by this view. Its possible values are: civil, persian, hijri, and japanese.
• monthLabelTextColor color
Specifies the text color of month name label.
• weekLabelTextColor color
Specifies the text color of week day name labels.
• dayLabelTextColor color
Specifies the text color of day number labels.
• todayLabelTextColor color
Specifies the text color of day number label which belongs to today.
• pickedDayLabelTextColor color
Specifies the text color of day number labels when they are picked.
• pickedDayBackgroundColor color
Specifies the background color of day numbers when they are picked.
• disabledDayLabelTextColor color
Specifies the text color of day number labels when they are disabled.
• monthLabelTextSize dimension
Specifies the text size of month name label.
• weekLabelTextSize dimension
Specifies the text size of week day name labels.
• dayLabelTextSize dimension
Specifies the text size of day number labels.
• monthLabelTopPadding dimension
Specifies the top padding of month name label.
• monthLabelBottomPadding dimension
Specifies the bottom padding of month name label.
• weekLabelTopPadding dimension
Specifies the top padding of week day name labels.
• weekLabelBottomPadding dimension
Specifies the bottom padding of week day name labels.
• dayLabelVerticalPadding dimension
Specifies the vertical padding (top and bottom) of day number labels.
• showTwoWeeksInLandscape boolean
When it sets true, month view shows two weeks (14 days) in each row for landscape screen orientation.
• animateSelection boolean
When it sets true, selected day/days will appear with animation.
• animationDuration integer
Specifies the duration of day selection animation.


1.2.
PrimeCalendarView
Specific Attributes:

Attribute Type
• flingOrientation enum
Specifies the fling orientation of calendar view. Its possible values are: vertical, horizontal.
• dividerColor color
Specifies the color of divider lines separating month views.
• dividerThickness dimension
Specifies the thickness of divider lines separating month views.
• dividerInsetLeft dimension
Specifies the left margin of divider lines when the fling orientation is vertical.
• dividerInsetRight dimension
Specifies the right margin of divider lines when the fling orientation is vertical.
• dividerInsetTop dimension
Specifies the top margin of divider lines when the fling orientation is horizontal.
• dividerInsetBottom dimension
Specifies the bottom margin of divider lines when the fling orientation is horizontal.
• loadFactor integer
Specifies the number of month to be load in pagination (endless scrolling).
• maxTransitionLength integer
Specifies the maximum number of month that are shown between current and target in transitions. It's used when goto method has called.
• transitionSpeedFactor float
Specifies the speed factor of scrolling in transitions. It's used when goto method has called.


2. Other Variables (Common for
PrimeMonthView
&
PrimeCalendarView
)

These variables are only accessible programmatically to get or set. (Available by getter and setter methods in java)

Variable Type
• typeface Typeface
Specifies the typeface of showing texts.
• pickedSingleDayCalendar PrimeCalendar
Specifies the single picked date.
• pickedRangeStartCalendar PrimeCalendar
Specifies the start date of the picked range.
• pickedRangeEndCalendar PrimeCalendar
Specifies the end date of the picked range.
• pickedMultipleDaysList List<PrimeCalendar>
Specifies the list of multiple picked dates.
• minDateCalendar PrimeCalendar
Specifies the minimum feasible date of the view.
• maxDateCalendar PrimeCalendar
Specifies the maximum feasible date of the view.
• pickType PickType
Specifies the date picking type of the view. Its possible values are: SINGLE, RANGE_START, RANGE_END, MULTIPLE, NOTHING.
• animationInterpolator Interpolator
Specifies the interpolator of day selection animation.


3. Listener (Common for
PrimeMonthView
&
PrimeCalendarView
)

You can listen to day picking actions by setting an instance of OnDayPickedListener to the views. For example:

monthView.onDayPickedListener = object : OnDayPickedListener {

override fun onDayPicked(pickType: PickType, 
                         singleDay: PrimeCalendar?, 
                         startDay: PrimeCalendar?, 
                         endDay: PrimeCalendar?,
                         multipleDays: List<primecalendar>?) {
    // TODO
}

}


Locale

PrimeMonthView
and
PrimeCalendarView
(consequently
PrimeDatePicker
) have been implemented with localization capabilities. By choosing locale for the
PrimeCalendar
instance which is passed to
goto
method, or by setting it directly to the views, you can localize names, digits, and layout direction.

Localization example for
PrimeMonthView
using
PersianCalendar
:


monthView.goto(PersianCalendar())
// or
monthView.locale = Locale("fa")
monthView.goto(PersianCalendar(Locale.ENGLISH))
// or
monthView.locale = Locale.ENGLISH


Localization example for
PrimeCalendarView
using
HijriCalendar
:


calendarView.goto(HijriCalendar())
// or
calendarView.locale = Locale("ar")
calendarView.goto(HijriCalendar(Locale.ENGLISH))
// or
calendarView.locale = Locale.ENGLISH


Change Log

Version 3.2.0

  • Ability to show adjacent months' days in the current month (using
    showAdjacentMonthDays
    ) and customize their text color.
  • Ability to change the background shape of the selected days (using
    pickedDayBackgroundShapeType
    and
    pickedDayRoundSquareCornerRadius
    ).
  • Minor improvements.

Version 3.1.1

  • Some UI adjustments.

Version 3.1.0

  • Adding ability to change background and text color of days in selected range.
  • Improvement in japanese text and temporal names.
  • Minor bug fixed.

Version 3.0.4

  • A minor bug fixed.

Version 3.0.0

  • Builder mechanism has changed a bit.
  • Adding full customization ability using a user configurable theme factory.
  • Ability to show the date picker as a dialog using
    PrimeDatePicker.dialogWith
    method as well as
    PrimeDatePicker.bottomSheetWith
    to show a bottom sheet.
  • Ability to specify a list of disabled days.

Version 2.0.0

  • Builder mechanism has changed.
  • Picking multiple days has better UX.
  • Adding Goto by tapping on Month-Year.
  • Picking animation has improved.
  • Possibility to change start day of week.
  • Adding RTL support in bottom sheet.```

Version 1.1.0

  • Migrated to AndroidX

Version 1.0.16

  • Ability to pick multiple days using
    MULTIPLE
    PickType.

Version 1.0.15

  • A minor bug is fixed.

Version 1.0.14

  • Animation for selected days using
    animateSelection
    ,
    animationDuration
    , and
    animationInterpolator
    attributes.


Third-Party Libraries

• PrimeCalendar (https://github.com/aminography/PrimeCalendar)

• PrimeAdapter (https://github.com/aminography/PrimeAdapter)


License

Copyright 2019 Mohammad Amin Hassani.

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.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.