MeowDateTimePicker
This library offers a hijri/shamsi (Iran Calendar) Date Picker and a normal time picker designed on Google's Material Design Principals For Pickers for Android 4.0.3 (API 15) + and forked from mohamad-amin/PersianMaterialDateTimePicker
New Feautres
- support custom font
Screenshots
Date Picker | Time Picker |
---|---|
Download
build.gradle (project path)
buildscript {
repositories {
jcenter() // this line need
}
....
}
Android Studio 3+
dependencies {
implementation 'ir.he.meowdatetimepicker:library:1.0.2'
}
Android Studio 2 or lower
dependencies {
compile 'ir.he.meowdatetimepicker:library:1.0.1'
}
Initialization
Call library init function in Application and refer that in AndroidManifest.xml
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// you can change typefaces here
Typeface regular = Typeface.createFromAsset(getAssets(), "fonts/IRANSansMobile.ttf");
Typeface medium = Typeface.createFromAsset(getAssets(), "fonts/IRANSansMobile_Medium.ttf");
Typeface bold = Typeface.createFromAsset(getAssets(), "fonts/IRANSansMobile_Bold.ttf");
Typeface light = Typeface.createFromAsset(getAssets(), "fonts/IRANSansMobile_Light.ttf");
MeowTypefaceHelper.init(regular, medium, bold, light);
}
}
Add vibrate permission
<manifest >
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:name=".MyApplication"
...
</application>
</manifest>
Usage
The library follows the same API as other pickers in the Android framework. After adding the library, for using a picker in your project you need to:
- Implement an
OnTimeSetListener
/OnDateSetListener
- Create a
TimePickerDialog
/DatePickerDialog
using the supplied factory - Theme the pickers
Implement an OnTimeSetListener
/OnDateSetListener
In order to receive the date or time set in the picker, you will need to implement the OnTimeSetListener
or OnDateSetListener
interfaces. Typically this will be the Activity
or Fragment
that creates the Pickers. The callbacks use the same API as the standard Android pickers.
@Override
public void onTimeSet(RadialPickerLayout view, int hourOfDay, int minute) {
String time = "You picked the following time: "+hourOfDay+"h"+minute;
timeTextView.setText(time);
}
@Override
public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) {
String date = "You picked the following date: "+dayOfMonth+"/"+(monthOfYear+1)+"/"+year;
dateTextView.setText(date);
}
Create a TimePickerDialog
/DatePickerDialog
using the supplied factory
You will need to create a new instance of TimePickerDialog
or DatePickerDialog
using the static newInstance()
method, supplying proper default values and a callback. Once the dialogs are configured, you can call show()
.
PersianCalendar persianCalendar = new PersianCalendar();
DatePickerDialog datePickerDialog = DatePickerDialog.newInstance(
MainActivity.this,
persianCalendar.getPersianYear(),
persianCalendar.getPersianMonth(),
persianCalendar.getPersianDay()
);
datePickerDialog.show(getFragmentManager(), "Datepickerdialog");
Theme the pickers
You can theme the pickers by overwriting the color resources mdtp_accent_color
and mdtp_accent_color_dark
in your project.
<color name="mdtp_accent_color">#009688</color>
<color name="mdtp_accent_color_dark">#00796b</color>
#Additional Options
TimePickerDialog
dark theme
TheTimePickerDialog
has a dark theme that can be set by calling
timePickerDialog.setThemeDark(true);
DatePickerDialog
dark theme TheDatePickerDialog
has a dark theme that can be set by calling
datePickerDialog.setThemeDark(true);
-
TimePickerDialog
setTitle(String title)
Shows a title at the top of theTimePickerDialog
-
setSelectableDays(PersianCalendar[] days)
You can pass aPersianCalendar[]
to theDatePickerDialog
. This values in this list are the only acceptable dates for the picker. It takes precedence oversetMinDate(PersianCalendar day)
andsetMaxDate(PersianCalendar day)
-
setHighlightedDays(PersianCalendar[] days)
You can pass aPersianCalendar[]
of days to highlight. They will be rendered in bold. You can tweak the color of the highlighted days by overwritingmdtp_date_picker_text_highlighted
-
OnDismissListener
andOnCancelListener
Both pickers can be passed aDialogInterface.OnDismissLisener
orDialogInterface.OnCancelListener
which allows you to run code when either of these events occur.
timePickerDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialogInterface) {
Log.d("TimePicker", "Dialog was cancelled");
}
});
vibrate(boolean vibrate)
Set whether the dialogs should vibrate the device when a selection is made. This defaults totrue
.