PrimeDatePicker
⚡
First, PrimeDatePicker
is a tool which provides picking a single day as well as a range of days. Second, you can use its MonthView
and CalendarView
as stand-alone views in your projects.
Picking a Single Day | Picking a Range of Days | Fling Orientations |
---|---|---|
Core Logic
The ❤️ of this library is provided by PrimeCalendar.
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:1.0.15'
implementation 'com.aminography:primecalendar:1.2.15'
}
Usage
To use PrimeDatePickerBottomSheet
, simply use below snippet:
Kotlin
val datePicker = PrimeDatePickerBottomSheet.newInstance(
currentDateCalendar,
pickType,
pickedSingleDayCalendar, // can be null
pickedRangeStartCalendar, // can be null
pickedRangeEndCalendar, // can be null
minDateCalendar, // can be null
maxDateCalendar, // can be null
typefacePath // can be null
)
datePicker.setOnDateSetListener(object : PrimeDatePickerBottomSheet.OnDayPickedListener {
override fun onSingleDayPicked(singleDay: PrimeCalendar) {
// TODO
}
override fun onRangeDaysPicked(startDay: PrimeCalendar, endDay: PrimeCalendar) {
// TODO
}
})
datePicker.show(supportFragmentManager, "SOME_TAG")
Java
PrimeDatePickerBottomSheet datePicker = PrimeDatePickerBottomSheet.newInstance(
currentDateCalendar, // for example: new PersianCalendar()
pickType // for example: PickType.SINGLE
);
datePicker.setOnDateSetListener(new PrimeDatePickerBottomSheet.OnDayPickedListener() {
@Override
public void onSingleDayPicked(@NotNull PrimeCalendar singleDay) {
// TODO
}
@Override
public void onRangeDaysPicked(@NotNull PrimeCalendar startDay, @NotNull PrimeCalendar endDay) {
// TODO
}
});
datePicker.show(getSupportFragmentManager(), "SOME_TAG");
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
<com.aminography.primedatepicker.monthview.PrimeMonthView
android:id="@+id/monthView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp" />
Programmatically
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
<com.aminography.primedatepicker.calendarview.PrimeCalendarView
android:id="@+id/calendarView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:pickedDayCircleColor="#0000FF" />
Programmatically
calendarView.pickedDayCircleColor = Color.BLUE
PrimeMonthView
& PrimeCalendarView
:
1.1. Common attributes for 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. | |
• pickedDayCircleColor | 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. |
PrimeCalendarView
Specific Attributes:
1.2. 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. |
PrimeMonthView
& PrimeCalendarView
)
2. Other Variables (Common for 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. | |
• 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, NOTHING. | |
• animationInterpolator | Interpolator |
Specifies the interpolator of day selection animation. |
PrimeMonthView
& PrimeCalendarView
)
3. Listener (Common for 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?) {
// TODO
}
}
Locale
PrimeMonthView
and PrimeCalendarView
(consequently PrimeDatePickerBottomSheet
) 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.
PrimeMonthView
using PersianCalendar
:
Localization example for monthView.goto(PersianCalendar()) // or monthView.locale = Locale("fa") |
monthView.goto(PersianCalendar(Locale.ENGLISH)) // or monthView.locale = Locale.ENGLISH |
PrimeCalendarView
using HijriCalendar
:
Localization example for calendarView.goto(HijriCalendar()) // or calendarView.locale = Locale("ar") |
calendarView.goto(HijriCalendar(Locale.ENGLISH)) // or calendarView.locale = Locale.ENGLISH |
Customizing Texts in Date Picker Bottom Sheet
If you want to change the texts of the date picker bottom sheet, define some strings in your project's strings.xml
with equal name defined in the library's strings.xml
, to override them.
Change Log
Version 1.0.15
- A minor bug is fixed.
Version 1.0.14
- Animation for selected days using
animateSelection
,animationDuration
, andanimationInterpolator
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.