This library is a Persian date picker with huge customization options. My initial idea for creating this library was to build it to be used for a lot of different UI conditions.
Views of this class can be changed directly, according to your UI needs. The library is dependent on this great NumberPicker library.
So you can play with each of these library's features except for setOnValueChangedListener()
, which is directly used in our library.
Add the dependency in your build.gradle
buildscript {
repositories {
jcenter()
}
}
dependencies {
implementation 'dev.emad:persiandatepicker:{latest_version}'
implementation 'com.shawnlin:number-picker:2.4.11'
}
After adding these two dependencies, sync your project and start using the View as below.
<com.razavioo.persiandatepicker.PersianDatePicker
android:id="@+id/persianDatePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
As you can see, this class does not have any custom XML attributes because that will make the view less customizable. If you need to change the UI parameter, you can get each of the inner view elements programmatically.
The methods for grabbing Views that you can change it is as follows.
Method | Return Value | Description |
---|---|---|
getYearNumberPicker() | NumberPicker | get picker for year |
getMonthNumberPicker() | NumberPicker | get picker for month |
getDayNumberPicker() | NumberPicker | get picker for day |
getYearTitleTextView() | TextView | get TextView for title of year picker |
getMonthTitleTextView() | TextView | get TextView for title of month picker |
getDayTitleTextView() | TextView | get TextView for title of day picker |
The NumberPicker is the view of the custom number picker.
We have a method to choose whether you want to show month values as digits or strings. Digits are the number of the month, and the string is the name of the month.
Method | Description |
---|---|
setMonthType((monthType: MonthType)) | set month value type (MonthType.DIGIT or MonthType.STRING) |
For listening to changes in the picker, you can use the below method. the interface has three methods, onYearChanged, onMonthChanged, onDayChanged.
Method | Description |
---|---|
setListener(listener: Listener) | set a listener for the year, month, and day changes |
As this class needs to be customized based on your special UI needs and conditions, I suggest that you create a class that extends the PersianDatePicker class and has initialized with all your special configurations. then use this class instead of the general class. In the sample, I have created one and you can get the idea by watching it.
Thanks to Shawn for his great work in NumberPicker, which is beyond my imagination. The UI of this library is dependent on his module.
Thanks for the amazing work of Saman Zamani for creating the PersianDate, which this class is built upon it. His work made creating this library so easy.
The source code is licensed under the apache2 license.