mohamad-amin / PersianMaterialDateTimePicker

An Android library containing a shamsi (persian calendar) date picker and a time picker with Material Design style
328 stars 91 forks source link

PersianMaterialDateTimePicker

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) +.

Date Picker Time Picker
Date Picker Time Picker

You can report any issue on issues page. Note: If you speak Persian, you can submit issues with Persian (Farsi) language and I will check them. :)

Importing

Please refer to the relative wiki page.

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:

  1. Implement an OnTimeSetListener/OnDateSetListener
  2. Create a TimePickerDialog/DatePickerDialog using the supplied factory
  3. 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

Credits

This libary is completely based on MaterialDateTimePicker Library and Persian Calendar.